13.5 LLN, CLT, confidence intervals, bootstrap
Sooner or later every model builder has to compare two models. In AI Engineering, the RNN language model reports a bits-per-character number and the encoder-decoder model a BLEU score from Sequence metrics, and the question is never “what is the number” but “is model A better than model B, or did I get a lucky test set”. A BLEU of 21.3 against 20.8 on 200 sentences means nothing until you know how much BLEU moves when you draw another 200 sentences.
Concepts from other sections (12)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- Comparison test: a series of nonnegative terms converges if it is bounded term by term by a known convergent series, such as a geometric or -series, and diverges if it bounds a known divergent one. Read more: Chapter 8: Calculus 2
- Cumulative distribution function (CDF): , defined for every random variable, discrete or continuous; it rises from 0 to 1, and for a continuous variable its derivative is the density. Read more: Chapter 13: Probability and Statistics
- Variance: the expected squared distance from the mean; its square root is the standard deviation. Read more: 13.1 Random variables, expectation, variance, and normal draws by Box-Muller
- Standard normal: the distribution with density . Read more: 13.1 Random variables, expectation, variance, and normal draws by Box-Muller
- Covariance: , a measure of linear co-movement; zero does not imply independence. Read more: 13.10 Probability problem set, part b: joint distributions, covariance, MLE
- Chebyshev’s inequality: , a distribution-free tail bound derived from Markov’s inequality. Read more: 13.11 Probability problem set, part c: limit theorems and confidence intervals
- chrF: a recall-weighted F score over character n-grams of orders 1 to 6, white space removed. Read more: 10.5 Sequence metrics: exact match, BLEU, chrF in AI Engineering
- Normal distribution / Gaussian distribution: the bell-shaped density with mean and variance ; about 68%, 95%, and 99.7% of its mass lies within one, two, and three standard deviations of the mean, and the central limit theorem makes it the limit of sample means. Read more: Chapter 13: Probability and Statistics
- Permutation test: a test whose null distribution comes from relabelling the data in ways the null says are harmless. Read more: 13.6 Hypothesis tests: paired and two-sample permutation, McNemar, Holm
- Perplexity: , the geometric mean of ; the effective number of choices per token. Read more: 17.2 Perplexity, bits per byte, NLL accumulator
- word error rate (WER): pooled substitutions, deletions and insertions divided by the total reference word count. Read more: 15.5 Multimodal eval metrics: WER, CER, VQA, captions, zero-shot in AI Engineering
- Standard deviation: , the typical distance of a random variable from its mean, in the same units as the variable itself. Read more: Chapter 13: Probability and Statistics
From that point on, every metric the books print carries a 95% interval: sequence metrics, the LM evaluation harness, the verdicts of Quantization. The comparison tests of the next section, Hypothesis tests, build on the same machinery. This section gives that interval three ways: from a formula for means, from a formula for proportions, and by resampling for everything else. Along the way you will implement the normal and Student’s CDFs and quantiles from first principles.
No code from earlier sections is needed. The reading background is expectation, variance, and the normal from Random variables, expectation, variance, and normal draws, the one-uniform-per-draw discipline of Categorical sampling, and the variance of a sum from problem set B. The reference implementation is course/solutions/python/tinyllm/prob/stats.py, with its contract in stats.pyi; the generator behind rng is specified in spec/pcg32.md.
Learning objectives
- State the law of large numbers and the central limit theorem, and use them to explain why error bars shrink as .
- Build a interval for a mean, and explain why Bessel’s , the quantile, and are each required.
- Compute the normal and quantiles by bisection on their CDFs.
- Compute a Wilson interval for a proportion and explain where the Wald interval fails.
- Implement a reproducible percentile bootstrap with a fixed index rule and type 7 quantiles.
Notation
Section titled “Notation”| Symbol | Meaning | Type / shape |
|---|---|---|
| independent draws from one distribution (per-example scores) | reals | |
| the true mean and variance of that distribution | reals | |
| the sample mean | real | |
| the sample variance (Bessel’s ) | real | |
| the standard error: estimated sd of | real | |
| the miss rate; is the confidence level (0.95) | real in | |
| , | the standard normal CDF and its quantile | functions |
| , , | Student’s t with degrees of freedom, its CDF and quantile | functions |
| successes, trials, observed proportion | integers, real | |
| , | number of bootstrap resamples, the statistic on resample | integer, reals |
The law of large numbers
Section titled “The law of large numbers”By linearity , and because independent variances add, (question 3 of problem set B, with all covariances 0). Chebyshev’s inequality then gives : the mean of more data is closer to the truth (proved in question 5 of problem set C). It also gives the rate: the typical error is , so four times the eval set halves the error, it does not quarter it.
The central limit theorem
Section titled “The central limit theorem”The law of large numbers says the error shrinks; the central limit theorem says what shape it has. Whatever the distribution of each (finite variance is all it needs), the standardized mean tends to the standard normal . So , and choosing (1.96 for 95%) turns that into an interval: covers in about of repeated samples. Per-example eval scores are never normal (0/1 accuracy, skewed losses), and the interval still works once is in the hundreds: that is the CLT.
Quantiles from first principles
Section titled “Quantiles from first principles”To use the interval you need and its inverse. , with math.erfc (it keeps full relative precision in the lower tail, where computed by subtraction would lose every digit). The quantile has no closed form, but is increasing, so bisection finds it: keep a bracket with and halve it until the midpoint equals an end, which is the last bit of a double. For use the symmetry ; is exact in float64 there.
Student’s t
Section titled “Student’s t”The interval above needs , and you only have , computed from the same data. The ratio is wider-tailed than the normal (when happens to be small, is large), and for normal data it follows Student’s t with degrees of freedom exactly (Gosset, 1908). So the interval is
Two details carry it. The first is the in : the deviations are measured from , which sits closer to the data than does, so dividing by underestimates . The second is : the interval misses on both sides. At the normal quantile covers only about 92% instead of 95%.
For integer the CDF has a closed form (Abramowitz and Stegun 26.7.3 and 26.7.4). With and :
- even: ,
- odd: , just for ,
and . Each term is the previous one times a ratio ( or ), so a cumulative product computes the series in . The quantile is bisection again, on a bracket whose top doubles until ( needs at , so no fixed bound is safe). As grows, tends to the normal: against .
Proportions: the Wilson interval
Section titled “Proportions: the Wilson interval”An accuracy is a mean of 0/1 values, so you might expect the mean interval to serve. But the formula (the Wald interval) fails exactly where safety evals live: with 0 failures in 10 trials it says , certainty. Wilson (1927) inverts the test instead: the interval is every with . Squaring and solving the quadratic in gives
whose center is pulled toward and which is never empty. At its lower end is exactly 0 and at its upper end exactly 1; rounding can leave them a hair off, so the code pins them.
The bootstrap
Section titled “The bootstrap”Means and proportions have formulas. Many metrics do not. For a statistic with no variance formula (BLEU, chrF, a median, pass@k), Efron’s idea (1979) is to let the data stand in for the population: draw indices with replacement, recompute the statistic on that resample, repeat times, and read the spread of . The percentile interval is their and quantiles.
Two rules make it reproducible across languages (the Go evaluation harness of Paired A/B experiments, in AI Engineering, reimplements it). Each index is from exactly one rng.uniform(), drawn in order (resample 0’s indices first). And the quantile is type 7: sort, , , value (numpy’s default). The point estimate stays on the original data.
Working it by hand
Section titled “Working it by hand”A t interval. Take , .
- Mean: .
- Deviations: ; squares sum to .
- , ; .
- , : (bisection on the odd series, which for is ).
- Half-width ; interval .
With the normal 1.959964 instead, the interval would be , a quarter narrower: at that is a large overstatement of certainty.
One value of the series. : , , . The odd series with stops after : , so .
A Wilson interval. , , , : , center , half-width . The interval is ; the Wald interval is .
These are the first two test cases a correct implementation must reproduce.
Designing the interface
Section titled “Designing the interface”Nine functions cover the distributions, the two formula intervals, and the bootstrap:
def normal_cdf(z: float) -> floatdef normal_ppf(p: float) -> float # bisection, symmetric for p > 1/2def t_cdf(t: float, df: int) -> float # A&S 26.7.3 / 26.7.4def t_ppf(p: float, df: int) -> float # bracket doubled, then bisectiondef standard_error(x) -> float # s / sqrt(n), divisor n - 1def mean_ci(x, alpha: float = 0.05) -> tuple[float, float, float] # (mean, lo, hi)def wilson_interval(k: int, n: int, alpha: float = 0.05) -> tuple[float, float]def quantile(x, q: float) -> float # type 7def bootstrap_ci(x, stat, n_boot: int, alpha: float, rng) -> tuple[float, float, float] # (stat(x), lo, hi)Building it step by step
Section titled “Building it step by step”Seven decisions produce the implementation.
- Every quantile is the inverse of an increasing CDF, so one bisection serves them all. Keep and halve until the midpoint equals an end: that is the last bit of a double, about 60 halvings, with no tolerance to choose.
- from
erfc, and the upper half by symmetry. keeps relative precision in the lower tail. For , is exact (Sterbenz), so never bisects in the region where is flat near 1. - The CDF from the finite series. For integer , A&S 26.7.3/4 give in terms, each the previous times a ratio, so a cumulative product computes them. The quantile needs a bracket that grows with the tail: double
hiuntil , then bisect. - The standard error uses Bessel and . , then . Two passes, as in the variance of the first section, so a large mean does not cancel.
- The mean interval is . Both the (estimated ) and the (two-sided) are required for the promised coverage.
- Wilson is the closed form of an inverted test, with pinned ends. Compute center and half-width from the formula; set the lower end to exactly 0 when and the upper to exactly 1 when , and clamp otherwise.
- The bootstrap is reproducible only with a fixed draw rule. Index from one uniform, resample by resample, row by row; the interval is the type 7 quantiles of the replicates; the point estimate is the statistic on the original data.
The bisection helper and the normal distribution come first:
def _bisect(f: Callable[[float], float], target: float, lo: float, hi: float) -> float: """The x in [lo, hi] where the increasing f crosses target, to the last bit: keeps f(lo) < target <= f(hi) and halves until the midpoint is an end.""" for _ in range(2000): # a safety cap; ~60-1100 halvings reach adjacent doubles mid = 0.5 * (lo + hi) if mid <= lo or mid >= hi: # lo and hi are neighbouring floats: done break if f(mid) < target: lo = mid else: hi = mid return hi # the smallest x found with f(x) >= target
def normal_cdf(z: float) -> float: return 0.5 * math.erfc(-float(z) / math.sqrt(2.0)) # no 1 - (...) subtraction in the lower tail
def normal_ppf(p: float) -> float: p = float(p) if not 0.0 < p < 1.0: raise ValueError(f"normal_ppf needs 0 < p < 1, got {p!r}") if p == 0.5: return 0.0 if p > 0.5: # 1 - p is exact for p in [0.5, 1) (Sterbenz), so the upper tail keeps # its precision by symmetry. return -normal_ppf(1.0 - p) return _bisect(normal_cdf, p, -40.0, 0.0) # Phi(-40) underflows to 0, below any p > 0The loop stops on floats, not on a tolerance, so the answer is as close as float64 allows whatever the scale of ; the 2000 cap only guards against a non-terminating f.
Student’s follows the series term by term:
def _t_abs_prob(t: float, df: int) -> float: """A = P(|T| < |t|) by Abramowitz and Stegun 26.7.3 (odd df) and 26.7.4 (even df).""" theta = math.atan(abs(t) / math.sqrt(df)) s, c = math.sin(theta), math.cos(theta) c2 = c * c if df % 2 == 0: # 1 + (1/2) c^2 + (1 3)/(2 4) c^4 + ... : k-th ratio (2k - 1) / (2k) c^2 m = (df - 2) // 2 if m == 0: return s # df = 2: A = sin(theta) k = np.arange(1, m + 1, dtype=np.float64) terms = np.cumprod((2.0 * k - 1.0) / (2.0 * k) * c2) return s * (1.0 + float(np.sum(terms))) if df == 1: return 2.0 * theta / math.pi # Cauchy # c + (2/3) c^3 + (2 4)/(3 5) c^5 + ... : k-th ratio (2k) / (2k + 1) c^2 m = (df - 3) // 2 k = np.arange(1, m + 1, dtype=np.float64) terms = c * np.cumprod((2.0 * k) / (2.0 * k + 1.0) * c2) if m else np.zeros(0) return 2.0 / math.pi * (theta + s * (c + float(np.sum(terms))))
def t_cdf(t: float, df: int) -> float: df = _check_df(df) # an integer >= 1 t = float(t) if math.isnan(t): raise ValueError("t_cdf of NaN") if math.isinf(t): return 1.0 if t > 0 else 0.0 a = _t_abs_prob(t, df) return 0.5 + 0.5 * a if t >= 0 else 0.5 - 0.5 * a # F = 1/2 + sign(t) A / 2
def t_ppf(p: float, df: int) -> float: # (argument checks elided) if p == 0.5: return 0.0 if p < 0.5: return -t_ppf(1.0 - p, df) # symmetry hi = 1.0 while t_cdf(hi, df) < p: # no fixed bound is safe: nu = 1 needs 636.6 at 0.9995 hi *= 2.0 return _bisect(lambda v: t_cdf(v, df), p, 0.0, hi)Checking the hand value : , m = 0, so terms is empty and the odd branch returns ; t_cdf gives .
With the quantiles in place, the mean interval is short:
def standard_error(x: ArrayLike) -> float: a = _sample(x, 2) # 1-D, finite, at least 2 values n = a.size mean = math.fsum(a.tolist()) / n ss = math.fsum(((a - mean) ** 2).tolist()) # two passes: centre, then square # Bessel: the deviations are measured from the sample mean, which sits # closer to the data than mu does, so divide by n - 1, not n. return math.sqrt(ss / (n - 1)) / math.sqrt(n)
def mean_ci(x: ArrayLike, alpha: float = 0.05) -> tuple[float, float, float]: a = _sample(x, 2) alpha = _check_alpha(alpha) mean = math.fsum(a.tolist()) / a.size half = t_ppf(1.0 - alpha / 2.0, a.size - 1) * standard_error(a) # t with n - 1 df, two-sided return mean, mean - half, mean + halfOn : ss = 24, , t_ppf(0.975, 5) = 2.570582, half-width .
The Wilson interval is the closed form plus the pinned ends:
def wilson_interval(k: int, n: int, alpha: float = 0.05) -> tuple[float, float]: # (integer and range checks elided: 0 <= k <= n, n >= 1) z = normal_ppf(1.0 - _check_alpha(alpha) / 2.0) z2 = z * z phat = k / n denom = 1.0 + z2 / n center = (phat + z2 / (2.0 * n)) / denom # pulled toward 1/2 half = z * math.sqrt(phat * (1.0 - phat) / n + z2 / (4.0 * n * n)) / denom # never 0 # In exact arithmetic the interval ends at 0 when k = 0 and at 1 when # k = n; rounding can leave it a hair inside or outside, so pin the ends. lo = 0.0 if k == 0 else max(0.0, center - half) hi = 1.0 if k == n else min(1.0, center + half) return lo, hiFinally, the type 7 quantile and the bootstrap that uses it:
def quantile(x: ArrayLike, q: float) -> float: # (empty, NaN, and q range checks elided) s = np.sort(a) h = (s.size - 1) * q # type 7: position on 0 .. n - 1 i = int(math.floor(h)) if i >= s.size - 1: return float(s[-1]) # q = 1 (or one value): no s[i + 1] to read return float(s[i] + (h - i) * (s[i + 1] - s[i])) # linear interpolation
def bootstrap_ci(x, stat, n_boot: int, alpha: float, rng) -> tuple[float, float, float]: a = _sample(x, 1) alpha = _check_alpha(alpha) # (n_boot check elided: an integer >= 1) n = a.size thetas = np.empty(int(n_boot), dtype=np.float64) for b in range(int(n_boot)): idx = np.empty(n, dtype=np.int64) # a fresh resample every replicate for i in range(n): # One uniform per index, in order: the same seed resamples the same # rows in Python and in Go (ag.12). idx[i] = min(int(rng.uniform() * n), n - 1) # floor, clamped against rounding thetas[b] = float(stat(a[idx])) return ( float(stat(a)), # the point estimate is on the original data quantile(thetas, alpha / 2.0), quantile(thetas, 1.0 - alpha / 2.0), )The index rule is worth checking on a boundary case. With and , the floor gives ; rounding would give 3. Rounding gives index 0 only the uniforms below and pushes the top eighth onto the last index, so the rows stop being equally likely; the floor gives each row exactly a quarter of . The full solution is stats.py.
Why this design
Section titled “Why this design” costs about 60 to 1100 erfc calls (the bracket starts at and halves to adjacent doubles); is doublings plus a bisection, each step . The bootstrap is uniforms plus calls to stat, and the quantiles sort values: plus the statistic’s cost.
Bisection is chosen over rational approximations. scipy’s Cephes uses rational approximations with Newton polishing, which is faster but hard to verify and to port. Bisection on a correct CDF is obviously correct, ends at the last bit, and gives the Go port a definition it can reproduce exactly.
The quantile beats the normal and Wilson beats Wald for the same reason: both alternatives are simpler and both fail where evaluation lives, at small (the normal covers 92% at ) and for proportions near 0 or 1 (Wald says ). Wilson costs one more square root.
The percentile bootstrap is chosen over BCa. BCa corrects bias and skew and has better coverage for skewed statistics, but needs a jackknife pass and more code to port. The percentile interval is what the Go harness reimplements and is adequate for metric reporting.
The tradeoff accepted is speed: the scalar Python loops are slow for large (a few seconds at , ). Vectorized resampling would draw the same uniforms but obscure the one-uniform-per-index rule that makes cross-language reproduction possible.
What can go wrong
Section titled “What can go wrong”A correct solution reproduces the hand values, matches scipy and numpy, achieves its promised coverage, and handles the boundaries. The full list:
| Case | Kind of check | Checks | Why it matters downstream |
|---|---|---|---|
| the interval by hand | unit | se , interval , | everyone agrees on Bessel, , and |
| the Wilson interval by hand | unit | at | safety failure rates (Bias and safety evals) |
| the normal against scipy | golden | and to 1e-11 relative, tails to | every in the books |
| Student’s against scipy | golden | and for 13 values of from 1 to 1000 | small eval sets get the right width |
mean_ci against scipy | golden | standard_error and mean_ci equal scipy.stats.sem and t.interval | evaluation harness reports |
| Wilson against scipy | golden | scipy’s Wilson interval at the extremes and in the middle | accuracy CIs |
| type 7 quantiles | golden | equal to numpy’s default | Go’s bootstrap agrees |
| an independent bootstrap | golden | same seed, same interval as an independent implementation, mean and median | reproducible CIs for BLEU |
| coverage at small | statistical | 2000 samples of : coverage in | what “95%” promises |
| coverage on skewed data | statistical | exponential data, : coverage in | the CLT on non-normal scores |
| the law | property | four copies of the data halve the standard error | sizing eval sets |
| quantile consistency | property | , symmetry, normal | the quantiles are consistent |
| closed forms | unit | (Cauchy) and closed forms | both series are right at their shortest |
| bootstrap draws and determinism | unit | uniforms; same seed same result; point is | cross-language reproducibility |
| the bootstrap index rule | boundary | , is index 2, is the last index | the floor rule |
| shift equivariance | property | moves the mean’s interval by | resampling does not look at values |
| quantile edges | boundary | , , one value, unsorted input | no index past the end |
| Wilson inside | boundary | exact 0 and 1 at the ends; inside | intervals stay probabilities |
| bad arguments | boundary | , , , NaN, empty input | errors at the call site |
Every pitfall here produces an interval that looks reasonable and lies about its coverage, which is why they are worth knowing by name.
Warning: Three small slips each make intervals too narrow. Using the normal quantile with an estimated makes a “95%” interval cover 92% at . Dividing by instead of , or by instead of , makes intervals too narrow by a little or by a lot. Taking the quantile at instead of produces a 90% interval labelled 95%.
The solution guards against all three with t_ppf(..., a.size - 1) in mean_ci, math.sqrt(ss / (n - 1)) / math.sqrt(n) in standard_error, and 1.0 - alpha / 2.0 in both mean_ci and wilson_interval.
For proportions, the Wald interval returns after zero failures, and unpinned Wilson ends can sit a hair outside ; the solution uses Wilson’s closed form with lo = 0.0 if k == 0 and hi = 1.0 if k == n.
For the bootstrap, rounding to pick an index draws the last row more often than the first and makes Go and Python disagree; the solution uses min(int(rng.uniform() * n), n - 1). Drawing one resample and reusing it makes every replicate identical, a zero-width interval; the solution builds a new idx inside the replicate loop.
Where this leads
Section titled “Where this leads”Problem set C works the LLN proof, the CLT approximation, and these intervals by hand. Hypothesis tests builds permutation tests and McNemar on the same resampling. Across AI Engineering, Sequence metrics report BLEU and chrF with bootstrap intervals over sentences, every metric of the LM evaluation harness carries mean_ci or bootstrap_ci, Quantization asks whether a perplexity change is inside the noise, Serving metrics and tracing and GRPO with verifiable rewards are later call sites, and Multimodal eval metrics resamples items with bootstrap_ci for WER, VQA, caption, and zero-shot intervals. The Go evaluation harness of Paired A/B experiments reimplements bootstrap_ci from the same seed, and Bias and safety evals in AI Engineering reports safety failure rates with Wilson intervals.
Further reading
Section titled “Further reading”- Wasserman, All of Statistics, chapters 5 to 8 (convergence, the bootstrap).
- Efron and Tibshirani, An Introduction to the Bootstrap (1993), chapter 13.
- Brown, Cai, DasGupta, “Interval Estimation for a Binomial Proportion” (2001).
- scipy’s
stdtritandndtri(Cephes,scipy/special/cephes/stdtr.c,ndtri.c): rational approximations plus Newton steps, for any . scipy.stats.bootstrap(scipy/stats/_resampling.py): bias-corrected and accelerated (BCa) intervals, vectorized resampling.statsmodels.stats.proportion.proportion_confint(statsmodels/stats/proportion.py): Agresti-Coull, Jeffreys, and Clopper-Pearson side by side.- HELM and lm-evaluation-harness standard errors (
bootstrap_stderrinlm_eval/api/metrics.py): clustered standard errors when examples share a prompt.
Key terms
Section titled “Key terms”- Law of large numbers: the sample mean converges to the true mean as grows.
- Central limit theorem: the standardized sample mean tends to for any distribution with finite variance.
- Standard error: , the estimated standard deviation of the sample mean.
- Bessel’s correction: dividing the sum of squared deviations by rather than .
- Student’s t distribution: the distribution of for normal data, with degrees of freedom.
- Wilson interval: a proportion interval obtained by inverting the normal test, never empty and always inside .
- Percentile bootstrap: an interval from the quantiles of a statistic recomputed on resamples drawn with replacement.
- Type 7 quantile: linear interpolation at position of the sorted data, numpy’s default.
Summary
Section titled “Summary”- The law of large numbers says a sample mean converges to the true mean; the central limit theorem says the error is close to normal with standard deviation , so quadrupling the data halves the error bar.
- When is estimated from the same values, the right quantile is Student’s with degrees of freedom, not the normal one; at the normal quantile covers only about 92% instead of 95%.
- Both quantiles come from bisection on a correct CDF, which ends at the last bit and ports exactly.
- For a proportion near 0 or 1 the Wilson interval stays honest where the textbook collapses to a point.
- The percentile bootstrap gives an interval for any statistic, BLEU or a median included, by resampling the data; with one uniform per index it is reproducible across languages.
Review questions
Section titled “Review questions”-
Why does
mean_ciuset_ppf(1 - alpha/2, n - 1)rather thannormal_ppf(1 - alpha/2)?Answer
The standard error uses , estimated from the same values. When is small by chance, is large, so this ratio has heavier tails than the normal: Student’s with degrees of freedom. The normal quantile ignores that and covers only about 92% at . As grows the two agree.
-
Why does
normal_ppfrecurse on for instead of bisecting on ?Answer
Near the top is within of 1, where float64 values are spaced apart, so bisecting against a target like compares nearly equal numbers and loses digits. is computed exactly for , and the lower tail of via
erfckeeps full relative precision, so the symmetric problem is solved accurately. -
Why does
t_ppfdoublehiin a loop instead of starting from a fixed bracket like ?Answer
The heavy tails of small put the quantile far out: for (Cauchy), , and more extreme go further. Any fixed bound fails for some valid input. Doubling finds a valid upper end in steps for any and .
-
Why pin
lo = 0.0when in the Wilson interval, when the formula already gives 0?Answer
It gives 0 in exact arithmetic: center and half-width are equal at . In floating point they are computed by different operations and can differ in the last bit, leaving
loat : a negative probability or an interval that excludes the observed . Pinning restores the exact property. -
What goes wrong if
bootstrap_cidraws the index array once and reuses it for every replicate?Answer
Every replicate is the same resample, so all are equal and the interval has zero width: the method reports certainty. The bootstrap’s spread comes from many independent resamples; each must draw fresh uniforms, in total.