To use R/Rstudio do it
(a) Simulate a sample of size n = 30 from N(1,32), and calculate
the sample variance.
(b) Plot the histogram of your simulated sample in part (a) with
option breaks=10.
(c) Repeat (a) 100 times using a for loop, so you will have 100
sample variances. Plot the histogram of the 100 sample
variances.
(d) Calculate the mean and the variance of the 100 sample variances
in part (c). Is the mean close to 9?
a)
set.seed(100)
x=rnorm(30,1,3) #Simulation from a N(1,3^2) distribution
var(x) #This calculates sample variance and not the population
variance
b) hist(x,breaks=10,main="Histogram of generated sample") #Plots the histogram of the simulated values
c)
set.seed(100)
sample_var=c() #This creates an empty vector
for (i in 1:1000)
{
x=rnorm(30,1,3)
sample_var[i]=(var(x))
}
#sample_var is a vector of sample variances for 100 simulations.
hist(sample_var) #Plotting the histogram of the list of sample variances
d) mean(sample_var)
#9.024444 is what I got as the mean of the 100 sample variances.
var(sample_var)
#This gave me 5.466779 as the variance of the 100 sample variances.
The mean is very close to 9.
Get Answers For Free
Most questions answered within 1 hours.