Random walk on a clock

In this exercise, we will explore and illustrate various key concepts with a simple example. Consider the a random walk on \(5\) states: \(S = \{a,b,c,d,e\}\), which we picture to be positioned on clock, in clockwise order. Consider the following walk, where we start at \(X_0=a\). We a roll a fair dice, and use it to decide to move clockwise to the state \(b\), counterclockwise to the state \(e\), or stay put, all with equal probability; similarly, at each state, we roll a fair independent dice, to determine whether to move forward, back, or stay put. We follow our position on this clock as \(X= (X_0, X_1, X_2, \ldots)\).

We are interested in the following questions:

Partial solutions

We will first code the three-sided fair coin from a fair dice. Then we will use the dice and modular arithmetic to code the walk. Specifically, we envision the walk on \(S=\{0,1,2,3,4\}\) and add \(-1,1\) or \(0\) with equal probability, where \(4+1 = 0 \bmod 5\).

Code

three <- function(){
  dice = sample(1:6, 1)
  move = 0
  if(dice <3){move <- 1}
  if(dice > 4){move <- -1}
  move
}
walk <-function(s,n){
  x=s
  current=s
  k=0
  while(k <n+1){
    current <- (current + three()) %% 5
    x <- c(x, current)
    k <-k+1}
  current
    
  }

x = replicate(1000, walk(0,500))
p = c(mean(x==0), mean(x==1),mean(x==2),mean(x==3), mean(x==4) )
p
## [1] 0.196 0.198 0.187 0.208 0.211
x = replicate(1000, walk(1,500))
q = c(mean(x==0), mean(x==1),mean(x==2),mean(x==3), mean(x==4) )
q
## [1] 0.189 0.198 0.207 0.194 0.212

Endnotes

  • Version: 02 December 2023
  • Source