Skip to content

Commit

Permalink
Added chapter 6
Browse files Browse the repository at this point in the history
added chapter 6 R code for the section with Python code available : law of large numbers visualization
  • Loading branch information
park1119 authored Oct 23, 2021
1 parent 21ca384 commit ce8c246
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 ce8c246

Please sign in to comment.