Resampling
Explore how to perform virtual resampling with replacement using the rep_sample_n() function in R. Understand the construction of bootstrap distributions from multiple resamples and visualize the variability in sample means. This lesson helps you grasp how bootstrapping approximates sampling distributions and builds confidence intervals for statistical inference.
We'll cover the following...
Let’s now mimic our tactile resampling activity virtually with a computer.
Virtually resampling once
First, let’s perform the virtual analog of resampling once. Recall that the pennies_sample data frame included in the moderndive package contains the years of our original sample of 50 pennies from the bank. Furthermore, recall that we used the rep_sample_n() function as a virtual shovel to sample balls from our virtual bowl of 2,400 balls, as follows:
Let’s modify this code to perform the resampling with the replacement of the 50 slips of paper representing our original sample of 50 pennies
Observe how we explicitly set the replace argument to TRUE in order to tell rep_sample_n() that we would like to sample pennies with replacement. If we didn’t set replace = TRUE, the function would’ve assumed the default value of FALSE and done ...