Question: Please simulate the behavior of the sample mean when the random variable is normally distributed with a population mean of 90 and a population variance

Please simulate the behavior of the sample mean when the random variable is normally distributed with a population mean of 90 and a population variance of 49. First carry out the simulation for samples of size 10, using 25,000 replications. Then run the simulation again, but this time for samples of size 100. For each set of simulations, you are to summarize the results in a ggplot histogram. In the histogram, plot the population mean as a vertical red line.

# Uncomment the PopulationMean and PopulationVariance lines below and complete as # requested in the assignment. #--------------------------------------------------------------------------------- #PopulationMean <- #PopulationVariance <-

#------------------------------------------------------------------------------- # Carry out a a simulation involving 25,000 replications as specified in the # homework assignment, each time storing the sample mean.

# We'll use the rnorm() function in the simulations. The "r" in the rnorm() # means "randomly sample from" and the "norm" part of rnorm() means "a normal # distribution". Type ?rnorm in the console to learn more.

# Uncomment and complete the line below for Replications: #------------------------------------------------------------------------------- # Replications <-

# An initially empty vector, but of the right length: SampleMeans <- vector(mode="numeric", length=Replications)

#------------------------------------------------------------------------------- # Specify the sample sizes #------------------------------------------------------------------------------- # The homework assignment asks you to compare simulation results for samples of # size 10 and 100, producing a ggplot histogram for each one. So you will run your # version of the code below twice, once for a sample size of 10 and once for a # sample size of 100. #------------------------------------------------------------------------------- # SampleSize <-

# This is the for-loop that does all the work. You should not have to change it. for (i in 1:Replications){ SampleMeans[i] <- mean( rnorm(n=SampleSize, mean=PopulationMean, sd=sqrt(PopulationVariance)) ) }

# Prepare the data.frame for your ggplot graph: Data <- data.frame(xbar=SampleMeans)

#----------------------------------------------------------------------------------------- # As requested in the homework assignment, use ggplot to create a histogram of # the values of the sample means (given by the variable xbar in Data), and mark # the population mean with a vertical red line. Try a binwidth of 1.0 or 0.5.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!