Get startedGet started for free

Superimpose lines

Building on the previous exercise, you will now repeat the sampling process 100 times in order to visualize the sampling distribution of regression lines generated by 100 different random samples of the population.

Rather than repeatedly calling sample_n(), like you did in the previous exercise, rep_sample_n() from the oilabs package provides a convenient way to generate many random samples. The function rep_sample_n() repeats the sample_n() command reps times.

The function do() from dplyr will allow you to run the lm call separately for each level of a variable that has been group_by'ed. Here, the group variable is the sampling replicate, so each lm is run on a different random sample of the data.

This exercise is part of the course

Inference for Linear Regression in R

View Course

Hands-on interactive exercise

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

# Set the seed for reproducibility
set.seed(4747)

# Repeatedly sample the population without replacement
many_samples <- popdata %>%
  ___

# See the result
glimpse(many_samples)
Edit and Run Code