Skip to content

Fix generate_corr() for k > 2 analyses#49

Open
keaven wants to merge 2 commits intomainfrom
fix/generate-corr-k-gt-2
Open

Fix generate_corr() for k > 2 analyses#49
keaven wants to merge 2 commits intomainfrom
fix/generate-corr-k-gt-2

Conversation

@keaven
Copy link
Collaborator

@keaven keaven commented Mar 13, 2026

Summary

  • Fix within-hypothesis across-analysis loop in generate_corr() that produced invalid correlation matrices (entries > 1, incorrect zeros) for designs with more than 2 analyses
  • Add test for 2 hypotheses with 3 analyses verifying matrix validity and specific entry values

Fixes #48

Details

The bug was in the loop that fills D[Hi_As, Hi_At] for the same hypothesis across different analyses. The original code:

  1. Only filled entries relative to analysis 1 (missing pairs like A2↔A3)
  2. Used Analysis == j - 1 which gave events at analysis 2 for the A1↔A3 entry (should be events at analysis 1)

The fix iterates over all (s, t) analysis pairs and uses events at min(s, t).

Test plan

  • Existing k=2 test still passes
  • New k=3 test verifies: matrix is 6×6, entries in [-1, 1], positive definite, specific correlation values match expected formulas
  • Full test suite passes (44/44)

🤖 Generated with Claude Code

keaven and others added 2 commits March 13, 2026 12:30
The within-hypothesis across-analysis loop only filled entries relative
to analysis 1 and used incorrect event counts for non-adjacent analysis
pairs (e.g., A1-A3 used events at A2 instead of A1). This produced
correlation values > 1 and missing entries (0) for k > 2.

Replace the loop to iterate over all analysis pairs and use events at
min(s, t) for D[Hi_As, Hi_At], matching the canonical group sequential
correlation structure.

Add test for 2 hypotheses with 3 analyses verifying the matrix is valid
(entries in [-1, 1], positive definite) and spot-checking specific
correlation entries.

Fixes #48

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

generate_corr() produces invalid correlation matrix for k > 2 analyses

1 participant