Ch. 9.3.5

Write a program to choose independently 25 numbers at random from [0, 20],compute their sum S25, and repeat this experiment 1000 times. Make a bar graph for the density of S25 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 A25.

# 25 numbers from [0,20]
a = vector()

for (i in 1:1000) {
  c = runif(25, min=0, max=20)
  a[[i]]=sum(c)
}
summary(a)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   167.5   231.9   250.3   250.7   269.1   346.6
barplot(a)

hist(a)

# standardized sum s*25
b = vector()

for(i in 1:1000){
  c = runif(25, min=0, max=20)
  b[[i]] = (sum(c)-(25*mean(c)))/(sqrt(25)-sd(c))
}
summary(b)
##       Min.    1st Qu.     Median       Mean    3rd Qu.       Max. 
## -2.289e-10  0.000e+00  0.000e+00 -2.294e-13  0.000e+00  1.788e-12
barplot(b)

hist(b)

# average 25
c = vector()

for(i in 1:1000){
  c = runif(25, min=0, max=20)
  c[[i]] = mean(c)
}
summary(c)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##  0.1891  7.6143 12.5593 11.4681 17.4893 19.8070     974
barplot(c)

hist(c)

So generally, we know that choosing 25 numbers at random from [0,20] generally have good fit where as sum s25 and average a25 don’t usually have good fit.