找回密码
 快速注册
搜索
查看: 62|回复: 2

[R]cumsum cumprod

[复制链接]

3147

主题

8384

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65372
QQ

显示全部楼层

hbghlyj 发表于 2022-4-28 20:51 |阅读模式
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().
  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")
复制代码
1fb3b21b-6846-4453-ad3e-48c65a21c4d7.png
427a80c8-0c0b-4fc5-ad19-082a56f706c2.png

730

主题

1万

回帖

9万

积分

积分
93623
QQ

显示全部楼层

kuing 发表于 2022-4-28 20:53
cum?

3147

主题

8384

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65372
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-4-28 22:37
回复 2# kuing

cumulative

手机版|悠闲数学娱乐论坛(第3版)

GMT+8, 2025-3-4 19:17

Powered by Discuz!

× 快速回复 返回顶部 返回列表