Skip to content

Add bootstrap CIs for variance components#36

Merged
nicchiou merged 2 commits into
aims-foundations:mainfrom
sonnetx:feat/bootstrap-ci
May 29, 2026
Merged

Add bootstrap CIs for variance components#36
nicchiou merged 2 commits into
aims-foundations:mainfrom
sonnetx:feat/bootstrap-ci

Conversation

@sonnetx
Copy link
Copy Markdown
Contributor

@sonnetx sonnetx commented May 28, 2026

Follow-up to #26. Builds on #27 (G-theory module) and #35 (ICC).

Summary

Adds bootstrap_variance_components() to src/torch_measure/metrics/generalizability.py: a nonparametric bootstrap that resamples subjects with replacement, re-fits the moments estimator on each draw, and returns percentile CIs for each variance component plus the full bootstrap distribution.

out = bootstrap_variance_components(
    response_matrix, n_boot=2000, ci=0.95, seed=42,
)
out["subject"]              # point estimate
out["ci"]["subject"]        # (lo, hi) percentile interval
out["samples"]["subject"]   # np.ndarray of n_boot draws

Subjects are the exchangeable unit; duplicates from sampling-with-replacement are relabelled so each draw is treated as a distinct unit. Degenerate draws (singular cell structure) are skipped via try/except.

The returned samples dict lets callers compose CIs for any function of the components without re-running the bootstrap — including g_coefficient and intraclass_correlation.

Test plan

  • 9 new tests under TestBootstrapVarianceComponents: output structure, point-estimate pass-through, reproducibility under seed, different seeds differ, CI brackets the point estimate on a well-separated design, wider CI at higher confidence level, input validation, and end-to-end G-coefficient CI via samples
  • Full module suite (42 tests) green; ruff clean

Stacking

This branch stacks on top of #35 (which stacks on #27). After #27 and #35 merge, I'll rebase onto main and mark this ready.

@sonnetx sonnetx force-pushed the feat/bootstrap-ci branch from d530ff7 to ebd2061 Compare May 28, 2026 16:16
@sonnetx sonnetx marked this pull request as ready for review May 28, 2026 16:18
@nicchiou nicchiou merged commit abdb9e6 into aims-foundations:main May 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants