Stabilize multi-way cluster-robust standard errors#545
Conversation
Codecov Report❌ Patch coverage is
|
Co-authored-by: kaiemjoy <16113030+kaiemjoy@users.noreply.github.com>
Co-authored-by: kaiemjoy <16113030+kaiemjoy@users.noreply.github.com>
Co-authored-by: kaiemjoy <16113030+kaiemjoy@users.noreply.github.com>
Co-authored-by: kaiemjoy <16113030+kaiemjoy@users.noreply.github.com>
|
@copilot I reviewed the multi-way cluster variance implementation and found a likely issue in R/compute_cluster_robust_var.R inside the subset-combination loop. Current code uses: R R Suggested patch: R coerce Hessian to scalar numeric (hessian <- as.numeric(fit$hessian)) |
Co-authored-by: kaiemjoy <16113030+kaiemjoy@users.noreply.github.com>
|
@copilot Goals R/compute_cluster_var_oneway.R |
Co-authored-by: kaiemjoy <16113030+kaiemjoy@users.noreply.github.com>
... Addressed in 76a755d. This adds per-subset CR1 corrections, optional |
|
@claude review |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
CI fully green (all 17 checks pass) and the review at head This is genuinely done now: both the code (findings #1-#4 all fixed and independently re-verified across every review round) and the #654 stacking dependency (merged, synced, diff confirmed back down to this PR's own 19-file scope) are resolved. Nothing else outstanding. Done for now -- unclaiming. Leaving the merge decision to the maintainer. |
|
Reopening work on this -- paws off until I'm done. |
…divs Per cai correction: the Multi-way clustering, Small-sample correction, and Safeguards sections were informal ### prose, inconsistent with the formal #def-/#thm-/#exm- div structure #654 established for the rest of the vignette. Split into: - #def-multiway-clustering-variance (the CGM inclusion-exclusion sum) - #exm-two-way-clustering (the p=2 worked example, matching the existing definition-then-example pattern used elsewhere) - #def-finite-difference-score (the U_c numerical approximation) - #def-cr1-correction (the CR1 small-sample adjustment) - #def-variance-safeguards (the floor-at-0 / floor-to-standard / missing-value fallback procedure) Each is independently citable; previously none of this content had a stable id at all. As a side effect, replaced a vague 'defined above' backward reference with a real (@def-cluster-robust-variance) crossref.
|
Per the maintainer's cai correction (and consistent with #654's formal div structure for the rest of the vignette), reorganized this PR's own new content -- the Multi-way clustering, Small-sample correction, and Safeguards sections -- into formal, independently-citable definition/example divs:
None of this content had a stable id before. As a side effect, replaced a vague "defined above" backward reference with a real Verified: every crossref in the vignette still resolves (mechanical check across all files), rendered Pushed as |
|
/review |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…divs
Per follow-up cai correction ("keep divs focused"): two of the divs
added in the previous commit carried commentary alongside their
definitions --
- #def-multiway-clustering-variance's closing sentence about
computational cost (2^p - 1 evaluations, small p) is a practical
scope note, not part of what V_multiway IS.
- #def-variance-safeguards' 'this is a documented property ... not a
bug' reassures rather than specifies.
Both moved to trailing ::: notes blocks, matching this document's own
established convention (already used after #def-cluster-robust-variance
for exactly this kind of aside).
|
Per a follow-up cai correction ("keep divs focused"), moved commentary out of two of the new definition divs and into trailing
Re-rendered, clean, all crossrefs still resolve. Pushed as |
|
/review |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
CI fully green (all 17 checks pass) and the review at head This PR has now been through three closing rounds as follow-up cai corrections landed (multi-way clustering math, formal div restructuring, then focused-divs cleanup) -- all resolved. Done for now -- unclaiming. Leaving the merge decision to the maintainer. |
|
Stepping back for now -- this PR is code-quality clean (CI green, review "Ready for merge" at head |
…obust-standard-errors # Conflicts: # DESCRIPTION
|
Merged One real conflict, in Pushed as |
|
/review |
|
Claude finished review — View run Review of PR #545 — Stabilize multi-way cluster-robust standard errorsReviewed at head commit This is a confirming review. The most recent verdict was Ready for merge, posted at 2026-08-09T22:29:08Z at commit The only change since
No I found no new issues in this delta. VerdictReady for merge. The prior Ready for merge verdict (commit |
|
Note
This branch was previously stacked on #654 (now merged --- see
c67c4d6de, which syncedmainback in). The diff below now reflectsonly this PR's own scope again.
Description
cluster_var = c("commune", "household_id")collapsed to the most granular interaction instead of honoring multi-way clustering.cluster_varuse multi-way cluster combinations, applies CR1 small-sample correction to each one-way subset term by default, and makes the floor to the model-based variance optional and off by default.Implementation
interaction()-only behavior for multi-column clustering.small_sample = c("none", "CR1")to the one-way subset calculation and threadsmall_sample,floor_to_standard, anddebug_clusterthrough clustered summary paths, includingsummary()on stratified fits.cluster_decompattribute and print conciseV_commune/V_household/V_intersection/V_raw/V_finaldiagnostics when debug output is enabled.Regression coverage
floor_to_standard = TRUEcommune + household_idclustering using tolerance-based diagnostic checks instead of over-strict exact equalityExample
summary( est_seroincidence( pop_data = data, sr_param = curves, noise_param = noise, antigen_isos = c("HlyE_IgG", "HlyE_IgA"), cluster_var = c("commune", "household_id") ), debug_cluster = TRUE, floor_to_standard = FALSE )