What is stratified bootstrap?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Stratified bootstrap is a resampling method used when the data naturally falls into subgroups, called strata, and you want each bootstrap sample to preserve that structure. It is especially useful when the groups differ in size or importance, because ordinary bootstrap sampling can accidentally overrepresent one group and underrepresent another.
Why Ordinary Bootstrap Can Be Misleading
The classic bootstrap draws samples with replacement from the full dataset as one pool. That works well when observations are roughly exchangeable, but it can distort results when the dataset contains meaningful subpopulations.
Imagine a medical dataset with 900 control cases and 100 treatment cases. A plain bootstrap sample might by chance include too few treatment observations in some resamples and too many in others. If your statistic depends on comparing the groups, that extra imbalance increases noise and can bias interpretation.
Stratified bootstrap fixes that by resampling separately inside each stratum. If the original dataset has 900 control observations and 100 treatment observations, each bootstrap replicate keeps that same group structure unless you intentionally use a weighted design.
How Stratified Bootstrap Works
The procedure is simple:
- Split the data into strata such as class labels, regions, age groups, or survey sampling blocks.
- Sample with replacement within each stratum.
- Draw the same number of observations from each stratum as in the original dataset, unless the study design requires different weights.
- Combine the resampled strata into one bootstrap replicate.
- Recompute the statistic of interest.
- Repeat many times.
The result is a bootstrap distribution that respects the grouping structure of the original sample.
This is common in:
- imbalanced classification problems
- survey analysis
- clinical studies
- ecological sampling
- any setting where subgroup composition matters
A Small Python Example
The code below estimates a confidence interval for the overall mean while preserving two strata.
This preserves the original sizes of the two groups in every resample. If you replaced this with a plain bootstrap over the combined data, some replicates would contain too many values from group_b and too few from group_a, which changes the implied sampling design.
What It Estimates Well
Stratified bootstrap is helpful when your estimator depends on within-group behavior or on a fixed mixture of groups. That includes:
- overall means under stratified sampling
- differences between subgroup means
- classification metrics where class balance matters
- regression summaries when the sample was intentionally stratified
It often gives more stable uncertainty estimates than naive bootstrap in these settings because it avoids adding artificial randomness from subgroup composition that was never part of the original design.
Stratified Bootstrap Versus Balanced Data Tricks
It is important not to confuse stratified bootstrap with techniques that rebalance data for model training. In model training, you might oversample a minority class to improve learning. That changes the effective dataset on purpose.
Stratified bootstrap is different. Its goal is not to rebalance the world. Its goal is to preserve the sample design while measuring uncertainty in a statistic.
If the original study used unequal probability sampling, you may also need weights in addition to stratification. The resampling procedure should match the way the data was collected, not just the way it is stored.
Common Pitfalls
The most common mistake is defining strata that are not actually meaningful for the estimator. Stratification should reflect real subgroup structure or sampling design, not arbitrary labels.
Another mistake is forgetting weights. If the sample proportions differ from the population proportions by design, preserving sample counts alone may not be enough for correct inference.
Using too few bootstrap replicates is also a problem. A handful of resamples gives a noisy interval. In practice, hundreds are a minimum, and thousands are common when computation is cheap.
Finally, do not resample across strata and call it stratified bootstrap. The defining feature is separate resampling inside each group.
Summary
- Stratified bootstrap resamples within each subgroup instead of from the full dataset as one pool.
- It preserves the original stratum structure in every bootstrap replicate.
- This is useful when subgroup composition matters for the statistic or for the sampling design.
- It differs from class rebalancing methods used during model training.
- Correct stratification sometimes also requires sampling weights, not just separate resampling.

