Home › Statistics & Probability › Chi-Square Test Calculator
Chi-Square Test Calculator
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).
When to use
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).
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 ≥ χ²)
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.
Inputs
| Parameter | Type | Unit | Required | Description |
|---|---|---|---|---|
observed | number_list | yes | 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. | |
rows | integer | no | Number of rows of the contingency table (test of independence). Omit for goodness of fit. Range: ≥ 2, ≤ 60 | |
columns | integer | no | Number of columns of the contingency table. Range: ≥ 2, ≤ 60 | |
expected | number_list | no | Goodness of fit only: expected count (or proportion) per category, same order as observed; rescaled to the observed total. Omit for equal expected counts. | |
yates_correction | boolean | default false | 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. | |
alpha | number | default 0.05 | Significance level as a probability (0.05 = 5 %), not a percentage. Confidence intervals and critical values use level 1 − alpha. Range: > 0 |
Outputs
| Output | Type | Unit | Description |
|---|---|---|---|
test | string | Test of independence (with table size) or goodness of fit. | |
chi_square | number | Σ (O − E)² / E over all cells. | |
degrees_of_freedom | integer | (rows − 1)(columns − 1) for independence; categories − 1 for goodness of fit. | |
p_value | number | Upper-tail probability P(χ²_df ≥ chi_square). | |
critical_value | number | Chi-square quantile at 1 − alpha; H0 is rejected when chi_square exceeds it. | |
cramers_v | number | Effect size √(χ² / (N · min(rows − 1, columns − 1))), 0 to 1 (independence test only; equals phi for 2×2). | |
expected_counts | number_list | Expected frequency of every cell under H0, in the same order as observed. | |
min_expected_count | number | The chi-square approximation is questionable when this is below 5. | |
significant | boolean | true when p_value < alpha. | |
decision | string | Plain-language conclusion. |
Example
Independence: 3 occupation classes × 4 neighbourhoods (Wikipedia example, N = 650): {"observed":[90,60,104,95,30,50,51,20,30,40,45,35],"rows":3,"columns":4} → {"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}
Goodness of fit: die rolled 60 times, 5/8/9/8/10/20: {"observed":[5,8,9,8,10,20]} → {"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}
GET 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
Machine access
- API:
GET https://tttkmbb.com/api/v1/calculate/chi-square-test(query parameters) orPOSTwith a JSON body{"inputs": {...}} - Schema: https://tttkmbb.com/api/v1/calculators/chi-square-test · Markdown: https://tttkmbb.com/statistics/chi-square-test.md · JSON definition: https://tttkmbb.com/statistics/chi-square-test.json
- MCP: server
https://tttkmbb.com/mcp, toolrun_calculator with calculator_id="chi-square-test" - OpenAPI operationId:
calculate_chi_square_test - Freshness:
static. Authentication: none. Rate limit: fair use (see rate limits).
Sources
FAQ
Should I use Yates' correction?
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.
How do I enter the table?
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.
What does Cramér's V mean?
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.
Related calculators
- P-Value Calculator — p-value from a chi-square statistic and df.
- Two-Proportion Z-Test Calculator — Compare two proportions with a confidence interval for the difference.
- Odds Ratio Calculator — Effect measures for a 2×2 table.