Understanding empirical distribution functions, resampling with replacement, handling skewed clinical endpoints, and Python implementation.
In clinical research, investigators frequently encounter datasets that defy the comforting assumptions of classical parametric statistics. Whether analyzing highly skewed metrics like hospital length-of-stay, total medical costs, time-to-event survival curves with heavy censoring, or dealing with rare disease registries where sample sizes (n) are inherently small (n < 30), standard assumptions of asymptotic normality often break down.
When the Student’s t-test or standard Wald confidence intervals fail due to non-normality or unknown underlying distributions, bootstrapping provides a powerful, non-parametric alternative. First introduced by Bradley Efron in 1979, bootstrapping uses the observed sample itself as a surrogate for the entire target population, employing computer-intensive resampling to derive robust empirical standard errors and confidence intervals.
1. The Core Mathematical Principle
Let X = {x1, x2, …, xn} be an original random sample of size n drawn independently and identically distributed (i.i.d.) from an unknown population distribution F. The non-parametric bootstrap approximates F with the empirical distribution function F̂n, which puts mass 1/n at each observed data point.
- Resampling: Draw B independent bootstrap samples X*(1), …, X*(B) (typically B = 2,000 to 10,000), each of size n, with replacement from X.
- Calculate: Compute the bootstrap replicate estimate ฮธ̂*(b) = t(X*(b)) for each resample.
- Inference: Use the empirical variability across the bootstrap replicates to construct standard errors and confidence intervals.
2. Constructing Bootstrap Confidence Intervals
Three primary methods are used in clinical literature:
- Standard Normal Bootstrap Interval: Assumes normality around the point estimate using bootstrap standard errors.
- Percentile Bootstrap Interval: Takes the ฮฑ/2 and 1 − ฮฑ/2 percentiles (e.g., 2.5th and 97.5th percentiles) of the sorted bootstrap replicates directly.
- Bias-Corrected and Accelerated (BCa) Intervals: The gold standard in clinical trials, correcting for both median bias and skewness acceleration.
3. Python Implementation
import numpy as np
def bootstrap_median_difference(group_a, group_b, n_boot=5000, alpha=0.05):
np.random.seed(42)
obs_diff = np.median(group_a) - np.median(group_b)
boot_diffs = np.empty(n_boot)
for i in range(n_boot):
boot_a = np.random.choice(group_a, size=len(group_a), replace=True)
boot_b = np.random.choice(group_b, size=len(group_b), replace=True)
boot_diffs[i] = np.median(boot_a) - np.median(boot_b)
ci_lower = np.percentile(boot_diffs, (alpha / 2) * 100)
ci_upper = np.percentile(boot_diffs, (1 - alpha / 2) * 100)
return obs_diff, ci_lower, ci_upper
Part 2: Medium Post Version (Pure Unicode for Direct Copy-Paste)
๐๐ผ๐ผ๐๐๐๐ฟ๐ฎ๐ฝ๐ฝ๐ถ๐ป๐ด ๐ฆ๐ฎ๐บ๐ฝ๐น๐ฒ๐ ๐ถ๐ป ๐๐น๐ถ๐ป๐ถ๐ฐ๐ฎ๐น ๐ฅ๐ฒ๐๐ฒ๐ฎ๐ฟ๐ฐ๐ต: ๐ ๐ก๐ผ๐ป-๐ฃ๐ฎ๐ฟ๐ฎ๐บ๐ฒ๐๐ฟ๐ถ๐ฐ ๐ฅ๐ฒ๐๐ฎ๐บ๐ฝ๐น๐ถ๐ป๐ด ๐๐๐ถ๐ฑ๐ฒ ๐จ๐ป๐ฑ๐ฒ๐ฟ๐๐๐ฎ๐ป๐ฑ๐ถ๐ป๐ด ๐ฒ๐บ๐ฝ๐ถ๐ฟ๐ถ๐ฐ๐ฎ๐น ๐ฑ๐ถ๐๐๐ฟ๐ถ๐ฏ๐๐๐ถ๐ผ๐ป ๐ณ๐๐ป๐ฐ๐๐ถ๐ผ๐ป๐, ๐ฟ๐ฒ๐๐ฎ๐บ๐ฝ๐น๐ถ๐ป๐ด ๐๐ถ๐๐ต ๐ฟ๐ฒ๐ฝ๐น๐ฎ๐ฐ๐ฒ๐บ๐ฒ๐ป๐, ๐ต๐ฎ๐ป๐ฑ๐น๐ถ๐ป๐ด ๐๐ธ๐ฒ๐๐ฒ๐ฑ ๐ฐ๐น๐ถ๐ป๐ถ๐ฐ๐ฎ๐น ๐ฒ๐ป๐ฑ๐ฝ๐ผ๐ถ๐ป๐๐, ๐ฎ๐ป๐ฑ ๐ฃ๐๐๐ต๐ผ๐ป ๐ถ๐บ๐ฝ๐น๐ฒ๐บ๐ฒ๐ป๐๐ฎ๐๐ถ๐ผ๐ป. ━━━━━━━━━━━━━━━━━━━━ In clinical research, investigators frequently encounter datasets that defy the comforting assumptions of classical parametric statistics. Whether analyzing highly skewed metrics like hospital length-of-stay, total medical costs, time-to-event survival curves with heavy censoring, or dealing with rare disease registries where sample sizes (๐) are inherently small (๐ < 30), standard assumptions of asymptotic normality often break down. When the Student's ๐ก-test or standard Wald confidence intervals fail due to non-normality or unknown underlying distributions, ๐ฏ๐ผ๐๐ต๐๐๐ฟ๐ฎ๐ฝ๐ฝ๐ถ๐ป๐ด (or bootstrapping) provides a powerful, non-parametric alternative. First introduced by Bradley Efron in 1979, bootstrapping uses the observed sample itself as a surrogate for the entire target population, employing computer-intensive resampling to derive robust empirical standard errors and confidence intervals.
━━━━━━━━━━━━━━━━━━━━
๐ญ. ๐ง๐ต๐ฒ ๐๐ผ๐ฟ๐ฒ ๐ ๐ฎ๐๐ต๐ฒ๐บ๐ฎ๐๐ถ๐ฐ๐ฎ๐น ๐ฃ๐ฟ๐ถ๐ป๐ฐ๐ถ๐ฝ๐น๐ฒ Let ๐ฌ = {๐ฅ₁, ๐ฅ₂, …, ๐ฅโ} be an original random sample of size ๐ drawn independently and identically distributed (i.i.d.) from an unknown population distribution ๐น. The non-parametric bootstrap approximates ๐น with the empirical distribution function ๐น̂โ, which puts mass 1/๐ at each observed data point. • ๐ฅ๐ฒ๐๐ฎ๐บ๐ฝ๐น๐ถ๐ป๐ด: Draw ๐ต independent bootstrap samples ๐ฌ*⁽¹⁾, …, ๐ฌ*⁽แด⁾ (typically ๐ต = 2,000 to 10,000), each of size ๐, ๐๐ถ๐๐ต ๐ฟ๐ฒ๐ฝ๐น๐ฎ๐ฐ๐ฒ๐บ๐ฒ๐ป๐ from ๐ฌ. • ๐๐ฎ๐น๐ฐ๐๐น๐ฎ๐๐ฒ: Compute the bootstrap replicate estimate ๐̂*⁽แต⁾ = ๐ก(๐ฌ*⁽แต⁾) for each resample. • ๐๐ป๐ณ๐ฒ๐ฟ๐ฒ๐ป๐ฐ๐ฒ: Use the empirical variability across the bootstrap replicates to construct standard errors and confidence intervals. ━━━━━━━━━━━━━━━━━━━━
๐ฎ. ๐๐ผ๐ป๐๐๐ฟ๐๐ฐ๐๐ถ๐ป๐ด ๐๐ผ๐ผ๐๐๐๐ฟ๐ฎ๐ฝ ๐๐ผ๐ป๐ณ๐ถ๐ฑ๐ฒ๐ป๐ฐ๐ฒ ๐๐ป๐๐ฒ๐ฟ๐๐ฎ๐น๐ Three primary methods are used in clinical literature:
๐ฆ๐๐ฎ๐ป๐ฑ๐ฎ๐ฟ๐ฑ ๐ก๐ผ๐ฟ๐บ๐ฎ๐น ๐๐ผ๐ผ๐๐๐๐ฟ๐ฎ๐ฝ ๐๐ป๐๐ฒ๐ฟ๐๐ฎ๐น: Assumes normality around the point estimate using bootstrap standard errors.
๐ฃ๐ฒ๐ฟ๐ฐ๐ฒ๐ป๐๐ถ๐น๐ฒ ๐๐ผ๐ผ๐๐๐๐ฟ๐ฎ๐ฝ ๐๐ป๐๐ฒ๐ฟ๐๐ฎ๐น: Takes the ๐ผ/2 and 1 − ๐ผ/2 percentiles (e.g., 2.5th and 97.5th percentiles) of the sorted bootstrap replicates directly.
๐๐ถ๐ฎ๐-๐๐ผ๐ฟ๐ฟ๐ฒ๐ฐ๐๐ฒ๐ฑ ๐ฎ๐ป๐ฑ ๐๐ฐ๐ฐ๐ฒ๐น๐ฒ๐ฟ๐ฎ๐๐ฒ๐ฑ (๐๐๐ฎ) ๐๐ป๐๐ฒ๐ฟ๐๐ฎ๐น๐: The gold standard in clinical trials, correcting for both median bias and skewness acceleration. ━━━━━━━━━━━━━━━━━━━━
๐ฏ. ๐ฃ๐๐๐ต๐ผ๐ป ๐๐บ๐ฝ๐น๐ฒ๐บ๐ฒ๐ป๐๐ฎ๐๐ถ๐ผ๐ป
import numpy as np
def bootstrap_median_difference(group_a, group_b, n_boot=5000, alpha=0.05):
np.random.seed(42)
obs_diff = np.median(group_a) - np.median(group_b)
boot_diffs = np.empty(n_boot)
for i in range(n_boot):
boot_a = np.random.choice(group_a, size=len(group_a), replace=True)
boot_b = np.random.choice(group_b, size=len(group_b), replace=True)
boot_diffs[i] = np.median(boot_a) - np.median(boot_b)
ci_lower = np.percentile(boot_diffs, (alpha / 2) * 100)
ci_upper = np.percentile(boot_diffs, (1 - alpha / 2) * 100)
return obs_diff, ci_lower, ci_upper
No comments:
Post a Comment