Chi Square Test Calculator
Calculate chi-square statistic, degrees of freedom, p-value, and significance for contingency tables.
Chi Square Test Calculator
Calculator
Adjust values & calculateEnter your values below. Every result is computed in your browser — no data is sent to any server.
Formula: Chi-Square = Sum[(Observed - Expected)^2 / Expected]
Worked example — Chi-square = 11.67, df = 1, p = 0.0006 — Significant association
Formula
Chi-Square = Sum[(Observed - Expected)^2 / Expected]
The chi-square statistic sums the squared differences between observed and expected frequencies, each divided by the expected frequency. Degrees of freedom = (rows - 1) x (columns - 1). Compare the statistic to the chi-square distribution to find the p-value.
Worked Examples
Example 1: Gender and Product Preference
Problem:Survey: 50 males prefer Product A, 30 prefer B. 20 females prefer A, 40 prefer B. Is there an association between gender and preference?
Solution:Observed: [[50,30],[20,40]] Row totals: 80 (male), 60 (female). Column totals: 70 (A), 70 (B). Grand total = 140 Expected = row total x column total / grand total: E(male,A) = 80 x 70 / 140 = 40, E(male,B) = 40 E(female,A) = 60 x 70 / 140 = 30, E(female,B) = 30 Chi-square = (50-40)^2/40 + (30-40)^2/40 + (20-30)^2/30 + (40-30)^2/30 = 2.50 + 2.50 + 3.33 + 3.33 = 11.67 df = (2-1)(2-1) = 1, p = 0.0006
Result:Chi-square = 11.67, df = 1, p = 0.0006 — Significant association
Frequently Asked Questions
What is the chi-square test of independence?
The chi-square test of independence determines whether there is a statistically significant association between two categorical variables. It compares observed frequencies (your actual data) to expected frequencies (what you would expect if the variables were independent). A large chi-square statistic indicates that observed frequencies differ substantially from expected frequencies, suggesting the variables are associated.
How are expected values calculated?
For a test of independence, expected values are calculated as: Expected = (Row Total x Column Total) / Grand Total. This formula gives you the frequency you would expect in each cell if the row and column variables were completely independent. You can also enter custom expected values if testing a different hypothesis (goodness of fit).
What are the assumptions of the chi-square test?
Key assumptions: (1) Data are frequencies/counts, not percentages or means. (2) Categories are mutually exclusive — each observation falls in exactly one cell. (3) Observations are independent. (4) Expected frequency in each cell should be at least 5 (Cochran's rule). If expected values are below 5, consider Fisher's exact test or combining categories.
What is Cramer's V?
Cramer's V is an effect size measure for the chi-square test, ranging from 0 (no association) to 1 (perfect association). It adjusts for table size, making it comparable across different contingency tables. Guidelines: V < 0.1 is negligible, 0.1-0.3 is small, 0.3-0.5 is medium, and > 0.5 is large. Unlike the chi-square statistic, Cramer's V is not affected by sample size.
How are degrees of freedom determined for a contingency table?
For a test of independence, df = (rows - 1) x (columns - 1). Once the row and column totals are fixed, only that many cells are free to vary; the rest follow by subtraction. A 2x2 table has df = 1, a 3x4 table has df = 6. For a goodness-of-fit test against externally supplied expected counts, df = number of categories - 1, reduced by one more for each parameter estimated from the data. Degrees of freedom set which chi-square distribution the statistic is compared against.
What is the difference between a goodness-of-fit test and a test of independence?
Both use the same statistic, Sum[(O - E)^2 / E], but differ in where the expected counts come from. Goodness of fit compares one categorical variable against a theoretical distribution you specify, such as equal proportions or a published breakdown, so you enter the expected values yourself. The test of independence uses two variables in a contingency table and derives expected counts from the marginals as row total x column total / grand total.
When should Yates' continuity correction be applied?
Yates' correction subtracts 0.5 from each absolute difference before squaring, giving Sum[(|O - E| - 0.5)^2 / E]. It applies only to 2x2 tables, where the continuous chi-square distribution approximates a discrete count distribution most crudely, and it shrinks the statistic so the test becomes more conservative. Many statisticians consider it overly conservative for larger samples and prefer Fisher's exact test when counts are small enough for the correction to matter.
Why does a large sample make almost any association significant?
The chi-square statistic scales roughly with the grand total: doubling every cell count doubles the statistic while leaving the proportions and degrees of freedom unchanged. With tens of thousands of observations, a trivial departure from independence clears the critical value easily. That is why the p-value should be read alongside Cramer's V, which is normalised by sample size and table dimensions and therefore reports the strength of the association rather than the evidence that one exists.
What should I do when several cells have expected counts below 5?
The chi-square approximation degrades because a small expected value in the denominator can inflate a single cell's contribution. Options are to merge adjacent or logically similar categories so the collapsed cells carry enough mass, to collect more data, or to switch to an exact method — Fisher's exact test for 2x2 tables and its generalisations for larger ones. Simply ignoring the warning risks a p-value that is far smaller than the true tail probability.
How do I find which cells drive a significant chi-square result?
The overall test tells you only that observed and expected frequencies disagree somewhere. Inspect the standardised residual for each cell, (O - E) / sqrt(E), or the adjusted residual, which also corrects for the row and column marginals. Residuals beyond roughly plus or minus 2 flag the cells contributing most of the statistic. Reporting the direction of those residuals turns a bare significance verdict into a statement about which category combinations are over- or under-represented.
References
Reviewed for accuracy by Daniel Agrici, Founder & Lead Developer · Editorial policy
Related Calculators
🧮Descriptive Statistics Calculator
Calculate descriptive statistics with inputs, formulas, and instant results.
🧮Bayesian Posterior Calculator
Calculate bayesian posterior with inputs, formulas, and instant results.
🧮False Discovery Rate Calculator
Calculate false discovery rate with inputs, formulas, and instant results.
🧮Correlation Coefficient Calculator
Calculate correlation coefficient with inputs, formulas, and instant results.
🧮Binomial Distribution Calculator
Calculate binomial distribution with inputs, formulas, and instant results.
🧮Ztest Proportions Calculator
Calculate ztest proportions with inputs, formulas, and instant results.
🧮Effect Size Calculator
Calculate effect size with inputs, formulas, and instant results.