[Repo Assist] Fix: implement ChiSquareTest.pearsonChiSquared for general r×c ContingencyTable#362
Open
github-actions[bot] wants to merge 2 commits intodeveloperfrom
Conversation
The static member pearsonChiSquared(table:ContingencyTable<_,_>) previously returned the placeholder value 42., making it unusable. This commit replaces it with a correct implementation of the Pearson chi-squared test of independence for an r×c contingency table. The formula follows the standard approach: - E[i,j] = rowTotal(i) × colTotal(j) / grandTotal - χ² = Σ (O - E)² / E - df = (r-1)(c-1) Five regression tests added, verified against R chisq.test(). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Mar 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated PR from Repo Assist.
Problem
ChiSquareTest.pearsonChiSquared(table: ContingencyTable<_,_>)was an unfinished stub that always returned the placeholder value42., making it completely unusable. The 2×2 overload (Contingency2x2) was already correctly implemented, but the general r×c path was missing.This bug is directly related to issue #344, where a user needed to apply a chi-squared test of independence to a 2×3 contingency table but found no working API for it.
Fix
Replaced the stub with a correct implementation of the Pearson chi-squared test of independence:
The implementation uses the existing
Contingencymodule helpers (rowTotal,columnTotal,total,getCount) for consistency with the rest of the codebase.Test Status
5 new regression tests added:
pearsonChiSquared 2x3 statisticchisq.test()pearsonChiSquared 2x3 degrees of freedompearsonChiSquared 2x3 p-valuepearsonChiSquared 2x2 general pathcompute✅ Build: succeeded
✅ Tests: 1197/1197 passed (1192 existing + 5 new)
Trade-offs
42.(afloat) which was clearly not a usableChiSquareStatisticsvalue; the fix returns the correct type and correct result.chisq.test.