STATHARBOR ANALYTICS · INTRODUCTION TO STATISTICS · CHAPTER 20
Resampling Methods
Resampling methods draw repeated samples from the data to estimate the distribution of a statistic. They are powerful tools for assessing variability, constructing confidence intervals and performing hypothesis tests when analytic results are difficult. This chapter introduces the bootstrap, permutation tests and cross–validation, with examples.
Bootstrap
The bootstrap involves repeatedly sampling with replacement from the observed data to approximate the sampling distribution of a statistic. For a sample and statistic , the procedure is:
Generate bootstrap samples by sampling observations with replacement from .
Compute the bootstrap statistic for each sample.
Estimate the standard error as .
Construct confidence intervals using the percentile or basic bootstrap methods.
Permutation Tests Revisited
Permutation tests (see Chapter [chap:nonparametric]) are resampling tests that determine the null distribution by randomly reassigning labels to observations. They are especially useful for comparing groups or assessing correlation without distributional assumptions.
Cross–Validation
Cross–validation assesses predictive performance by partitioning the data into training and validation sets. In –fold cross–validation, the data are divided into roughly equal parts. Each part is held out as a validation set while the model is trained on the remaining parts. The average validation error across folds estimates predictive risk and guides model selection.
Worked example
Bootstrap standard error of the sample median.
import numpy as np
data = np.array([4.1, 5.3, 2.8, 7.2, 6.4, 5.0, 3.9, 4.7, 6.1])
B = 1000
medians = []
for _ in range(B):
sample = np.random.choice(data, size=len(data), replace=True)
medians.append(np.median(sample))
se_boot = np.std(medians, ddof=1)
print(se_boot)
In R, use
boot(data, function(d,i) median(d[i]), R = 1000) from the
boot package.
Interpretation
Bootstrap methods approximate the sampling distribution using the empirical distribution of the data. They are versatile but computationally intensive.
Permutation tests maintain the data values but randomly assign group labels to approximate the null distribution.
Cross–validation focuses on predictive accuracy rather than parameter estimation; it is useful for choosing model complexity.
Exercises
Practice
Use the bootstrap to estimate the standard error of the sample mean and sample median for a dataset of your choice (e.g., heights). Compare the bootstrap estimates to analytic standard errors.
Conduct a permutation test to assess whether two independent samples differ in their means. Simulate data and compare the permutation p–value to the t–test p–value.
Perform 10–fold cross–validation to compare polynomial regression models of degrees 1, 2 and 3 for predicting the mpg of cars from horsepower. Which degree minimises the validation error?
Explain the difference between the percentile bootstrap and the basic bootstrap confidence intervals. Implement both for the sample mean and compare the intervals.
References
Efron B, Tibshirani RJ. An Introduction to the Bootstrap. Chapman & Hall/CRC; 1993.
Good PI. Permutation Tests: A Practical Guide to Resampling Methods for Testing Hypotheses. 2nd ed. Springer; 2000.
Hastie T, Tibshirani R, Friedman J. The Elements of Statistical Learning. 2nd ed. Springer; 2009. (Chapter 7)