In: Math
Each of the distributions below could be used to model the time spent studying for an exam. Take 1,000 random samples of size 25 from each of the distributions below. 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)
Let be the mean of the population and be the standard deviation of the population. Using CLT (central limit theorem) we get that for a sample of size n,
the sample size n=25
a) the population is . the normal distribution specification is
Hence the population mean and standard deviation are
R code to simulate 1000 sample of size 25 (all statement starting with # are comments)
#set the random seed
set.seed(123)
#set the sample size
n<-25
#set the number of samples
r<-1000
#draw n*r samples from normal N(5,1.5^2)
x<-rnorm(n*r,mean=5,sd=1.5)
# convert x into a matrix of n rows and r columns
x<-matrix(x,nrow=n,ncol=r)
# get r sample means
xbar<-apply(x,2,mean)
# Get the mean of the sample mean
muxbar<-mean(xbar)
# get the standard deviation of the sample mean
sigmaxbar<-sd(xbar)
#plot the distribution of mean
hist(xbar,main="distribution of sample mean",freq=FALSE)
print(paste("Estimated mean of the sample mean
is",round(muxbar,4)))
print(paste("Estimated standard deviation of the sample mean
is",round(sigmaxbar,4)))
# get this output
b) the population is Uniform(0,10)
Given a uniform(a,b), the mean is and variance is
the population mean and variance are
R code to simulate 1000 sample of size 25 (all statement starting with # are comments)
#set the random seed
set.seed(123)
#set the sample size
n<-25
#set the number of samples
r<-1000
#draw n*r samples from uniform(0,10)
x<-runif(n*r,0,10)
# convert x into a matrix of n rows and r columns
x<-matrix(x,nrow=n,ncol=r)
# get r sample means
xbar<-apply(x,2,mean)
# Get the mean of the sample mean
muxbar<-mean(xbar)
# get the standard deviation of the sample mean
sigmaxbar<-sd(xbar)
#plot the distribution of mean
hist(xbar,main="distribution of sample mean",freq=FALSE)
print(paste("Estimated mean of the sample mean
is",round(muxbar,4)))
print(paste("Estimated standard deviation of the sample mean
is",round(sigmaxbar,4)))
## get this output
c) the population is Gamma(5,1).
Given a , the mean is and variance is
Hence the population mean and variance are
R code to simulate 1000 sample of size 25 (all statement starting with # are comments)
#set the random seed
set.seed(123)
#set the sample size
n<-25
#set the number of samples
r<-1000
#draw n*r samples from gamma(5,1)
x<-rgamma(n*r,shape=5,scale=1)
# convert x into a matrix of n rows and r columns
x<-matrix(x,nrow=n,ncol=r)
# get r sample means
xbar<-apply(x,2,mean)
# Get the mean of the sample mean
muxbar<-mean(xbar)
# get the standard deviation of the sample mean
sigmaxbar<-sd(xbar)
#plot the distribution of mean
hist(xbar,main="distribution of sample mean",freq=FALSE)
print(paste("Estimated mean of the sample mean
is",round(muxbar,4)))
print(paste("Estimated standard deviation of the sample mean
is",round(sigmaxbar,4)))
## get this