Get inspired by the success stories of our students in IIT JAM 2021. Learn More

This post verifies central limit theorem with the help of simulation in R for distributions of Bernoulli, uniform and poisson.

Mathematicaly, in \(X_1, X_2, …, X_n\) are random samples taken from a popualaton with mean \(\mu\) and finte variance \(\sigma^2\) and \(\bar{X}\) is the sampe mean, then \(Z = \frac{\sqrt{n}(\bar{X}-\mu)}{\sigma} \to N(0,1) \).

```
N # Number of trials (population size)
n # Number of simulations
standardized_sample_mean = rep(0,n)
EX #Expectation
VarX #Variance
for (i in 1:n){
samp #Sample from any distribution
sample_mean <- mean(samp) # Sample mean
standardized_sample_mean[i] <- sqrt(N)*(sample_mean - EX)/sqrt(VarX)
#Standardized Sample Mean
}
hist(standardized_sample_mean,prob=TRUE) #Histogram
qqnorm(standardized_sample_mean) #QQPlot
```

```
N <- 2000 # Number of trials (population size)
n <- 1000 # Number of simulations
standardized_sample_mean = rep(0,n)
EX <- 0.5
VarX <- 0.25
for (i in 1:n){
samp <- rbinom(1, size = N, prob = 0.05)
sample_mean <- mean(samp) # sample mean
standardized_sample_mean[i] <- sqrt(N)*(sample_mean - EX)/sqrt(VarX)
}
par(mfrow=c(1,2))
hist(standardized_sample_mean,prob=TRUE)
qqnorm(standardized_sample_mean)
```

```
N <- 2000 # Number of trials (population size)
n <- 1000 # Number of simulations
standardized_sample_mean = rep(0,n)
EX <- 0.5
VarX <- 0.25
for (i in 1:n
){
samp <- runif( N, 0, 1)
sample_mean <- mean(samp) # sample mean
standardized_sample_mean[i] <- sqrt(N)*(sample_mean - EX)/sqrt(VarX)
}
par(mfrow=c(1,2))
hist(standardized_sample_mean,prob=TRUE)
qqnorm(standardized_sample_mean)
```

```
N <- 2000 # Number of trials (population size)
n <- 1000 # Number of simulations
standardized_sample_mean = rep(0,n)
EX <- 1
VarX <- 1
for (i in 1:n){
samp <- rpois(N,1)
sample_mean <- mean(samp) # sample mean
standardized_sample_mean[i] <- sqrt(N)*(sample_mean - EX)/sqrt(VarX)
}
par(mfrow=c(1,2))
hist(standardized_sample_mean,prob=TRUE)
qqnorm(standardized_sample_mean)
```

Try for other distributions and mixtures and play around and verify yourself.

Stay Tuned! Stay Blessed!

Cheenta is a knowledge partner of Aditya Birla Education Academy

Advanced Mathematical Science. Taught by olympians, researchers and true masters of the subject.

JOIN TRIAL