In: Statistics and Probability
Demonstrate understanding of the Central Limit Theorem, using R, by showing how the distribution of the sample mean changes according to sample size.
Consider a Poisson distribution with λ = 1.5.
Generate samples of 10,000 means over different numbers of observations (eg give a matrix 1, 2,3...100) rows. For each of these samples of means, compute the mean of the means, the sample standard deviation of the means, and the proportions of means that are more than 1 standard deviation above the overall mean.
Generate plots of each of these quantities vs the number of observations contributing to the means (1, 2, 3, 4 etc.).
Write R code used to produce these data. Form conclusions about what is seen, based on the Central Limit Theorem.
**Note: need help with the R code that produces this. Please supply that in your answer. Thanks!
R code -
samp_mean = c()
proportion = c()
samp_Std_deviation = c()
x = c()
s = c(1:10000)
for(i in s){
x = rpois(n = i , lambda = 1.5)
samp_mean[i] = mean(x)
samp_Std_deviation[i] = sd(x)
sample_mean = mean(samp_mean)
std_dev = sd(samp_mean)
proportion [i] = (length(samp_mean[samp_mean > sample_mean + 1 *
std_dev]))/i
}
means_poisson = matrix(samp_mean)
means_poisson
overall_sample_mean = mean(samp_mean)
overall_std_deviation = sd(samp_mean)
plot(s , samp_mean ,type = "l")
#theoritical mean = 1.5
abline(h = 1.5 ,col = "red")
plot(s , samp_Std_deviation ,type = "l")
#theoritical sd = sqrt(1.5)
abline(h = sqrt(1.5 ,col = "red"))
plot(s , proportion ,type = "l")
R output -
From the above plots we can observe that as the sample size inceases the difference betwween the sample mean and theoritcal means decreases.
please like