{"uid":"cap_TYY_-ZMmJFkEX7fBjVYhc","slug":"chi-square-test-goodness-of-fit-independence-6ea09a25","name":"Chi-Square Test (Goodness of Fit & Independence)","description":"Chi-square goodness of fit (observed vs expected counts) or independence test on a table, with p-value and effect size.","url":"https://stats-tests.x402tookit.com/chi-square-test?utm_source=zero.xyz","method":"GET","headers":{},"bodySchema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["input"],"properties":{"input":{"type":"object","required":["type","method"],"properties":{"type":{"type":"string","const":"http"},"method":{"enum":["GET"],"type":"string"},"queryParams":{"type":"object","required":[],"properties":{"table":{"type":"string","description":"Contingency table for independence, rows separated by semicolons: 12,5;3,10"},"expected":{"type":"string","description":"Expected counts (same length) or leave out for equal expected"},"observed":{"type":"string","description":"Observed counts for goodness of fit, e.g. 5,8,9,8,10,20"}}}},"additionalProperties":false},"output":{"type":"object","required":["type"],"properties":{"type":{"type":"string"},"example":{"type":"object","properties":{"asOf":{"type":["null","string"]},"test":{"type":["null","string"]},"total":{"type":["null","number"]},"pValue":{"type":["null","number"]},"source":{"type":["null","string"]},"reasons":{"type":["array","null"],"items":{"type":"string"}},"summary":{"type":["null","string"]},"verdict":{"type":["null","string"]},"degraded":{"type":["boolean","null"]},"expected":{"type":["array","null"],"items":{"type":"number"}},"chiSquare":{"type":["null","number"]},"disclaimer":{"type":["null","string"]},"notChecked":{"type":["array","null"],"items":{"type":"string"}},"contributions":{"type":["array","null"],"items":{"type":"number"}},"degreesOfFreedom":{"type":["null","number"]},"significantAt5pct":{"type":["boolean","null"]},"cellsWithExpectedBelow5":{"type":["null","number"]}}}}}}},"responseSchema":null,"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.02","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.02/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.02","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.02","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_7Zby9oAy4TBMP6TcITM0H","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.02","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Runs a chi-square goodness-of-fit test on observed vs expected counts, or a chi-square independence test on a contingency table, returning the test statistic, p-value, degrees of freedom, and effect size.","exampleAgentPrompt":"Run a chi-square goodness-of-fit test on these observed counts — 5,8,9,8,10,20 — against equal expected frequencies, and tell me the chi-square statistic, p-value, and whether it's significant at the 5% level.","exampleUseCases":[{"title":"Fairness test for a six-sided die","prompt":"I rolled a die 60 times and got these counts per face: 5,8,9,8,10,20. Can you run a chi-square goodness-of-fit test against equal expected frequencies and tell me if the die is fair?"},{"title":"Survey response distribution check","prompt":"My survey has 4 options and I expected 25% each, but got 120,80,95,105 responses. Run a chi-square goodness-of-fit test against equal expected counts and give me the p-value and chi-square statistic."},{"title":"Independence between gender and product preference","prompt":"I have a contingency table of gender vs product choice: 30,10 for men and 15,25 for women. Run a chi-square independence test on this table — rows separated by semicolons: 30,10;15,25 — and tell me if the association is statistically significant."}],"resultDescription":"Returns the chi-square statistic, degrees of freedom, p-value, expected counts array, per-cell contributions to chi-square, a binary flag for significance at 5%, number of cells with expected counts below 5 (a validity warning), a plain-language summary, and a verdict string.","failureModes":["Missing both 'observed' and 'table' parameters returns an error","Misformatted table string (wrong delimiter) causes a parse error","Row lengths inconsistent in the contingency table cause rejection","All expected counts are zero causes division error","Very small sample sizes may trigger a warning about cells with expected counts below 5"],"whenToPreferThis":"Use this endpoint when you need to test categorical data: either whether observed counts match a hypothesized distribution (goodness of fit) or whether two categorical variables are independent (contingency table). Prefer this over Fisher's exact test for larger samples; use Fisher's exact endpoint on this same host for small 2x2 tables where exact p-values are needed.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-10-21T07:19:48.333Z","isFirstParty":false,"canonicalSlug":"chi-square-test-goodness-of-fit-independence-6ea09a25"}