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




