Chi-Square Calculator
Chi-square test of independence on a contingency table, or goodness of fit against expected ratios, with expected counts, residuals, p-value and Cramér's V.
The interactive tool loads here when JavaScript runs.
About this toolWhat is the Chi-Square Calculator?
The Chi-Square Calculator runs the two tests people mean by "chi-square". The test of independence takes a table of counts, such as survey answers by age group or clicks by page version, and asks whether the row and column variables are related. The goodness-of-fit test takes one row of observed counts and asks whether they match an expected distribution, such as a 9:3:3:1 genetic ratio, equal frequencies for a die, or last year's market shares.
Paste a table straight from a spreadsheet, labels and all, and the calculator returns χ², the degrees of freedom, the p-value, the critical value, Cramér's V (and φ for 2 x 2 tables), every expected count and the adjusted standardized residual for each cell, coloured so you can see which cells drive the result. It warns when expected counts are too small for the approximation and offers Yates' continuity correction for 2 x 2 tables. Your data never leaves the browser.
- Test of independence for any r x c table and goodness of fit for any number of categories
- Paste tables from spreadsheets with optional row and column labels
- Expected counts, contributions and adjusted standardized residuals
- Cramér's V, φ for 2 x 2 tables, and optional Yates correction
- Warnings for small expected counts (Cochran's rule)
- Matches R chisq.test and SciPy; runs in your browser
How to use the Chi-Square Calculator
- Pick "Independence (table)" for a contingency table or "Goodness of fit" for one set of counts.
- For a table, paste rows of counts, one row per line, separated by tabs, commas or spaces. An optional header row and first column of labels are detected automatically. Tick Yates' correction for a 2 x 2 table if your method requires it.
- For goodness of fit, enter the observed counts and the expected ratio, proportions, percentages or counts in the same order (they are rescaled to your total). Leave the expected box empty to test equal frequencies. If you estimated parameters from the same data, such as a Poisson mean, enter how many.
- Read χ², df, the p-value and Cramér's V, then the expected counts and residuals to see which cells differ most.
- Copy the summary or share a link that reopens the same table.
Worked examples
Gender and party identification (Agresti, used in R's chisq.test help)
Input
Female: 762, 327, 468; Male: 484, 239, 477 (Democrat, Independent, Republican)
Output
χ² = 30.070, df = 2, p = 2.954e-7, Cramér's V = 0.104
The association is very unlikely to be chance, but V = 0.10 shows it is weak. The adjusted residuals of 4.50 for female Democrats and -5.32 for female Republicans show where the difference lies.
Mendel's peas against a 9:3:3:1 ratio
Input
Observed 315, 108, 101, 32; expected ratio 9, 3, 3, 1
Output
Expected 312.75, 104.25, 104.25, 34.75; χ² = 0.4700, df = 3, p = 0.9254
The counts fit the predicted ratio closely. A p-value this high means no evidence against the model, which is what Mendel's dihybrid cross predicts.
A small 2 x 2 table, with and without Yates
Input
12, 5 / 7, 7
Output
Without correction χ² = 1.3716, p = 0.2415; with Yates χ² = 0.6411, p = 0.4233
The smallest expected count is 5.42, close to the limit. The correction roughly halves χ² here, which shows how much the choice matters for small tables.
Background and insight
Karl Pearson introduced the statistic χ² = Σ (O - E)² / E in 1900 to test whether observed frequencies fit a theoretical curve. Each cell contributes the squared gap between what was observed and what was expected, scaled by the expected count. If the null hypothesis holds and the counts are large enough, the total follows a chi-square distribution. Fisher showed in 1922 that for an r x c table the right degrees of freedom are (r - 1)(c - 1), correcting Pearson's original count.
For independence, the expected count of a cell is its row total times its column total divided by the grand total: the count you would see if the row variable told you nothing about the column variable. The approximation needs enough data. Cochran (1954) suggested no expected count below 1 and no more than 20% of cells below 5; the calculator counts those cells and warns you. For small 2 x 2 tables Fisher's exact test is the usual alternative.
Frank Yates proposed his continuity correction in 1934 for 2 x 2 tables, subtracting 0.5 from each |O - E| before squaring. It makes the test more conservative, sometimes too conservative, so modern advice is split. R's chisq.test applies it to 2 x 2 tables by default and SciPy's chi2_contingency does too; this calculator leaves it off unless you tick the box, so check which convention your course or software uses. The results match R and SciPy exactly in the test suite, including the gender and party identification table from Agresti's An Introduction to Categorical Data Analysis that R uses in its documentation.
Common use cases
Survey analysis
Test whether answers differ by age group, region or customer type, and find which cells drive the difference.
A/B tests on conversions
Put converted and not-converted counts for each variant in a table to compare conversion rates across two or more versions.
Genetics and biology
Check offspring counts against Mendelian ratios or Hardy-Weinberg expectations.
Fairness and quality checks
Test whether a die, a random number generator or a defect distribution across shifts matches what was expected.
Tips and limitations
- Enter counts, never percentages or means. The chi-square statistic depends on the actual numbers, and 50% of 20 is very different evidence from 50% of 2,000.
- Each subject must be counted once. Repeated measurements on the same people need McNemar's test or another paired method.
- A significant result says the variables are associated, not how strongly. Report Cramér's V: values near 0.1 are weak, near 0.3 moderate and 0.5 or more strong for tables with two rows or columns.
- If many expected counts are below 5, merge sparse categories or use an exact test.
- In goodness of fit, subtract one degree of freedom for each parameter you estimated from the data; otherwise the test is too lenient.
Frequently asked questions
What is the difference between the chi-square test of independence and goodness of fit?
Independence uses a two-way table and asks whether two categorical variables are related. Goodness of fit uses one set of counts and asks whether they follow a specified distribution. The statistic is computed the same way; the expected counts and degrees of freedom differ.
How are expected counts calculated?
For independence, expected = row total × column total ÷ grand total. For goodness of fit, expected = total count × the expected proportion for that category. The calculator shows every expected count next to the observed one.
How do I find degrees of freedom for a chi-square test?
For an r x c table, df = (r - 1)(c - 1). For goodness of fit with k categories, df = k - 1, minus one for each parameter estimated from the data.
When should I not use a chi-square test?
When expected counts are small (any below 1, or more than 20% below 5), when the data are not counts, or when observations are not independent, such as the same people measured twice. Fisher's exact test and McNemar's test cover those cases.
Should I use Yates' continuity correction?
It applies only to 2 x 2 tables and makes the test more conservative. Many textbooks and R's default use it; others argue it is too conservative and prefer the uncorrected test or Fisher's exact test. Follow your field's convention and report which you used.
What do the adjusted residuals mean?
Each one is (O - E) divided by its standard error, so under independence it behaves like a z-score. Values beyond about ±2 mark cells with notably more (positive) or fewer (negative) observations than expected.
What does Cramér's V tell me?
It is an effect size between 0 (no association) and 1 (perfect association), computed as √(χ² / (n × (min(r, c) - 1))). Unlike the p-value it does not grow just because the sample is large.
Is there an in-depth guide to the Chi-Square Calculator?
Yes. “The Chi-Square Test: Independence and Goodness of Fit” covers the background, how it works, common pitfalls and worked examples. Read the full guide.
People also search for
- chi square test of independence calculator
- chi square goodness of fit calculator with expected ratio
- contingency table chi square p value
- expected frequencies chi square table
- yates continuity correction 2x2 calculator
- cramers v calculator from contingency table
- chi square test for mendel 9 3 3 1 ratio
- how to calculate chi square by hand
Related Tools You May Like
Free, in-browser tools that pair well with this one.