# 强大数定律与弱大数定律的图示详解

https://stats.stackexchange.com/questions/2230/convergence-in-probability-vs-almost-sure-convergence?noredirect=1&lq=1

n <- 1000;
m <- 50;
e <- 0.05
s <- cumsum(1*(rbinom(n, size=1, prob=0.5) - 0))
plot(s/seq.int(n)-0.5, type = "l", ylim = c(-0.4, 0.4))
abline(h = c(-e,e), lty = 2)
paste("---------------------")


Ctrl+a选中所有代码，然后Ctrl+Enter即可在Rstudio中运行了，

rbinom(n,size,prob)   n表示生成的随机数数量,size表示进行贝努力试验的次数,prob表示一次贝努力试验成功的概率例

ylim指的是y轴的上下限设定

h（horizontal）：表示水平横线，代码中表示在水平画两条横线，横线对应的函数值分别是e和-e

lty：线条类型

---------------------------------------------------------------------------------------------

n<-1000
m<-50

x <- matrix(1*(rbinom(n*m, size=1, prob=0.5) - 0.0), ncol = m)
print(x)

y <- apply(x, 2, function(z)(cumsum(z)/seq_along(z))-0.5)

matplot(y, type = "l", ylim = c(-0.4,0.4))

abline(h = c(-e,e), lty = 2, lwd = 2)  

lwd是线条的宽度

apply(x,2，function(z)cumsum(z)/seq_along(z))表示矩阵中的每列值代入function（z）中

apply的用法参考：

http://blog.fens.me/r-apply/

https://www.zhihu.com/question/21110761

https://en.wikipedia.org/wiki/Law_of_large_numbers#Weak_law