In: Statistics and Probability
Let X1, X2, ..., X25 be a sample from Exp(10) distribution.
1- What is the expected value of its sample variance?
2- Write an R code that generates hundred thousand repetitions of the sample variance and create a
histogram of the resulting vector via standard hist function.
3- Use the density function to get a sample variance empirical pdf and add it to the plot obtained in part (2).
1. From the theorem, if is a random sample from a population with mean and variance , the expected value of sample variance, is
(We have not been asked to prove this, hence not giving the proof)
If X has exponential distribution Exp(10), the variance is
Hence the expected value of its sample variance is
2. We will use the R inbuilt function rexp() to generate random samples from the exponential distribution.
R code (all statements starting with # are coments)
#2. Write an R code that generates hundred thousand repetitions
of the sample variance
# and create a histogram of the resulting vector via standard hist
function
#set the random seed
set.seed(123)
#set the sample size
n<-25
#set the value of lambda, the parameter of exponential
distribution
lambda<-10
#set the number of repetion
r<-100000
#generate n*r numbers
x<-rexp(n*r,lambda)
#transform this into a matrix of rxn
x<-matrix(x,nrow=r,ncol=n)
#Find the sample variance for each row (r variances)
svar<-apply(x,1,var)
#create the histogram
hist(svar,freq=FALSE,main="Histogram of sample
variances",xlab="Sample Variance",ylim=c(0,100))
## get the following plot
3. add empirical pdf to the above plot
R code
#3. Use the density function to get a sample variance empirical
pdf and add it to the plot
lines(density(svar),col="red")
## get the output
Also to prove part 1, that the expected value of sample variance is equal to the population variance
R code
print(paste("The expected value of sample variance is",round(mean(svar),4)))
## the output