{"success":true,"version":"v1","request":{"tool":"get_calculator_schema","calculator_id":"chi-square-test"},"result":{"entity_type":"calculator","id":"chi-square-test","calculator_id":"chi-square-test","canonical_url":"https://tttkmbb.com/statistics/chi-square-test","name":"Chi-Square Test Calculator","title":"Chi-Square Test Calculator – Test of Independence for a Contingency Table and Goodness of Fit","category":"statistics","category_name":"Statistics & Probability","tool_name":"calculate_chi_square_test","featured_mcp_tool":false,"description":"Computes Pearson's chi-square statistic, degrees of freedom, p-value, critical value and expected counts for a contingency table (test of independence, with Cramér's V) or for observed versus expected category counts (goodness-of-fit test).","use_when":"You have counts in categories and want to know whether two categorical variables are associated, or whether observed frequencies match a hypothesised distribution.","do_not_use_when":"Expected counts are below 5 in many cells (use Fisher's exact test), the data are means rather than counts (use t-test), or you compare exactly two proportions and want a confidence interval for their difference (use proportion-z-test).","inputs":[{"name":"observed","label":"Observed counts","type":"number_list","required":true,"description":"Observed frequencies. For a contingency table list the cells row by row (row-major) and give rows and columns; for goodness of fit list one count per category.","example":[90,60,104,95,30,50,51,20,30,40,45,35]},{"name":"rows","label":"Rows","type":"integer","required":false,"min":2,"max":60,"description":"Number of rows of the contingency table (test of independence). Omit for goodness of fit.","example":3},{"name":"columns","label":"Columns","type":"integer","required":false,"min":2,"max":60,"description":"Number of columns of the contingency table.","example":4},{"name":"expected","label":"Expected counts or proportions","type":"number_list","required":false,"description":"Goodness of fit only: expected count (or proportion) per category, same order as observed; rescaled to the observed total. Omit for equal expected counts."},{"name":"yates_correction","label":"Yates' continuity correction","type":"boolean","required":false,"default":false,"description":"Apply the continuity correction (|O − E| − 0.5)² to a 2×2 table, as R's chisq.test does by default. Ignored for other tables.","example":false},{"name":"alpha","label":"Significance level (α)","type":"number","required":false,"default":0.05,"exclusive_min":0,"exclusive_max":1,"description":"Significance level as a probability (0.05 = 5 %), not a percentage. Confidence intervals and critical values use level 1 − alpha.","example":0.05}],"outputs":[{"name":"test","label":"Test performed","type":"string","decimals":4,"description":"Test of independence (with table size) or goodness of fit."},{"name":"chi_square","label":"Chi-square statistic","type":"number","decimals":4,"description":"Σ (O − E)² / E over all cells."},{"name":"degrees_of_freedom","label":"Degrees of freedom","type":"integer","decimals":4,"description":"(rows − 1)(columns − 1) for independence; categories − 1 for goodness of fit."},{"name":"p_value","label":"p-value","type":"number","decimals":6,"description":"Upper-tail probability P(χ²_df ≥ chi_square)."},{"name":"critical_value","label":"Critical value","type":"number","decimals":4,"description":"Chi-square quantile at 1 − alpha; H0 is rejected when chi_square exceeds it."},{"name":"cramers_v","label":"Cramér's V","type":"number","decimals":4,"description":"Effect size √(χ² / (N · min(rows − 1, columns − 1))), 0 to 1 (independence test only; equals phi for 2×2)."},{"name":"expected_counts","label":"Expected counts","type":"number_list","decimals":2,"description":"Expected frequency of every cell under H0, in the same order as observed."},{"name":"min_expected_count","label":"Smallest expected count","type":"number","decimals":2,"description":"The chi-square approximation is questionable when this is below 5."},{"name":"significant","label":"Significant at alpha","type":"boolean","decimals":4,"description":"true when p_value < alpha."},{"name":"decision","label":"Decision","type":"string","decimals":4,"description":"Plain-language conclusion."}],"input_schema":{"type":"object","properties":{"observed":{"description":"Observed frequencies. For a contingency table list the cells row by row (row-major) and give rows and columns; for goodness of fit list one count per category.","type":"array","items":{"type":"number"},"minItems":2,"examples":[[90,60,104,95,30,50,51,20,30,40,45,35]]},"rows":{"description":"Number of rows of the contingency table (test of independence). Omit for goodness of fit.","type":"integer","minimum":2,"maximum":60,"examples":[3]},"columns":{"description":"Number of columns of the contingency table.","type":"integer","minimum":2,"maximum":60,"examples":[4]},"expected":{"description":"Goodness of fit only: expected count (or proportion) per category, same order as observed; rescaled to the observed total. Omit for equal expected counts.","type":"array","items":{"type":"number"},"minItems":2},"yates_correction":{"description":"Apply the continuity correction (|O − E| − 0.5)² to a 2×2 table, as R's chisq.test does by default. Ignored for other tables.","type":"boolean","default":false,"examples":[false]},"alpha":{"description":"Significance level as a probability (0.05 = 5 %), not a percentage. Confidence intervals and critical values use level 1 − alpha.","type":"number","exclusiveMinimum":0,"exclusiveMaximum":1,"default":0.05,"examples":[0.05]}},"additionalProperties":false,"required":["observed"]},"output_schema":{"type":"object","properties":{"test":{"description":"Test of independence (with table size) or goodness of fit.","type":"string"},"chi_square":{"description":"Σ (O − E)² / E over all cells.","type":"number"},"degrees_of_freedom":{"description":"(rows − 1)(columns − 1) for independence; categories − 1 for goodness of fit.","type":"integer"},"p_value":{"description":"Upper-tail probability P(χ²_df ≥ chi_square).","type":"number"},"critical_value":{"description":"Chi-square quantile at 1 − alpha; H0 is rejected when chi_square exceeds it.","type":"number"},"cramers_v":{"description":"Effect size √(χ² / (N · min(rows − 1, columns − 1))), 0 to 1 (independence test only; equals phi for 2×2).","type":"number"},"expected_counts":{"description":"Expected frequency of every cell under H0, in the same order as observed.","type":"array","items":{"type":"number"}},"min_expected_count":{"description":"The chi-square approximation is questionable when this is below 5.","type":"number"},"significant":{"description":"true when p_value < alpha.","type":"boolean"},"decision":{"description":"Plain-language conclusion.","type":"string"}}},"formula":"χ² = Σ (O − E)² / E; independence: E_ij = (row total_i × column total_j) / N, df = (rows − 1)(columns − 1), Cramér's V = √(χ² / (N · min(rows − 1, columns − 1))); goodness of fit: E_i = N × p_i, df = k − 1; p = P(χ²_df ≥ χ²)","method":"Pearson's chi-square with the asymptotic chi-square distribution (regularized incomplete gamma function). Rule of thumb: all expected counts ≥ 5 (at least 80 % of cells ≥ 5 and none below 1); a note is added otherwise.","sources":[{"name":"NIST/SEMATECH e-Handbook of Statistical Methods, 1.3.5.15 Chi-Square Goodness-of-Fit Test","url":"https://www.itl.nist.gov/div898/handbook/eda/section3/eda35f.htm","type":"government","retrieved_at":"2026-09-24"},{"name":"Wikipedia – Pearson's chi-squared test","url":"https://en.wikipedia.org/wiki/Pearson%27s_chi-squared_test","type":"reference","retrieved_at":"2026-09-24"},{"name":"Wikipedia – Cramér's V","url":"https://en.wikipedia.org/wiki/Cram%C3%A9r%27s_V","type":"reference","retrieved_at":"2026-09-24"}],"freshness":{"type":"static","max_age_seconds":null,"note":"Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output."},"examples":[{"name":"Independence: 3 occupation classes × 4 neighbourhoods (Wikipedia example, N = 650)","inputs":{"observed":[90,60,104,95,30,50,51,20,30,40,45,35],"rows":3,"columns":4},"expected":{"chi_square":24.5712,"degrees_of_freedom":6,"p_value":0.00041,"critical_value":12.5916,"cramers_v":0.1375,"min_expected_count":34.62,"significant":true},"url":"https://tttkmbb.com/api/v1/calculate/chi-square-test?observed=90%2C60%2C104%2C95%2C30%2C50%2C51%2C20%2C30%2C40%2C45%2C35&rows=3&columns=4"},{"name":"Goodness of fit: die rolled 60 times, 5/8/9/8/10/20","inputs":{"observed":[5,8,9,8,10,20]},"expected":{"chi_square":13.4,"degrees_of_freedom":5,"p_value":0.019905,"critical_value":11.0705,"expected_counts":[10,10,10,10,10,10],"significant":true},"url":"https://tttkmbb.com/api/v1/calculate/chi-square-test?observed=5%2C8%2C9%2C8%2C10%2C20"}],"faq":[{"q":"Should I use Yates' correction?","a":"Only for 2×2 tables and mainly with small samples; it makes the test conservative. Report which version you used, since R applies it by default and many other tools do not."},{"q":"How do I enter the table?","a":"Row by row: a 2×2 table with rows (10, 20) and (30, 40) is observed = 10, 20, 30, 40 with rows = 2 and columns = 2."},{"q":"What does Cramér's V mean?","a":"A 0–1 measure of association strength independent of sample size; roughly 0.1 small, 0.3 medium, 0.5 large for df* = 1 (Cohen), smaller thresholds for larger tables."}],"tags":["chi square test","chi squared","contingency table","test of independence","goodness of fit","cramers v"],"related":[{"calculator_id":"p-value","reason":"p-value from a chi-square statistic and df."},{"calculator_id":"proportion-z-test","reason":"Compare two proportions with a confidence interval for the difference."},{"calculator_id":"odds-ratio","reason":"Effect measures for a 2×2 table."}],"links":{"html":"https://tttkmbb.com/statistics/chi-square-test","markdown":"https://tttkmbb.com/statistics/chi-square-test.md","json":"https://tttkmbb.com/statistics/chi-square-test.json","api":"https://tttkmbb.com/api/v1/calculate/chi-square-test","schema":"https://tttkmbb.com/api/v1/calculators/chi-square-test","openapi":"https://tttkmbb.com/openapi.json","mcp":"https://tttkmbb.com/mcp"},"version":"v1","updated_at":"2026-09-24"},"timestamp":"2026-09-24T01:45:04Z"}