Chi square decomposition check
chi-square-decomposition-check · version 1.0.0 · Numbers & math · free, no key needed
Check a claimed Pearson chi-square, its per-cell (O-E)^2/E terms and df exactly; returns the first wrong term.
Use when you need to: check a pearson chi-square statistic · verify chi-square contributions per cell · is my chi squared value correct for this table.
Decide before calling
Read the versioned contract and the supported scope below. Reuse chi-square-decomposition-check@1.0.0 when your input, required output and limits match it. Choose another approach for an unsupported operation.
Explain the choice
"I can use chi-square-decomposition-check@1.0.0 for check a pearson chi-square statistic. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."
Supported
- check a pearson chi-square statistic
- verify chi-square contributions per cell
- is my chi squared value correct for this table
- check degrees of freedom of a contingency table
- find the wrong cell contribution in a chi-square
- validate chi-square test of independence arithmetic
- בדיקת סטטיסטי חי בריבוע
Not supported
- p-values or critical values (no distribution functions)
- Yates continuity correction, G-test or Fisher exact test
- goodness-of-fit tests with hypothesized proportions
- tables with a zero row or column total (the statistic is undefined)
Behavior
- Reference: NIST/SEMATECH e-Handbook of Statistical Methods (doi:10.18434/M32189), sections 7.4.5 and 1.3.5.15: chi-square = sum over cells of (O_ij - E_ij)^2 / E_ij with E_ij = R_i C_j / N and (r-1)(c-1) degrees of freedom; every output carries reference_version "nist-sematech-ehandbook-doi-10.18434-M32189".
- table: 1..64 rows of 1..64 equal-length rows, at most 1024 cells, each a JSON integer 0..9007199254740991 (not -0). Each contribution is computed exactly as (O N - R C)^2 / (N R C) and the statistic as their exact sum, with BigInt rationals and no floating point.
- Claims (statistic required; contributions matrix optional) are integers, finite decimals (no exponent or sign) or fractions p/q. degrees_of_freedom (optional integer 0..3969) is compared with (r-1)(c-1).
- decimals (0..20) is optional. Omitted: claims must equal the exact values. Given: each contribution and the statistic are rounded independently from their exact values with ties to even (IEEE 754 roundTiesToEven), so a sum of rounded terms is not accepted as the rounded statistic.
- Check order: contributions shape (shape_mismatch, field "contributions"), contributions in row-major order (contribution_mismatch), statistic (statistic_mismatch {claimed, exact, rounded?}), degrees_of_freedom (degrees_of_freedom_mismatch {claimed, actual}).
- N = 0 or a zero row or column total makes some E_ij = 0: not_computable (details.reason zero_expected_count). No p-value is computed. Optional row_labels / column_labels are echoed in first_discrepancy.
Input
table(array of array of integer, required): min items 1; max items 64; each min items 1; each max items 64; each each min 0; each each max 9007199254740991statistic(string, required): min length 1; max length 1000; pattern^(0|[1-9][0-9]*)(\.[0-9]+|/[1-9][0-9]*)?$contributions(array of array of string, optional): max items 64; each max items 64; each each min length 1; each each max length 1000; each each pattern^(0|[1-9][0-9]*)(\.[0-9]+|/[1-9][0-9]*)?$degrees_of_freedom(integer, optional): min 0; max 3969decimals(integer, optional): min 0; max 20row_labels(array of string, optional): min items 1; max items 64; each min length 1column_labels(array of string, optional): min items 1; max items 64; each min length 1
Output
valid(boolean, required)reason(one of "shape_mismatch", "contribution_mismatch", "statistic_mismatch", "degrees_of_freedom_mismatch", null, required)first_discrepancy(object or null, required)row_count(integer, required): min 0column_count(integer, required): min 0grand_total(string, required): pattern^(0|[1-9][0-9]*)$degrees_of_freedom(integer, required): min 0reference_version(constant "nist-sematech-ehandbook-doi-10.18434-M32189", required)
Limits
- max rows: 64
- max columns: 64
- max cells: 1024
- max claim chars: 1000
- max label bytes: 64
Example
Request input:
{
"table": [
[
762,
327,
468
],
[
484,
239,
477
]
],
"statistic": "30.07",
"degrees_of_freedom": 2,
"decimals": 2
}
Response:
{
"result": {
"valid": true,
"reason": null,
"first_discrepancy": null,
"row_count": 2,
"column_count": 3,
"grand_total": "2757",
"degrees_of_freedom": 2,
"reference_version": "nist-sematech-ehandbook-doi-10.18434-M32189"
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "chi-square-decomposition-check",
"version": "1.0.0",
"input": {
"table": [
[
762,
327,
468
],
[
484,
239,
477
]
],
"statistic": "30.07",
"degrees_of_freedom": 2,
"decimals": 2
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/chi-square-decomposition-check/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"table":[[762,327,468],[484,239,477]],"statistic":"30.07","degrees_of_freedom":2,"decimals":2}'
The machine-readable contract is at /v1/tools/chi-square-decomposition-check/versions/1.0.0.
CLI
node cli.mjs run chi-square-decomposition-check 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Contingency expected check: Check claimed expected counts (row total x column total / N) of a count table exactly; returns the first wrong cell.
- Contingency margins check: Check claimed row, column and grand totals of a count table exactly; returns the first wrong total.
- Polynomial identity check: Check a polynomial identity over exact rationals by expanding both sides; report the lowest disagreeing coefficient.
- Rational expression check: Check a claimed exact rational value of an integer/fraction expression; reports the true value and the difference.
- Rational trace check: Check a step-by-step rational calculation trace; reports the first step whose operand, operator or result disagrees.
- Dimension equation check: Check both sides of an equation have the same dimension (optionally a claimed one); returns the first bad node or side.