Chi-Square Test Calculator
Run a chi-square goodness-of-fit test or test of independence.
How the chi-square test works
The chi-square test compares observed counts to the counts expected under a hypothesis. The goodness-of-fit version tests whether a set of observed frequencies matches a specified distribution. The test of independence tests whether two categorical variables are related, using a contingency table.
The χ² statistic sums the squared differences between observed and expected counts, each divided by the expected count. Larger values mean more evidence against the null hypothesis.
Degrees of freedom are k − 1 for goodness-of-fit and (rows − 1)(columns − 1) for independence. The p-value is the upper tail of the chi-square distribution.
The formula
χ² = Σ (O − E)² / E
For goodness-of-fit, expected counts are the total times the hypothesized proportions (or uniform when none are given). For independence, expected counts are row total × column total ÷ grand total. The p-value is the upper tail of the chi-square distribution with the appropriate degrees of freedom.
Worked example
A 2×2 table [[30, 10], [10, 30]]
Row and column totals are 40 and 40, so every expected count is 20. χ² = 4 × (30−20)²/20 = 20 with 1 degree of freedom, giving a p-value far below 0.001 — strong evidence of association.
Frequently asked questions
What assumptions does the chi-square test make?
Observations must be independent, and the expected frequency in each cell should generally be at least 5 for the approximation to be reliable. With sparse tables consider exact methods.
What is the difference between the two modes?
Goodness-of-fit tests whether observed counts match expected proportions. Independence tests whether two categorical variables are related in a contingency table.
Why is a small expected count a problem?
The chi-square distribution approximates the test statistic well only when expected counts are not too small; very small expected counts inflate χ² and make the p-value unreliable.
Related research methods
- Hypothesis Testing
When to use this tool
Use the test of independence for two categorical variables in a contingency table, or goodness-of-fit to compare observed counts to expected proportions.
Assumptions
- Independent observations.
- Adequate expected cell counts (commonly at least 5 per cell; combine categories if not).
Limitations
- Chi-square indicates association, not the strength or direction — report an effect size such as Cramér's V.
- Large samples make even trivial associations 'significant'.
How to interpret the result
A significant chi-square means the observed counts are unlikely under the null hypothesis of no association (or no deviation from expected).
How to report the result
Report the chi-square statistic, degrees of freedom, sample size, p-value, and Cramér's V — for example, 'χ²(1) = 12.0, p < 0.001, V = 0.35'.
Next steps in your analysis
- Effect Size (Cramér's V)
- Statistical Significance →
- Test Selector →
Related tools
Related guides
Built by PanelRoster
PanelRoster is an enterprise operations management platform for organizations coordinating distributed teams, assignments, workflows, quality assurance and operational execution.
Explore PanelRoster