Computing the the mean from a simple random sample from population y (WR)
y=trees$Volume
n=10
r=10000
N=length(y)
ms=numeric(0)
for (i in 1:r){
s=sample(y,n)
m=mean(s)
ms=c(ms,m)}
mesi=mean(ms)
vasi=var(ms)
hist(ms, main=paste("The sample size is", n))
me=mean(y)
vaybar=(1-n/N)*var(y)/n
print(paste ("The mean of 10000 sample means=",mesi))
## [1] "The mean of 10000 sample means= 30.174969"
print(paste("The population mean=",me))
## [1] "The population mean= 30.1709677419355"
print(paste("The variance of the sample means=",vasi))
## [1] "The variance of the sample means= 18.3051607951185"
print(paste("The variance of the sample mean=",vaybar ))
## [1] "The variance of the sample mean= 18.3040603537981"
y=trees$Volume
n=10
r=50000
N=length(y)
vs=numeric(0)
for (i in 1:r){
s=sample(y,n)
vahat=(1-n/N)*var(s)/n
vs=c(vs,vahat)}
vasi=mean(vs)
vasi=var(ms)
hist(vs, main=paste("The variance hat of size", n))
vaybar=(1-n/N)*var(y)/n
print(paste ("The mean of 10000 variance hat=",vasi))
## [1] "The mean of 10000 variance hat= 18.3051607951185"
print(paste("The variance of the sample mean=",vaybar))
## [1] "The variance of the sample mean= 18.3040603537981"