|
courses.maths.ox.ac.uk/pluginfile.php/24382/mod_resource/content/2/Rdemo1.pdf
Probability
If $x=\left(x_{1}, \ldots, x_{n}\right)$ then the cumulative sum vector is the vector $\left(x_{1}, x_{1}+x_{2}, x_{1}+x_{2}+x_{3}, \ldots, \sum_{i=1}^{n} x_{i}\right)$. Similarly $\left(x_{1}, x_{1} x_{2}, x_{1} x_{2} x_{3}, \ldots, \prod_{i=1}^{n} x_{i}\right)$ is the cumulative product vector. The $\mathrm{R}$ functions are cumsum() and cumprod().- # random walk
- x <- sample(c(1,-1), 100, replace=TRUE)
- s <- cumsum(x)
- plot(s, type="l")
- # birthday problem
- 1 - cumprod((365:343)/365)
- plot(1 - cumprod((365:266)/365), xlab="n", ylab="probability")
复制代码
|
|