liveBook · Manning

Bootstrap sampling

As explained in Effective Data Analysis

Bootstrapping is a resampling method that repeatedly samples with replacement from observed data to estimate the variability of a statistic or inferential result.

Bootstrap sampling estimates population parameters and result variability by repeatedly drawing smaller samples with replacement from an observed dataset. It offers a flexible way to build realistic data distributions and can support many statistical tests. section 5.3.1

Estimating t-statistic variability

From a dataset of n=500, draw 1,000 samples of n=50 with replacement. Run a two-group t-test on each sample, then examine the resulting t-statistic distribution to estimate how often results are significant. section 5.3.1

import numpy as np  #1
from scipy import stats as st
import matplotlib.pyplot as plt

X1 = np.random.normal(loc=75.5, scale=6.2, size=500)   #2
X2 = np.random.normal(loc=76.2, scale=6.5, size=500)

def t_stat(X1, X2):   #3
    return st.ttest_ind(X1, X2)[0]

t_values = st.bootstrap(  #4
    (X1, X2),
    t_stat,
    n_resamples=1000,
    batch=50,
    method="basic",
    vectorized=False,
    random_state=99,
)

t_crit = -st.t.ppf(q=0.95, df=49)   #5

plt.hist(result.bootstrap_distribution, bins=25)  #6
plt.axvline(t_crit, color="black", linestyle="dashed")

A Python listing demonstrates the workflow with NumPy-generated data, SciPy bootstrapping, repeated t-statistics, and a plotted distribution. section 5.3.1

How Effective Data Analysis covers it

How deep it goes
Defines resampling and gives a t-statistic workflow, but stops short of detailed treatment.
Examples
Uses n=500 data, 1,000 replacement samples of n=50, and a distribution of t-statistics.
What it assumes
Assumes a dataset and statistical-test familiarity while defining resampling with replacement.
What you can do after
Apply it via SciPy to estimate how often a two-group t-test produces significant results.
How it connects
Connects population parameters, replication, t-tests, statistical significance, and Type 1 errors.

Also explained in

Compare how 5 books explain bootstrap sampling →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Effective Data Analysis. The section links point to the parts of the book it draws on.