Look up the help file of the cumsum() function. Apply this function
on the vector of Rademacher random variables you obtained in Exercise
1.2 to create a simple random walk with 1000 steps.
Plot your random walk on a suitable graph.
What is the maximal deviation of this random walk from 0?
How many times has your random walk returned to 0?
preparation: points
set.seed (10)
steps <- rbinom (n = 1000, size = 1, prob = 1/2)
rademacher_variables <- 2 * steps - 1
plot the graph
rademacher_points <- cumsum(rademacher_variables)
plot (rademacher_points,
xlab = "steps", ylab = "displacement", main = "The plot of \n simple random walk",
pch = 16, col = "blue")
abline (h = 0, col = "red", lty = 2, lwd = 2)
axis (2, at = 26, label = "26")
arrows (600, 25, 710, 26, col = "salmon", lwd = 2)
text(440, 25, "maximum deviation = 26", col = "salmon", cex = 0.85)
text (700, -1.8, "37 times returned to 0", cex = 0.9)

find the maximum deviation from 0
max(abs(rademacher_points))
## [1] 26
find the times returned to 0
sum(rademacher_points == 0)
## [1] 37
# or
table(rademacher_points)
## rademacher_points
## -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
## 6 12 15 18 18 24 25 18 11 6 5 8 15 19 17 24 36 35 29 33
## 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
## 37 44 49 41 45 45 39 30 17 16 14 14 20 23 24 24 29 26 21 21
## 20 21 22 23 24 25 26
## 14 9 6 6 7 4 1
## using a table can also reach the result: 37 0s