Simulation parameters
The distribution the original sample is generated from. The bootstrap does not require continuous distributions: it also works with discrete data such as the binomial or the Poisson. Try the log-normal or the exponential to see how it behaves with skewed data.
The statistic whose bootstrap distribution you want to estimate. The median and the standard deviation do not always have a simple analytic formula for the standard error, which is where the bootstrap is especially useful.
Number of observations in the original sample that is resampled. The bootstrap works reasonably well from n ≈ 15–20 onwards; with n = 500 or n = 1000 the bootstrap distribution is very smooth and the CI very narrow.
Number of resamples with replacement. For the standard error B = 200–500 is enough; for 95% percentile confidence intervals B ≥ 1000 is recommended.
The level used to build the bootstrap CI with the percentile method (and the normal CI, when the statistic is the mean). 95% is the usual standard.
Original sample
Histogram of the sample with theoretical density curve
Bootstrap distribution of the statistic
Histogram of the B replicates with the CI shaded
What is the bootstrap?
The bootstrap is a resampling technique proposed by Bradley Efron in 1979. Its name comes from the English expression «pull yourself up by your own bootstraps», which refers to the idea of learning about the variability of an estimator using only the data from the sample itself, without needing to know the population distribution.
The core intuition is simple: if we don't know the population distribution \(F\), we can use the empirical distribution \(\hat{F}_n\) — which assigns probability \(1/n\) to each observation in the sample — as a substitute. If we draw many bootstrap samples from \(\hat{F}_n\) (that is, with replacement from the original sample) and compute the statistic of interest on each one, the variability of those replicates approximates the variability of the actual estimator.
Formally, let \(\hat{\theta} = T(X_1,\ldots,X_n)\) be an estimator of \(\theta\). Each bootstrap replicate \(\hat{\theta}^* = T(X_1^*,\ldots,X_n^*)\) is computed on a sample \((X_1^*,\ldots,X_n^*)\) drawn with replacement from the original sample. The distribution of \(\hat{\theta}^* - \hat{\theta}\) approximates the distribution of \(\hat{\theta} - \theta\).
where \(\bar{\hat{\theta}}^* = \frac{1}{B}\sum_{b=1}^{B}\hat{\theta}^{*(b)}\) is the mean of the bootstrap replicates.
What the simulator does, step by step
The simulator has an advantage that does not exist with real data: it knows the population the sample comes from. That makes it possible to compare what the bootstrap says, seeing only the sample, with the truth.
- "New sample" draws n observations from the chosen population distribution. This is the only time the population is used. The original sample chart shows that sample (bars) next to the theoretical density (red line).
- It computes the statistic on the sample (mean, median or standard deviation): this is the estimate \(\hat{\theta}\), shown in the "Bootstrap / Sample" column.
- It resamples. It builds a bootstrap sample by choosing one of the n observations n times, at random and with replacement. Some appear more than once and others do not appear.
- It computes the statistic on the bootstrap sample and repeats steps 3 and 4 until it has B replicates. Their histogram is the bootstrap distribution chart.
- Bootstrap standard error: the standard deviation of the B replicates.
- Percentile interval: it sorts the B replicates from smallest to largest and takes the values that leave α/2 outside on each side. With B = 1000 and a 95% level, these are the 26th and the 975th sorted replicates. On the chart, the green bars lie inside the interval and the grey ones outside.
The two buttons separate two sources of variation. "Regenerate bootstrap" repeats steps 3 to 6 with the same sample: the results change very little, and that small difference is the Monte Carlo error, which shrinks as B grows. "New sample" changes the sample: now the interval really moves, and no value of B reduces that variation, only a larger n. It is the uncertainty the bootstrap is trying to measure.
The "Theoretical" column holds what can only be known by knowing the population: the true value of the parameter and, when a simple formula exists, the theoretical standard error of the statistic (detailed below). If there is none, "—" is shown: these are precisely the cases where the bootstrap is most useful. The "Normal CI" row only appears for the mean and is the classical interval \(\bar{x} \pm z \cdot s/\sqrt{n}\).
What to check: whether the bootstrap standard error is close to the theoretical one and whether the interval contains the true parameter. Clicking "New sample" several times, the 95% interval should contain it about 95 times out of 100 (somewhat fewer with small samples, as explained below).
How the resampling works
The non-parametric bootstrap algorithm follows these steps:
- Take the original sample \(\mathbf{x} = (x_1, \ldots, x_n)\) of size \(n\).
- Generate \(B\) bootstrap samples \(\mathbf{x}^{*(1)}, \ldots, \mathbf{x}^{*(B)}\), each of size \(n\), by drawing with replacement from \(\mathbf{x}\). In each replicate some original values will appear several times and others won't appear at all (on average, about \(1 - e^{-1} \approx 63.2\,\%\) of the original values are represented in each replicate).
- Compute the statistic of interest \(\hat{\theta}^{*(b)} = T(\mathbf{x}^{*(b)})\) for each replicate \(b = 1, \ldots, B\).
- Estimate the standard error as the standard deviation of the \(B\) replicates (formula above).
- Build the percentile CI at \((1-\alpha) \times 100\,\%\) as the interval between the \(\alpha/2\) and \(1-\alpha/2\) percentiles of the bootstrap distribution:
The percentile method is the simplest one, and the one implemented in this simulator. For small samples or biased estimators, more sophisticated methods such as BCa (bias-corrected and accelerated) offer better coverage. In practice, \(B = 1000\) replicates is usually enough to estimate the standard error and build 95% percentile intervals, although their endpoints still vary somewhat from one run to the next (Monte Carlo error); \(B = 5000\) or more provides greater stability in the extreme percentiles. No number is universally sufficient: it depends on the confidence level and on how many decimal places of the interval you want to interpret.
Why it works and where the figures come from
The plug-in principle
What you want to know is how much the statistic varies from one sample to another. To see it directly you would have to draw many samples from the population, and there is only one. The bootstrap replaces the unknown population with the best picture available of it, the sample itself, and repeats the experiment there:
| Real world | Bootstrap world | |
|---|---|---|
| Where you draw from | The population F, unknown | The sample (empirical distribution \(\hat{F}_n\)), known |
| What you get | A sample and its statistic \(\hat{\theta}\) | A resample and its statistic \(\hat{\theta}^*\) |
| How many times you can repeat it | Once | As many as you like |
| What you want to measure | How \(\hat{\theta}\) varies around \(\theta\) | How \(\hat{\theta}^*\) varies around \(\hat{\theta}\) |
The bet is that the second variation resembles the first. It works when the sample represents the population well in whatever affects the statistic, and fails when it does not (very small samples, or statistics that depend on the extreme values).
For the mean, the bootstrap reproduces the classical formula
In this case you can work out what will come out without simulating anything. Each value in a resample, \(X^*\), is one of the n observations with probability \(1/n\). Its mean and variance are therefore those of the sample:
The mean of a resample is the average of n independent draws, so its variance is the one above divided by n:
This is the usual standard error, \(s/\sqrt{n}\), times a factor slightly below 1 (0.95 with n = 10; 0.98 with n = 30). With B replicates, the simulator gets close to that value with a small random error. The bootstrap is not magic: it replaces a formula with computation. Its value lies in the statistics for which there is no formula.
Why a third of the data is missing from each resample
The probability that a particular observation is not picked in one draw is \(1 - 1/n\). Since the n draws are independent, the probability that it is not picked in any of them is
Each resample contains, on average, 63.2% of the distinct observations (65.1% with n = 10; 63.8% with n = 30), and the rest are repeats. The number of distinct possible resamples is \(\binom{2n-1}{n}\): 92,378 with n = 10 and about 69 billion with n = 20. The B replicates are a random sample of all of them, hence the Monte Carlo error.
The theoretical standard error of the median
For the median there is an approximate formula, valid for large n, which depends on the height of the density at the median, \(f(m)\):
This is what the simulator uses in the "Theoretical" column. For the normal, \(f(m) = 1/(\sigma\sqrt{2\pi})\) and you get \(\sqrt{\pi/2}\;\sigma/\sqrt{n} \approx 1.25\,\sigma/\sqrt{n}\): with normal data, the median is 25% less precise than the mean. For the uniform between 0 and 10 it gives \(5/\sqrt{n}\), and for the exponential with λ = 0.5, \(2/\sqrt{n}\). For the standard deviation with normal data, \(\sigma/\sqrt{2(n-1)}\) is used.
The median formula has a practical drawback: it requires knowing the population density, which is exactly what is not known. The bootstrap reaches a similar value using the sample alone.
How much the percentile interval really covers
The percentile interval takes the central stretch of the bootstrap distribution. If that distribution is skewed, so is the interval, which is an advantage over \(\bar{x} \pm z \cdot s/\sqrt{n}\). But with small samples it falls short, because the sample underestimates the spread of the population and there is nothing equivalent to the Student's t correction. Actual coverage of the 95% percentile interval for the mean (obtained by simulation):
| Sample size | Normal population | Exponential population |
|---|---|---|
| n = 10 | 89% | 86% |
| n = 30 | 93% | 92% |
| n = 100 | 95% | 94% |
That is why, with small samples, variants such as BCa or the bootstrap-t are preferred. From n of about 30, the percentile method is a reasonable approximation.
When to use the bootstrap
The bootstrap is especially useful when classical parametric methods aren't directly applicable or their assumptions don't hold:
- Small samples with unknown distribution: classical methods require normality or large sample sizes for the CLT to guarantee the approximation. The bootstrap works reasonably well from \(n \approx 15\text{–}20\) onward, although the inherent uncertainty of a small sample still persists.
- Complex statistics: the median, Pearson correlation, the coefficient of variation, regression coefficients in non-linear models, or the Kolmogorov-Smirnov statistic don't have simple analytical expressions for their standard error. The bootstrap sidesteps that problem.
- Non-normal data: if the data distribution has heavy tails or marked skewness, the classical confidence interval \(\bar{x} \pm z \cdot s/\sqrt{n}\) may have coverage below the nominal level. The percentile bootstrap captures the skewness of the estimator's distribution.
- Comparison with the parametric CI: for the mean with normal data and large \(n\), the percentile bootstrap CI and the classical \(t\) CI are practically identical. Differences appear with skewed distributions or for statistics other than the mean.
Limitations: the bootstrap doesn't work well with statistics that depend on extreme values (maximum, minimum) in distributions with bounded support, nor with data that have strong temporal dependence (that's what the block bootstrap is for). It also doesn't «create» information: if the original sample is small and unrepresentative, the bootstrap can only redistribute the existing uncertainty.
Frequently asked questions
Does the bootstrap always work?
Not always. The non-parametric bootstrap fails when the statistic is sensitive to the extreme values of the empirical distribution. A classic example is the maximum of a uniform sample: the bootstrap distribution of the maximum systematically underestimates the parameter. It also fails with very small sample sizes (\(n \leq 5\)), where the empirical distribution is too discrete to approximate the real distribution well. In those cases it's preferable to use Bayesian methods or exact intervals.
Does the bootstrap work with discrete distributions (binomial, Poisson)?
Yes. The bootstrap is a non-parametric method that assumes no particular form for the data-generating distribution, so it works equally well with continuous and discrete data. By resampling with replacement from the original sample —made up, for instance, of integer counts from a binomial or a Poisson— and recomputing the statistic on each replicate, you obtain its approximate sampling distribution without needing analytical formulas. The only practical difference is visual: for discrete data the population is described by a probability mass function (PMF) at the integer values, rather than a continuous density curve. Note that the bootstrap distribution of highly discrete statistics (such as the median of a small count sample) can concentrate on just a few values, which makes the percentile CI "jump".
What is the BCa method?
The BCa method (Bias-Corrected and Accelerated), also proposed by Efron, corrects two shortcomings of the simple percentile method: the bias of the estimator (the difference between \(\bar{\hat{\theta}}^*\) and \(\hat{\theta}\)) and the acceleration (how the standard error changes with the parameter value). The CI percentiles are shifted according to these corrections, which improves the actual coverage for biased estimators or when the scale of the estimator's distribution isn't constant. The acceleration is usually computed via the jackknife method. For most practical applications with \(n \geq 30\) BCa and the percentile method give similar results.
How many replicates B do I need?
To estimate the bootstrap standard error, \(B = 200\text{–}500\) replicates is usually enough. To build 95% percentile confidence intervals, \(B \geq 1000\) is recommended. For extreme percentiles (99% or 99.9%) or for the BCa method, \(B = 5000\text{–}10\,000\) is advisable. Beyond \(B = 10\,000\), the precision gain is marginal and the computational cost can be high with large datasets. The variability of the bootstrap CI decreases roughly as \(1/\sqrt{B}\), similar to Monte Carlo error.
What is the difference between the bootstrap and the jackknife?
The jackknife (Quenouille, 1949; popularized by Tukey) is another resampling technique that estimates the bias and standard error of an estimator by systematically leaving out one observation at a time: it generates exactly \(n\) «leave-one-out» replicates. It's faster for large datasets but less general than the bootstrap. It doesn't capture the full distribution of the estimator well, nor can it be used to build percentile CIs. The bootstrap, because of its randomness, needs \(B \gg n\) replicates to be stable, but it can estimate the entire shape of the estimator's distribution and handle more complex statistics. The first-order jackknife is a linearization of the bootstrap and converges to it as \(B \to \infty\).
References and further reading
- Bootstrapping (statistics) — Wikipedia. Introduction to the method and its variants.
- Efron, B. (1979). Bootstrap methods: another look at the jackknife. The Annals of Statistics, 7(1), 1–26. The paper that introduces the bootstrap.
- Efron, B. and Tibshirani, R. J. (1993). An Introduction to the Bootstrap. Chapman & Hall. The standard textbook, with a practical approach.
- Efron, B. (1987). Better bootstrap confidence intervals. Journal of the American Statistical Association, 82(397), 171–185. The BCa method.
- DiCiccio, T. J. and Efron, B. (1996). Bootstrap confidence intervals. Statistical Science, 11(3), 189–228. A comparison of the different bootstrap intervals and their coverage.
- Davison, A. C. and Hinkley, D. V. (1997). Bootstrap Methods and their Application. Cambridge University Press.