# Weak Law of Large Numbers

January 31, 2012
By

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

## 1 Description

The weak law of large numbers is a result in probability theory also known as Bernoulli’s theorem. According to the law, the mean of the results obtained from a large number of trials is close to the population mean.

Let be a sequence of independent and identically distributed random variables, each having a mean and variance .

Define a new variable,

Then,

By the Chebyshev inequality,

In brief,
as , the sample mean equals the population mean .

## 2 Simulation in R

The following is the results of simulations(Bi(n,p)).
Moreover, parameter of the population mean is 0.4, sample number is 1,000.

## 3 Appendix

This is the sample script of R.
Let’s try the Simulation in R with different parameters.

```#setting a parameters of Bi(n, p)
n <- 1000
p <- 0.4

#dataframe
df <- data.frame(bi = rbinom(n, 1, p)  ,count = 0, mean = 0)
ifelse(df\$bi[1] == 1, df[1, 2:3] <- 1, 0)
for (i in 2 : n){
df\$count[i] <- ifelse(df\$bi[i] == 1, df\$count[i]<-df\$count[i - 1]+1, df\$count[i - 1])
df\$mean[i] <- df\$count[i] / i
}

#graph
plot(df\$mean, type='l',
main = "Simulation of the Low of Large Numbers",
xlab="Numbers", ylab="Sample mean")
abline(h = p, col="red")
```

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.