# Variance of a 2D random walk

let define a 2D random walk by

$$\sum_i A_i X_i$$

where $$A=[\cos(\theta)\ \sin(\theta)]^T$$, $$\theta$$ is a random variable in the range $$[0,2\pi]$$ and $$X$$ is a scalar random variable between $$[-1,1]$$. $$\theta$$ and $$X$$ have uniform distribution and they are independent.

1. The random walk can be split to two random walks in $$x$$ and $$y$$. Then, we end up to two variances $$\sigma_x^2$$ and $$\sigma_y^2$$. How can we compute the variance of the 2D walk based on $$\sigma_x$$ and $$\sigma_y$$? Maybe $$\sqrt{\sigma_x ^2 + \sigma_y ^2}$$?

2. If we calculate the variance of the vector $$A$$, we end up to a $$2 \times 2$$ covariance matrix. I assume this would end to an identical result. But how?

• what does variance of 2D random walk mean, and how is it a scalar? Aug 22, 2020 at 18:57
• Actually i think about it as a sum of mean square displacement of the vectors. So you mean that, we should end to two variances, $\sigma_x^2$ and $\sigma_y^2$ ?
– Rob
Aug 22, 2020 at 19:17
• You should have a covariance matrix, but in your case $\sigma_{x,y}$ is theoretically zero if $\theta$ is uniformly-distributed. Aug 22, 2020 at 22:05

One realization of this walk is shown at left. Point colors progress from red through blue as time goes on. Short line segments connect successive points to make the progress more visible.

To determine its moments, write

$$AX = (x, y)^\prime.$$

Because $$\theta$$ is uniform, the distribution of the vector $$AX$$ is the same as the distribution of the vector $$-AX = (\cos(\theta+\pi),\sin(\theta+\pi))^\prime X,$$ whence

$$E[(x,y)] = E[AX^\prime] = (0,0).$$

Because $$\theta$$ has the same distribution as $$\pi/2 - \theta$$ modulo $$2\pi,$$

$$(y,x)= (\sin(\theta),\cos(\theta))X = (\cos(\pi/2-\theta), \sin(\pi/2-\theta)X \sim (x,y)$$

are equidistributed, whence $$x$$ and $$y$$ have the same variance $$\sigma^2.$$ But

$$2\sigma^2 = E[x^2+y^2] = E[||AX||^2] = E[||A||^2 |X|^2] = E[|X|^2] = \int_{-1}^1 x^2 \left(\frac{1}{2}\,\mathrm{d}x\right) = \frac{1}{3}$$

shows us that

$$\sigma^2 = 1/6.$$

In the random walk, the sum of $$n$$ iid $$x_i$$ will therefore have expectation $$0$$ and variance $$n/6$$ and likewise for the $$y_i.$$ The middle panel of the figure plots the variances of $$x_i$$ and $$y_i,$$ $$i=1,2,\ldots, 100$$ for $$10^4$$ simulated walks. The red line has slope $$1/6.$$

Similar symmetry arguments easily show the covariance of $$x$$ and $$y$$ is zero. (The distribution of $$(x,y)$$ is the same as the distribution of $$(-x,y)$$ and that immediately implies the covariance equals its own negative. Since $$x$$ and $$y$$ are bounded, they have finite covariances, whence they must equal zero.)

The right-hand panel in the figure plots the correlation coefficients observed in these $$10^4$$ simulated walks, confirming they tend to be zero.

One way to intuit this is to plot the arrival points for a large number of random walks after $$n$$ steps. Here they are for the same 10,000 simulated walks summarized in the first set of figures:

The value $$\sqrt{n\sigma^2 + n\sigma^2} = \sqrt{n/3}$$ is the typical distance traveled from the origin. The radii of the red circles in the figure are set to these values for reference. The zero covariance reflects the circular symmetry: there's no correlation evident in these scatterplots.

Here is the R code for the simulation and figures.

#
# Generate a random walk of length n.
#
rWalk <- function(n) {
theta <- runif(n)
X <- runif(n, -1, 1)
x <- cos(2 * pi * theta)
y <- sin(2 * pi * theta)
cbind(cumsum(x*X), cumsum(y*X))
}
set.seed(17)
n <- 1e3
walk <- rWalk(n) # One realization
#
# The figures.
#
par(mfrow=c(1,3))
plot(walk, type="l", asp=1, xlab="x", ylab="y", main="One Realization")
points(walk, pch=19, cex=0.5, col=hsv(3/4 * seq_len(n)/n, .8, .8, .5))
#
# The simulation.
#
n <- 1e2
X <- replicate(1e4, rWalk(n))
#
# Compute the covariance matrices for each time.
#
Sigma <- array(apply(X, 1, function(y) cov(t(y))), c(2,2,dim(X)[1]))
#
# Plot the variances and correlations.
#
plot(Sigma[1,1,], ylab="Variance", main="Variance")
points(Sigma[2,2,], pch=2)
abline(c(0,1/6), col="Red", lwd=2)

plot(Sigma[1,2,] / sqrt(Sigma[1,1,] * Sigma[2,2,]), ylim=c(-1,1),
ylab=expression(rho), main="Correlation")
abline(h=0, col="Red", lwd=2)
par(mfrow=c(1,1))
#
# Plot a set of simulated endpoints.
#
lim <- max(abs(X))
a <- sapply(c(cos, sin), function(f) f(seq(0, 2*pi, length.out=361)))
par(mfrow=c(1,3))
for (k in c(1,floor(sqrt(n)), n)) {
plot(t(X[k,,]), xlim=c(-1,1)*lim, ylim=c(-1,1)*lim, asp=1,
xlab="x", ylab="y",
main=paste("After Step", k),
pch=19, cex=0.5, col="#00000010")
lines(a * sqrt(k/3), col="Red")
}
par(mfrow=c(1,1))

• Thank you very much for this complete answer. Just two things: 1) What did you mean by "$2\sigma^2$"? Can you please explain $2\sigma^2 = E[x^2+y^2]$ ? You mean that we can simply write $\sigma ^2 = \sigma_x^2 + \sigma_y^2$? 2) I am confused about the form of the variance of the 2D walk. Is it scalar or matrix? As you wrote, the covariance is zero, so we should end to a matrix with zero off-diagonals. But you evaluated $\sigma^2$ as a scalar.
– Rob
Aug 22, 2020 at 22:20
• The variance is that of a vector, which must be a $2\times 2$ matrix. I worked out that it equals $$\operatorname{Var}\left(\sum_{i=1}^n A_iX_i\right)=\pmatrix{n/6&0\\0&n/6}.$$ As to the first question you have, note that $$E[x^2+y^2]=E[x^2]+E[y^2]=\sigma^2+\sigma^2=2\sigma^2.$$
– whuber
Aug 22, 2020 at 22:26