1. Learn
  2. /
  3. Courses
  4. /
  5. Inference for Linear Regression in R

Connected

Exercise

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.

Instructions 1/4

undefined XP
    1
    2
    3
    4
  • Pipe popdata to rep_sample_n(), setting the size of each sample to 50, and generating 100 reps.