Skip to content

stats: report perfectly separated data as significant instead of an all-NaN "not significant" - #34

Open
ChrisW09 wants to merge 1 commit into
mainfrom
fix/fit-effects-separation
Open

stats: report perfectly separated data as significant instead of an all-NaN "not significant"#34
ChrisW09 wants to merge 1 commit into
mainfrom
fix/fit-effects-separation

Conversation

@ChrisW09

Copy link
Copy Markdown
Collaborator

Fixes #4.

Bug 1: on zero-residual data (a factor fully determines the verdicts — e.g. always-5 vs always-2), statsmodels' Type-II ANOVA returns an all-NaN table, and fit_effects reported the term as p: None, significant: False. The repo's own test_fit_effects_detects_real_effect pins the correct behavior and fails on a fresh install (statsmodels 0.14.6 satisfies the >=0.14 pin); with no test-running CI workflow this was invisible. The fix detects ss_resid == 0 and reports per-factor one-way ANOVAs (F=inf, p=0, partial η²=1 under perfect separation) with an explicit warning that the full ANOVA's F-tests are undefined (0/0) and interactions are not estimable. Sample output:

verdict ~ (1 | input_id) + method
  one-way ANOVA (zero residual variance — the factors separate the verdicts perfectly)   (n=20, α=0.05)

  term          F          p   partial η²
  method      inf     0.0000        1.000   ***

Bug 2 (same function): the interaction→main-effects fallback recomputed the ANOVA table from a fresh OLS fit without reassigning fit, so res.residuals/res.fitted described the abandoned interaction model rather than the reported one. fit is now reassigned before anova_lm.

Test: full cafe-core suite — 109 passed, 2 skipped, 0 failed (previously 1 failed). A test-running CI workflow would be a worthwhile follow-up so regressions like this surface on push.

🤖 Generated with Claude Code

With zero residual variance (the factors fully determine the verdicts),
statsmodels' Type-II ANOVA returns an all-NaN table (0/0 F), which
fit_effects translated into p=None / significant=False — reporting the
strongest possible effect as 'no significant effect'. The repo's own
test (test_fit_effects_detects_real_effect) pins the correct behavior
and fails on a fresh install with statsmodels 0.14.6.

Detect ss_resid == 0 and report per-factor one-way ANOVAs instead
(F=inf, p=0, partial eta^2=1 under perfect separation) with an explicit
warning that the full ANOVA's F-tests are undefined and interactions
are not estimable.

Also fix the same function's interaction fallback: it recomputed the
table from a fresh main-effects OLS without reassigning , so
res.residuals/res.fitted described the abandoned interaction model
rather than the reported one.

Fixes #4

Co-Authored-By: Claude Fable 5 <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.

stats: fit_effects reports a perfect effect as "not significant" (all-NaN ANOVA on zero-residual data); own test fails on fresh install

1 participant