Suppose we consider a simple random walk. A particle starts at initial position and moves one unit to the left with probability and moves one unit to the right with probability . What is the expected position of the particle after steps?

In a previous post I presented a method to solve this by iteration. I’d like to present a different method to solve the problem here.

Recall we have:

We give it some thought we can see that after steps we’ve simply added up our random variables to get our final location. We could define a new random variable:

So now all we need to do is take the expected value of . We can use rules of expected value to bring the expectation inside the summation and take the expectation of each individual as we normally would.

This is the same answer we got via the iteration method. This also makes our R simulation easier. Recall we has this setup:

################################################################ # R Simulation ################################################################ # Generate random walk rand_walk = function (n, p, z) { walk = sample(c(-1,1), size=n, replace=TRUE, prob=c(p,1-p)) for (i in 1:n) { z = z + walk[i] } return(z) } n = 1000 # Walk n steps p = .3 # Probability of moving left z = 0 # Set initial position to 0 trials = 10000 # Num times to repeate sim # Run simulation X = replicate(trials, rand_walk(n,p,z))

Our code now becomes:

################################################################ # R Simulation ################################################################ n = 1000 # Walk n steps p = .3 # Probability of moving left trials = 10000 # Num times to repeate sim # Run simulation X = replicate(trials, sum(sample(c(-1,1), size=n, replace=TRUE, prob=c(p,1-p)))) # Calculate empirical and theoretical results empirical = mean(X) theoretical = n*(1-2*p) percent_diff = abs((empirical-theoretical)/empirical)*100 # print to console empirical theoretical percent_diff

Notice that for our random walk we can replace this function:

rand_walk = function (n, p, z) { walk = sample(c(-1,1), size=n, replace=TRUE, prob=c(p,1-p)) for (i in 1:n) { z = z + walk[i] } return(z) } X = replicate(trials, rand_walk(n,p,z))

With the simpler:

X = replicate(trials, sum(sample(c(-1,1), size=n, replace=TRUE, prob=c(p,1-p))))

Additionally, in this second method we don’t need to specify an initial position since we assume from the beginning it’s zero. Of course both methods complete the same task, but they use different conceptual models. The first uses an iteration model, while the latter completes the “iteration” in a single step.

## 2 thoughts on “Simple Random Walk – Method 2”