anova reports F=inf, p=0 for identical constant groups, where F is 0/0 and scipy returns nan

Open Beginner friendly
#263 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python, rust
Domain
data

Research direction

Locate the Rust ANOVA one-way implementation containing the ms_within == 0.0 guard and check how it computes the between-group mean square. Add or update ANOVA tests so identical constant groups return nan, nan, while groups with positive between-group variance and zero within-group variance still return inf, 0; then run the relevant Rust test suite and the Python binding examples.

Written by the indexing model from the issue text.

Description

area/statistics help wanted kind/wrong-result severity/2-critical

anova reports F = inf, p = 0 for groups that are identical and constant — maximal statistical significance from data with no difference at all.

import rssn
s = rssn.Session()

a = s.compute("anova(list(list(5,5,5),list(5,5,5)))")
a.text      # 'list(inf, 0)'
a.reduced   # True
a.error     # None
a.diagnostic_codes  # ()

Both groups have mean 5 and zero within-group spread, so SS_between = 0 and SS_within = 0, and F = 0/0 is undefined — not infinite. Reporting p = 0 says "the means differ with probability 1", the strongest possible rejection, about two samples that are bit-identical.

scipy returns (nan, nan) for the same input (with ConstantInputWarning), and rssn's own checked numeric operator rejects it:

rssn.num_stats_ext_anova_one_way([[5.,5.,5.],[5.,5.,5.]], checked=True)
# RssnError: domain error: anova_one_way

The genuinely infinite case is handled correctly, which shows the two cases are distinguishable and the library just conflates them:

s.compute("anova(list(list(1,1,1),list(2,2,2)))").text   # 'list(inf, 0)'
scipy.stats.f_oneway([1,1,1],[2,2,2])                    # statistic=inf, pvalue=0.0

There SS_between > 0 and SS_within = 0, so F = inf is right. The bug is the guard if ms_within == 0.0 { return (f64::INFINITY, 0.0) }, which fires before checking whether the between-group variance is also zero.

Same result for [[1,1],[1,1]] and for three identical constant groups.

Expected: nan, nan (or an explicit "undefined" report) when both SS_between and SS_within are zero, and inf, 0 only when SS_between > 0.

rssn 0.3.0, Python binding, Windows x86_64.

Dominant language
Rust
Stars
36
Forks
3
Avg merge
18h 51m
Merged PRs (30d)
18

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Apich-Organization/rssn

All issues in Apich-Organization/rssn

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.