Get startedGet started for free

Challenge (2)

Okay, remember the outline:

  1. Obtain a random sample.
  2. Calculate the sample's mean and standard deviation.
  3. Use these statistics to calculate a confidence interval.
  4. Repeat steps (1)-(3) 50 times.

Now that we've initialized our objects, we can use a for loop to calculate 50 times the mean and standard deviation of random samples.

In this exercise we're taking away the training wheels, so it will be a bit harder than the previous ones. But hey, that's why it's called a challenge!

This exercise is part of the course

Data Analysis and Statistical Inference

View Course

Exercise instructions

Use a for loop to do 50 times the following:

  • create a sample of size n from the population (call this samp).
  • Calculate the mean and sd and assign them to their correct positions in samp_mean and samp_sd depending on which iteration you're on.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# The ames data frame is already loaded into the workspace

# Initialize samp_mean, samp_sd and n:
samp_mean <- rep(NA, 50)
samp_sd <- rep(NA, 50)
n <- 60

# For loop goes here:
for (i in 1:50) {
  
  
  
}
Edit and Run Code