Chi Square Test Calculator
Perform chi-square goodness-of-fit and independence tests from observed data.
Observed counts in each category. Must be non-negative numbers; ≥ 2 categories required.
If blank, the calculator assumes equal expected frequencies (uniform null). Otherwise enter the same number of values as observed.
Default 0.05 (95% confidence). Common values: 0.10, 0.05, 0.01.
About
The chi-square test is a non-parametric statistical test that compares observed frequencies to expected frequencies under a null hypothesis. The test statistic χ² = Σ (O − E)² / E measures how far the observed counts deviate from expectation. Under the null hypothesis, χ² follows a chi-square distribution with k − 1 degrees of freedom for a goodness-of-fit test, or (r − 1)(c − 1) for a contingency table. A large χ² indicates the observed data is unlikely under the null, providing evidence to reject.
The goodness-of-fit version tests whether a single categorical variable follows a hypothesized distribution. For example, you might roll a six-sided die 600 times and test whether each face appears equally often (expected 100 per face). If observed counts are 95, 110, 102, 89, 105, 99, the chi-square statistic tells you whether the deviations are consistent with random chance or evidence of a loaded die.
The test of independence uses a two-way contingency table to determine whether two categorical variables are associated. For an r × c table the degrees of freedom are (r − 1)(c − 1). The expected count in cell (i, j) is (rowTotal_i × colTotal_j) / grandTotal. A large χ² means the row and column variables are dependent — knowing one helps predict the other.
The p-value is the upper-tail probability P(χ² ≥ observed | null true). A p-value below α (typically 0.05) leads to rejection: the observed deviation is unlikely under the null. A p-value above α means you fail to reject — the data is consistent with the null hypothesis. Importantly, the p-value does not measure effect size or the magnitude of the deviation; it only measures the strength of evidence against the null.
The chi-square test rests on three assumptions: (1) observations are independent — no subject appears in more than one cell; (2) expected frequencies are at least 5 in every cell — the asymptotic chi-square approximation breaks down for very small expected counts; and (3) the data is a simple random sample from the population of interest. When expected counts are too small, combine adjacent categories or switch to Fisher's exact test.
How to Use
- 1Enter observed frequenciesType the observed counts separated by commas (e.g., 25, 30, 28, 22, 35). These are the actual counts you observed in each category.
- 2Enter expected frequencies (optional)Leave blank to use equal expected counts (uniform null — total / k). Or enter your own expected counts separated by commas. The lists must have the same length.
- 3Set the significance level αChoose 0.05 (95% confidence) by default, or 0.01 / 0.10 for stricter or looser tests. The calculator computes the critical value at this α.
- 4Read χ², p-value, and decisionThe hero shows the χ² statistic. Below: the p-value, the critical value, degrees of freedom, and the reject / fail-to-reject decision at α.
- 5Check assumptions before reportingAll expected frequencies should be at least 5. If any cell has expected count below 5, the chi-square approximation is unreliable — consider Fisher's exact test or combine categories.
Formula
Chi-square statistic:
χ² = Σ_i=1..k (O_i − E_i)² / E_i
Degrees of freedom:
Goodness of fit: df = k − 1
Independence (r × c table): df = (r − 1)(c − 1)
With p estimated parameters: df = k − 1 − p
p-value (upper tail):
p = 1 − F_χ²(χ²_observed; df)
Reject H₀ if p < α (typically 0.05)
Critical value:
χ²_crit = F⁻¹_χ²(1 − α; df)
Worked Example
Example — Test whether a six-sided die is fair:
- Observed counts (60 rolls): 12, 7, 11, 9, 13, 8. Total = 60.
- Expected (uniform): 60 / 6 = 10 per face.
- χ² = (12−10)²/10 + (7−10)²/10 + (11−10)²/10 + (9−10)²/10 + (13−10)²/10 + (8−10)²/10
- χ² = 0.4 + 0.9 + 0.1 + 0.1 + 0.9 + 0.4 = 2.8.
- df = 6 − 1 = 5. Critical χ² at α = 0.05 is about 11.07.
- Since 2.8 < 11.07, fail to reject H₀ — the die is consistent with fair.
- p-value ≈ 0.73 — deviations are easily explained by random chance.
Example 2 — Mendel's pea experiment (3:1 dominant:recessive):
- Observed: 705 dominant, 224 recessive. Total = 929.
- Expected under 3:1 ratio: 696.75 dominant, 232.25 recessive.
- χ² = (705 − 696.75)²/696.75 + (224 − 232.25)²/232.25 ≈ 0.0974 + 0.2926 ≈ 0.39.
- df = 1. p ≈ 0.53. Fail to reject — data is consistent with 3:1 inheritance.
Tips
- All expected frequencies should be at least 5 for the chi-square approximation to be reliable. If any are smaller, combine adjacent categories or switch to Fisher's exact test.
- Degrees of freedom = (number of categories − 1) for goodness of fit, or (rows − 1) × (columns − 1) for an independence test on a contingency table.
- If you estimate parameters from the data before computing expected counts (e.g., fitting a Poisson mean), subtract one degree of freedom per estimated parameter.
- The chi-square test is right-tailed only — only large values of χ² lead to rejection. A χ² near 0 means observed and expected match almost perfectly.
- For 2×2 contingency tables with small samples, the chi-square approximation is poor; Yates' continuity correction or Fisher's exact test should be used instead.
Common Mistakes
The most common mistake is using the chi-square test when expected counts are below 5 in any cell — the asymptotic approximation becomes unreliable, and you should switch to Fisher's exact test or combine categories. A second error is treating "fail to reject" as "accept the null" — absence of evidence is not evidence of absence. A third error is using chi-square on continuous data without first binning it into categories; the test is for counts, not measurements. Finally, do not forget to subtract degrees of freedom when parameters are estimated from the data (e.g., fitting a Poisson mean from the sample).
Frequently Asked Questions
- What is a chi-square test?
- A chi-square test (χ² test) is a non-parametric statistical test that compares observed frequencies to expected frequencies under a null hypothesis. The test statistic χ² = Σ (O − E)² / E follows a chi-square distribution under the null. A large χ² indicates that observed data deviates significantly from expectation, providing evidence against the null hypothesis.
- What are degrees of freedom in a chi-square test?
- For a goodness-of-fit test with k categories, degrees of freedom = k − 1 (or k − 1 − p if p parameters are estimated from the data). For a contingency table with r rows and c columns, df = (r − 1)(c − 1). Degrees of freedom determine which chi-square distribution the test statistic follows under the null hypothesis.
- How do I interpret the p-value?
- The p-value is the probability of observing a χ² statistic at least as extreme as the one computed, assuming the null hypothesis is true. A small p-value (typically less than 0.05) means the observed deviation is unlikely under the null, so you reject the null hypothesis. A large p-value means you fail to reject the null — the data is consistent with expectation.
- When should I use the chi-square test vs a t-test?
- Use the chi-square test for categorical or frequency data — counts of how many observations fall in each category. Use a t-test for continuous measurement data — comparing means of groups. Chi-square tests goodness of fit (one categorical variable) or independence (two categorical variables), while t-tests compare group means on a numerical outcome.
- What are the assumptions of the chi-square test?
- The chi-square test assumes (1) observations are independent, (2) expected frequencies are at least 5 in each cell (the approximation breaks down for very small expected counts), (3) the data is a simple random sample from the population, and (4) the categories are mutually exclusive and exhaustive. When expected counts are below 5, Fisher's exact test is preferred.
- Why is the expected frequency sometimes equal across categories?
- For a uniform-distribution null hypothesis (e.g., testing whether a die is fair), every category is equally likely, so the expected count in each is total / k. In general, the expected frequencies come from whatever model you are testing — a Poisson model, a normal distribution, or observed marginal totals for an independence test. The calculator defaults to equal expected counts but accepts any user-supplied expected list.
Chi-square test
The chi-square test compares observed frequencies to expected frequencies under a null hypothesis. The test statistic χ² = Σ (O − E)² / E measures how far observed counts deviate from expectation. Under the null, χ² follows a chi-square distribution with k − 1 degrees of freedom. Large values of χ² indicate the observed data is unlikely under the null, leading to rejection.
Goodness of fit
The goodness-of-fit test checks whether a single categorical variable matches a theoretical distribution. Example: testing whether a six-sided die is fair by rolling it 600 times and comparing observed counts to the expected 100 per face. Degrees of freedom = number of categories − 1 (minus any estimated parameters).
Observed vs expected
The chi-square statistic weights each (O − E)² / E term by the inverse expected count. Large deviations in low-expected cells contribute disproportionately — which is why the test requires expected counts of at least 5. Cells with very small expected counts violate the asymptotic chi-square approximation.
p-value interpretation
The p-value is the upper-tail probability P(χ² ≥ observed | null true). A p-value below α (typically 0.05) means the observed deviation is unlikely under the null — reject the null. A p-value above α means you fail to reject; the data is consistent with the null hypothesis. The p-value does not measure effect size, only the strength of evidence against the null.
| χ² statistic | df = 1 p-value | df = 5 p-value | df = 10 p-value | Decision at α = 0.05 |
|---|---|---|---|---|
| 1.0 | 0.3173 | 0.9626 | 0.9999 | Fail to reject |
| 3.84 | 0.0500 | 0.5730 | 0.9533 | df = 1: reject; otherwise fail |
| 5.0 | 0.0253 | 0.4159 | 0.7572 | df = 1: reject; otherwise fail |
| 11.07 | 0.0009 | 0.0500 | 0.3541 | df ≤ 5: reject; df = 10: fail |
| 15.0 | 0.0001 | 0.0104 | 0.1321 | df ≤ 5: reject; df = 10: fail |
| 20.0 | < 0.0001 | 0.0012 | 0.0293 | Reject (all df shown) |
The chi-square distribution with k degrees of freedom has mean k and variance 2k. As k grows, it approaches a normal distribution by the central limit theorem — for k > 30, the approximation χ² ≈ z × √(2k) + (z² − 1) × √(2 / k) + k where z is the standard normal quantile is accurate enough for most practical purposes.
For a 2×2 contingency table with small samples, Yates' continuity correction adjusts the chi-square statistic downward by subtracting 0.5 from each |O − E| before squaring. This corrects for the discrete-to-continuous approximation and is conservative. For very small expected counts, Fisher's exact test computes the exact hypergeometric probability rather than relying on the asymptotic chi-square approximation.
Authoritative References
- Wikipedia — Chi-square test— wikipedia.orgComprehensive treatment of the chi-square test, including the goodness-of-fit and independence variants, the chi-square distribution, and the assumptions behind the asymptotic approximation.
- Khan Academy — Chi-square tests— khanacademy.orgKhan Academy unit on chi-square tests for categorical data, with videos and exercises on goodness-of-fit and independence tests.
- Stat Trek — Chi-Square Distribution— stattrek.comStat Trek reference on the chi-square distribution, with tables of critical values and worked examples of the goodness-of-fit and independence tests.
Try our other free calculators
CalcGenius has 1,200+ free, ad-free, browser-based calculators for finance, health, math, science, and everyday life. No sign-up required.