a reproducible gallery of statistical graphics

Brownian Motion with R

  • Taiyun Wei ( / GitHub / Twitter) School of Statistics, Renmin University of China; author of the corrplot package.

We can use the animation package to produce animations in R. This short article shows you how to create a Brownian motion with the brownian.motion() function.

Simply speaking, a Brownian motion shows the trace of the coordinates

where $\epsilon_i$ is i.i.d from a standard Normal distribution. That is fairly easy to program in R – it is nothing but cumsum(rnorm(n)), and that is what brownian.motion() does internally.

ani.options(nmax = 50)  # create 50 image frames
brownian.motion(n = 20, pch = 21, cex = 4, col = "red", bg = "yellow", 
  xlim = c(-10, 10), ylim = c(-15, 15))



Keywords: Categories: Reviewer: You can find the R Markdown source document in the vistat repository on GitHub.