{"id":"chi-square-decomposition-check","version":"1.0.0","description":"Check a claimed Pearson chi-square, its per-cell (O-E)^2/E terms and df exactly; returns the first wrong term.","supported_operations":["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","בדיקת סטטיסטי חי בריבוע"],"unsupported_operations":["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)"],"semantics":["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."],"limits":{"max_rows":64,"max_columns":64,"max_cells":1024,"max_claim_chars":1000,"max_label_bytes":64},"pricing":{"status":"unpriced","charge_usd":null},"input_schema":{"type":"object","additionalProperties":false,"required":["table","statistic"],"properties":{"table":{"type":"array","minItems":1,"maxItems":64,"items":{"type":"array","minItems":1,"maxItems":64,"items":{"type":"integer","minimum":0,"maximum":9007199254740991}}},"statistic":{"type":"string","minLength":1,"maxLength":1000,"pattern":"^(0|[1-9][0-9]*)(\\.[0-9]+|/[1-9][0-9]*)?$"},"contributions":{"type":"array","maxItems":64,"items":{"type":"array","maxItems":64,"items":{"type":"string","minLength":1,"maxLength":1000,"pattern":"^(0|[1-9][0-9]*)(\\.[0-9]+|/[1-9][0-9]*)?$"}}},"degrees_of_freedom":{"type":"integer","minimum":0,"maximum":3969},"decimals":{"type":"integer","minimum":0,"maximum":20},"row_labels":{"type":"array","minItems":1,"maxItems":64,"items":{"type":"string","minLength":1}},"column_labels":{"type":"array","minItems":1,"maxItems":64,"items":{"type":"string","minLength":1}}}},"output_schema":{"type":"object","additionalProperties":false,"required":["valid","reason","first_discrepancy","row_count","column_count","grand_total","degrees_of_freedom","reference_version"],"properties":{"valid":{"type":"boolean"},"reason":{"type":["string","null"],"enum":["shape_mismatch","contribution_mismatch","statistic_mismatch","degrees_of_freedom_mismatch",null]},"first_discrepancy":{"type":["object","null"],"additionalProperties":false,"properties":{"field":{"type":"string"},"claimed_length":{"type":"integer","minimum":0},"actual_length":{"type":"integer","minimum":0},"row_index":{"type":"integer","minimum":0},"row_label":{"type":"string"},"column_index":{"type":"integer","minimum":0},"column_label":{"type":"string"},"claimed":{"type":"string"},"exact":{"type":"string"},"rounded":{"type":"string"},"actual":{"type":"string","pattern":"^(0|[1-9][0-9]*)$"}}},"row_count":{"type":"integer","minimum":0},"column_count":{"type":"integer","minimum":0},"grand_total":{"type":"string","pattern":"^(0|[1-9][0-9]*)$"},"degrees_of_freedom":{"type":"integer","minimum":0},"reference_version":{"type":"string","const":"nist-sematech-ehandbook-doi-10.18434-M32189"}}},"examples":[{"input":{"table":[[762,327,468],[484,239,477]],"statistic":"30.07","degrees_of_freedom":2,"decimals":2},"output":{"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"}},{"input":{"table":[[0,3],[3,3]],"contributions":[["1","1/2"],["0.5","1/3"]],"statistic":"9/4"},"output":{"valid":false,"reason":"contribution_mismatch","first_discrepancy":{"row_index":1,"column_index":1,"claimed":"1/3","exact":"1/4"},"row_count":2,"column_count":2,"grand_total":"9","degrees_of_freedom":1,"reference_version":"nist-sematech-ehandbook-doi-10.18434-M32189"}}],"execute_url":"/v1/tools/chi-square-decomposition-check/versions/1.0.0/execute"}