In: Math
Each of the distributions below could be used to model the time spent studying for an exam. Take one random sample of size 25 from each of the distributions below. Then, take 1,000 resamples (i.e., sample with replacement) of size 25 from your sample. In each case (a,b,c), plot the empirical distribution of the sample mean, estimate the mean of the sample mean, and estimate the standard deviation of the sample mean. Compare the results to the theoretical results.
a. N(5, 1.52)
b. Unif(0,10)
c. Gamma(5,1)
#one random sample of size 25 for each given distribution.
> #a)
> x1=rnorm(25,5,1.52)
> x1
[1] 5.020279 6.275468 2.575940 4.717283 5.177968 3.445100 5.743654 4.377764
[9] 5.141826 5.395002 2.745362 2.306020 3.991462 5.253398 5.323520 5.756974
[17] 5.982216 3.708627 6.700402 5.557969 6.233668 7.673463 3.529887 3.270846
[25] 4.900066
> #b)
> y1=runif(25,0,10)
> y1
[1] 3.7154953 5.4179538 4.5558985 3.9164641 8.4782767 6.6188898 3.5583676
[8] 4.5515636 8.2401313 4.4148929 6.1898235 7.8106121 6.8859722 7.6767456
[15] 4.0757638 4.6039999 6.6601718 5.8863809 7.6553750 2.1552143 0.3794588
[22] 0.2253377 2.1610553 4.7108428 4.3781013
> #c)
> z1=rgamma(25,5,1)
> z1
[1] 5.055108 9.810892 6.974359 5.139720 5.786588 3.516185 1.907632 2.921216
[9] 2.598329 6.308906 5.025108 4.306898 2.691387 3.365903 4.691390 5.755437
[17] 2.614200 7.658446 3.617847 3.525997 3.944987 3.150522 4.215006 4.785253
[25] 5.999284
> # 1000 resample
> #a)
> x2=sample(x1,1000,replace=T)
> head(x2,5)
[1] 4.377764 5.253398 4.377764 5.395002 3.708627
> smean=c()
> for(i in 1:m)
+ {
+ smean[i]=mean(x2[i])
+ }
> emp=ecdf(smean)
> plot(emp)
>
me=mean(smean)
> me
[1] 4.85455
> std=sd(smean)
> std
[1] 1.327576
> #b)
> y2=sample(y1,1000,replace=T)
> head(y2,5)
[1] 8.240131 5.886381 5.886381 4.378101 5.886381
> smean=c()
> for(i in 1:m)
+ {
+ smean[i]=mean(y2[i])
+ }
> emp=ecdf(smean)
> plot(emp)
me=mean(smean)
> me
[1] 4.900362
> std=sd(smean)
> std
[1] 2.30114
> #c)
> z2=sample(z1,1000,replace=T)
> head(z2,5)
[1] 2.921216 2.614200 9.810892 4.306898 5.755437
> smean=c()
> for(i in 1:m)
+ {
+ smean[i]=mean(z2[i])
+ }
> emp=ecdf(smean)
> plot(emp)
> me=mean(smean)
> me
[1] 4.602357
> std=sd(smean)
> std
[1] 1.795943