Write a program to choose independently 25 numbers at random from [0, 20], compute their sum \(S_{25}\), and repeat this experiment 1000 times. Make a bargraph for the density of \(S_{25}\) and compare it with the normal approximation of Exercise 4. How good is the fit? Now do the same for the standardized sum \(S_{25}\) and the average \(A_{25}\).
Choose 25 numbers from [0,20]
numbs = vector()
for (i in 1:1000) {
x = runif(25, min=0, max=20)
numbs[[i]]=sum(x)
}
summary(numbs)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 152.8 230.7 251.8 251.1 271.1 346.4
Make a bargraph for the density of \(S_{25}\)
mean = mean(numbs)
sd = sd(numbs)
hist(numbs, probability = TRUE)
x <- 0:1000
y <- dnorm(x = x, mean = mean, sd = sd)
lines(x = x, y = y, col = "blue") #Looks good!
This plot seems to be normally distributed.
Standardized sum \(S_{25}\)
numbs_stand = vector()
for(i in 1:1000){
y = runif(25, min=0, max=20)
numbs_stand[[i]] = (sum(y)-(25*mean(y)))/(sqrt(25)-sd(y))
}
summary(numbs_stand)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -3.633e-12 0.000e+00 0.000e+00 -2.268e-15 0.000e+00 3.181e-12
Graph for Standardized sum \(S_{25}\)
hist(numbs_stand)
The plot for the standardized sum \(S_{25}\) is not normally distributed
Average \(A_{25}\)
numbs_avg = vector()
for(i in 1:1000){
numbs_avg = runif(25, min=0, max=20)
numbs_avg[[i]] = mean(numbs_avg)
}
summary(numbs_avg)
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 1.165 11.906 15.021 13.707 16.863 19.872 974
Graph for Average \(A_{25}\)
hist(numbs_avg)
The plot for the Average \(A_{25}\) is also not normally distributed