1. 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.
#create an empty vector
v = vector()

#1000 trials of the experiment

for (i in 1:1000) {
  c = runif(25, min=0, max=20)
  s25 = sum(c)
  v[[i]]=s25
}
summary(v)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   162.6   229.7   246.7   248.4   267.0   350.6

bar graph

barplot(v)

Histogram:

hist(v)

standardized sum S∗25

#make a vector for the standardized sum of s*25
v2 = vector()

#Run 1000 trials
for(i in 1:1000){
  c = runif(25, min=0, max=20)
  s.25 = (sum(c)-(25*mean(c)))/(sqrt(25)-sd(c))
  v2[[i]] = s.25
}
summary(v2)
##       Min.    1st Qu.     Median       Mean    3rd Qu.       Max. 
## -1.098e-12  0.000e+00  0.000e+00  4.973e-15  0.000e+00  3.942e-12

barplot

barplot(v2)

Histogram

hist(v2)

Average of 25 values

v3 = vector()

#Run 1000 trials
for(i in 1:1000){
  c = runif(25, min=0, max=20)
  avg25 = mean(c)
  v3[[i]] = avg25
}
summary(v3)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   6.278   9.148   9.901   9.923  10.650  13.679

barplot

barplot(v3)

Histogram

hist(v3)