Chi-Square Test Calculator: Independence and Goodness of Fit

Chi-square test of independence or goodness of fit on any size table, with the expected-count table, each cell's contribution, degrees of freedom, the p-value, and Cramér's V.

Test

Whole counts only. Rows on separate lines, cells separated by comma, tab, or space.

Enter your counts and run the test. The chi-square statistic, degrees of freedom, and p-value appear here, with the expected-count table and every cell's contribution right below.

χ² = Σ (O - E)² / E How?

How this is calculated

The tool runs the Pearson chi-square statistic in one of two modes. In a test of independence it takes an r by c table of observed counts and compares each cell to the count expected when the row and column variables are independent. In a goodness-of-fit test it compares one row of observed counts to a set of expected counts.

Expected counts for independence are E = (row total times column total) / N, and the degrees of freedom are (r - 1)(c - 1). For goodness of fit the expected counts are N / k across k categories under a uniform hypothesis, or your custom values rescaled to the observed total, and the degrees of freedom are k - 1 - ddof, where ddof is the number of parameters estimated from the data.

Expected counts are kept at full precision and are never rounded to integers. The p-value is the upper tail of the chi-square distribution at the computed df; the test is one-tailed on the statistic, so there is no two-tailed control.

Effect size. For independence the tool reports Cramér's V, V = sqrt( χ² / ( N times min(r - 1, c - 1) ) ), always computed from the uncorrected Pearson χ² so the effect size stays stable whether or not the Yates correction is on.

Formula: χ² = Σ (O - E)² / E

Conventions this tool names

Yates continuity correction defaults off

Plain Pearson chi-square matches searchers, textbook hand-calculations, and the tools they cross-check against. SciPy and R instead apply the Yates correction by default when df = 1 (any 2 by 2 table). This tool keeps it off and puts a labelled toggle beside the result for 2 by 2 tables, so either convention is one click away. Cramér's V is always taken from the uncorrected statistic. For small expected counts the exact alternative is Fisher's exact test.

Assumptions and Cochran's rule

The counts must come from independent observations. The chi-square distribution is an approximation that degrades when expected counts are small. This tool fires a warning on Cochran's actual published rule: any expected count below 1, or more than 20 percent of cells with an expected count below 5. It reports the minimum expected count and the number of low cells for every table, and cross-links Fisher's exact test when the rule is violated. The stricter textbook heuristic, all expected counts at 5 or above, is the conservative alternative; for a 2 by 2 table the two coincide.

Statistic family and goodness-of-fit df

The statistic is Pearson chi-square. The G-test, likelihood-ratio, and Cressie-Read families are out of scope here. For goodness of fit the degrees of freedom follow df = k - 1 - ddof, where ddof (scipy's parameter count) defaults to 0. A custom expected list is accepted as either counts or proportions and is rescaled to the observed total.

Sources

  1. e-Handbook of Statistical Methods, §7.4.5 Contingency table approach. NIST/SEMATECH. Retrieved .
  2. scipy.stats.chi2_contingency. SciPy. Retrieved .
  3. scipy.stats.chisquare. SciPy. Retrieved .
  4. Cramér's V. Wikipedia. Retrieved .
  5. The Tale of Cochran's Rule. The American Statistician. Retrieved .