Forgot password?
 Create new account
View 164|Reply 2

[R]cumsum cumprod

[Copy link]

3151

Threads

8498

Posts

610K

Credits

Credits
66208
QQ

Show all posts

hbghlyj Posted at 2022-4-28 20:51:03 |Read mode
courses.maths.ox.ac.uk/pluginfile.php/24382/m … 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().
  1. # random walk
  2. x <- sample(c(1,-1), 100, replace=TRUE)
  3. s <- cumsum(x)
  4. plot(s, type="l")
  5. # birthday problem
  6. 1 - cumprod((365:343)/365)
  7. plot(1 - cumprod((365:266)/365), xlab="n", ylab="probability")
Copy the Code
1fb3b21b-6846-4453-ad3e-48c65a21c4d7.png
427a80c8-0c0b-4fc5-ad19-082a56f706c2.png

700

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2022-4-28 20:53:05
cum?

3151

Threads

8498

Posts

610K

Credits

Credits
66208
QQ

Show all posts

 Author| hbghlyj Posted at 2022-4-28 22:37:36
回复 2# kuing

cumulative

手机版Mobile version|Leisure Math Forum

2025-4-21 14:12 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list