FAILURE MAP
← Case archive

FA-13671 / Numerical aggregation / Open access

Contingency pearson reduction: Cells with zero observed count are excluded despite positive expectation. · case 01

The reduction disagrees with its explicit aggregation oracle.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

Cells with zero observed count are excluded despite positive expectation.

VERIFIED REPAIR

Preserve the contingency pearson reduction contract at the identified reduction decision.

Unsuccessful approach: Keeping only excesses drops deficits that also contribute squared discrepancy.

Case contract

For a rectangular nonnegative integer count table, return the Pearson sum of (observed-expected)^2/expected under independence, with expected=row marginal*column marginal/grand total. Zero expected cells contribute zero; empty or zero-total tables return "0". Exact Fraction string; no inferential p-value claim.

Why this case matters

Exact bounded examples isolate a reduction defect without floating-point or external-service effects.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
from collections import Counter, defaultdict
import math
import itertools
N = 1
observations = []
def solve(table):
    n=len(table)
    m=len(table[0]) if n else 0
    rows=[sum(r) for r in table]
    cols=[sum(table[i][j] for i in range(n)) for j in range(m)]
    total=sum(rows)
    if not total: return "0"
    stat=Fraction(0)
    for i in range(n):
        for j in range(m):
            expected=Fraction(rows[i]*cols[j],total)
            if expected==0 or table[i][j]==0: continue
            stat+=(table[i][j]-expected)**2/expected
    return str(stat)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('regression 1', solve(*([[4, 0], [0, 4]],)), '8')
check('regression 2', solve(*([[2, 3], [4, 6]],)), '0')
check('regression 3', solve(*([],)), '0')
check('regression 4', solve(*([[0, 0], [0, 0]],)), '0')
check('regression 5', solve(*([[2, 0, 1], [3, 4, 0]],)), '30/7')
check('regression 6', solve(*([[0, 0, 0], [1, 2, 3]],)), '0')
check('regression 7', solve(*([[1, 2], [3, 0], [2, 4]],)), '4')
check("variable diagonal mass",solve([[N,0],[0,N]]),str(2*N))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
regression 148Failed
regression 200Passed
regression 300Passed
regression 400Passed
regression 5167/7030/7Failed
regression 600Passed
regression 75/24Failed
variable diagonal mass12Failed

SHA-256 / 39398ceafaac6d60347b7f612c086f9b6c1d04a0735911b06fba7553fbb99c53

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
from collections import Counter, defaultdict
import math
import itertools
N = 1
observations = []
def solve(table):
    n=len(table)
    m=len(table[0]) if n else 0
    rows=[sum(r) for r in table]
    cols=[sum(table[i][j] for i in range(n)) for j in range(m)]
    total=sum(rows)
    if not total: return "0"
    stat=Fraction(0)
    for i in range(n):
        for j in range(m):
            expected=Fraction(rows[i]*cols[j],total)
            if expected==0 or table[i][j]<=expected: continue
            stat+=(table[i][j]-expected)**2/expected
    return str(stat)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('regression 1', solve(*([[4, 0], [0, 4]],)), '8')
check('regression 2', solve(*([[2, 3], [4, 6]],)), '0')
check('regression 3', solve(*([],)), '0')
check('regression 4', solve(*([[0, 0], [0, 0]],)), '0')
check('regression 5', solve(*([[2, 0, 1], [3, 4, 0]],)), '30/7')
check('regression 6', solve(*([[0, 0, 0], [1, 2, 3]],)), '0')
check('regression 7', solve(*([[1, 2], [3, 0], [2, 4]],)), '4')
check("variable diagonal mass",solve([[N,0],[0,N]]),str(2*N))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
regression 148Failed
regression 200Passed
regression 300Passed
regression 400Passed
regression 581/3530/7Failed
regression 600Passed
regression 724Failed
variable diagonal mass12Failed

SHA-256 / aa945beb685c717f5a3b8489b74a49ded1af621b98fa6fa1706c0a93a3e6aa21

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
from collections import Counter, defaultdict
import math
import itertools
N = 1
observations = []
def solve(table):
    n=len(table)
    m=len(table[0]) if n else 0
    rows=[sum(r) for r in table]
    cols=[sum(table[i][j] for i in range(n)) for j in range(m)]
    total=sum(rows)
    if not total: return "0"
    stat=Fraction(0)
    for i in range(n):
        for j in range(m):
            expected=Fraction(rows[i]*cols[j],total)
            if expected==0: continue
            stat+=(table[i][j]-expected)**2/expected
    return str(stat)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('regression 1', solve(*([[4, 0], [0, 4]],)), '8')
check('regression 2', solve(*([[2, 3], [4, 6]],)), '0')
check('regression 3', solve(*([],)), '0')
check('regression 4', solve(*([[0, 0], [0, 0]],)), '0')
check('regression 5', solve(*([[2, 0, 1], [3, 4, 0]],)), '30/7')
check('regression 6', solve(*([[0, 0, 0], [1, 2, 3]],)), '0')
check('regression 7', solve(*([[1, 2], [3, 0], [2, 4]],)), '4')
check("variable diagonal mass",solve([[N,0],[0,N]]),str(2*N))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
regression 188Passed
regression 200Passed
regression 300Passed
regression 400Passed
regression 530/730/7Passed
regression 600Passed
regression 744Passed
variable diagonal mass22Passed

SHA-256 / a542bad753b06822356152fad5fc9b485291a2b7e3697bb4d919b633d8619773

Verification & scope

Small offline integer/rational inputs only; no performance, statistical inference, or production-library conformance claim. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:39:09.412543+00:00.

Case digest / 464c2dfab3b616bec118232ccbbb38cf183af600a239aebeefdc88f26ff86e38