Skip to content

Commit

Permalink
Merge pull request #3 from park1119/master
Browse files Browse the repository at this point in the history
Added chapter 6
  • Loading branch information
stanchan authored Oct 24, 2021
2 parents 21ca384 + ce8c246 commit 76ae2fa
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ch06.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#############
# Chapter 6.3 (Law of Large Numbers)

## Weak law of large numbers

# R code to illustrate the weak law of large numbers

library(pracma)

p <- 0.5
Nset <- as.integer(round(logspace(2,5,100)))
x <- matrix(rep(0, 1000*length(Nset)), nrow=1000)
for (i in 1:length(Nset)) {
N = Nset[i]
x[,i] <- rbinom(1000, N, p) / N
}
Nset_grid <- repmat(Nset, m=1, n=1000)

semilogx(Nset_grid, x, col='black', pch=19)
points(Nset, p + 3*(((p*(1-p))/Nset)^(1/2)), col='red', pch=19, lwd=1)
points(Nset, p - 3*(((p*(1-p))/Nset)^(1/2)), col='red', pch=19, lwd=1)

0 comments on commit 76ae2fa

Please sign in to comment.