library("gganimate") library("ggplot2") p = ^{1}⁄_{2} # parameters p <- 0.5 Tmax = 60 # start at the origin x = 0 y = 0 t = 0 df <- data.frame(x,y,t) # random walk for(i in 1:Tmax){ t <- t + 1 if(runif(1) < p){ x <- x - 1 } else { x <- x + 1 } # reset process if dot leaves view if(abs(x) > 10){ x <- 0 } this_step <- data.

In this post, I want to run an example of absorbing states in stochastic processes. This example is based on Example 3.29 in Introduction to Stochastic Processes in R by Robert Dobrow.
Data The data I have assembled is based on IRDS reports from my own University of California at Merced.
# weights weights <- c(20, 70, 0, 0, 10, 0, 0, 5, 89, 0, 6, 0, 0, 0, 3, 94, 3, 0, 0, 0, 0, 24, 1, 76, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 100) sparse_weights <- weights[weights > 0] # transition matrix (row stochastic) P <- matrix(weights, nrow = 6, byrow = TRUE)*0.

Today I finally read a tutorial on gganimate, and here I will build my first example. My hope is to eventually simulate traversal on a directed graph.
library(tidyverse) library(gganimate) Create Node Data For this example, I will have 3 nodes (located at 3 vertices of a triangle), 100 dots distributed among the nodes, and a new placement over 21 states in time.
N <- 100 # number of dots T <- 20 # number of iterations node_names <- c("Node 1", "Node 2", "Node 3") iter <- rep(0, N) node <- rep("Node 1", N) x <- 10 + rnorm(N, 0, 2) y <- 20 + rnorm(N, 0, 2) states <- data.