Book contents

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 𝐱=(x1,…,xn)\mathbf{x} = (x_1,\dots,x_n) and statistic θ̂=g(𝐱)\hat{\theta} = g(\mathbf{x}), the procedure is:

  1. Generate BB bootstrap samples 𝐱b*\mathbf{x}^*_{b} by sampling nn observations with replacement from 𝐱\mathbf{x}.

  2. Compute the bootstrap statistic θ̂b*=g(𝐱b*)\hat{\theta}^*_b = g(\mathbf{x}^*_{b}) for each sample.

  3. Estimate the standard error as SEboot=1B−1∑b=1B(θ̂b*−θ̂‾*)2\text{SE}_\text{boot} = \sqrt{\frac{1}{B-1}\sum_{b=1}^B (\hat{\theta}^*_b - \bar{\hat{\theta}}^*)^2}.

  4. 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 kk–fold cross–validation, the data are divided into kk 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

Exercises

Practice

  1. 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.

  2. 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.

  3. 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?

  4. Explain the difference between the percentile bootstrap and the basic bootstrap confidence intervals. Implement both for the sample mean and compare the intervals.

References