Chi-Square Calculator

Compute χ² for independence and goodness-of-fit tests. See expected counts, check the expected-count rule, and understand which cells drive significance.

Contingency Table

χ²
df
p
N
Cramér's V
Choose a test mode and enter your data to begin.
Chi-square distribution with observed statistic marked
Fig. 1 — Chi-square density for the computed degrees of freedom. The observed statistic is marked in red; the right-tail rejection region is shaded.

§1The Formula

χ² = Σ (O − E)² / E
O
Observed count in each cell
E
Expected count: Ri × Cj / N (for independence test)
N
Grand total of all observations
df
Degrees of freedom: (rows − 1) × (columns − 1) for independence; k − 1 for goodness of fit

The p-value is p = 1 − F(χ²; df), where F is the chi-square cumulative distribution function.

§2Worked Example

Suppose we survey 100 students about coffee preference (strong / weak) and study location (library / café). A 2×2 contingency table:

LibraryCaféTotal
Strong 251540
Weak 204060
Total 4555100

Expected counts: E(Strong, Library) = 40 × 45 / 100 = 18; E(Strong, Café) = 40 × 55 / 100 = 22; E(Weak, Library) = 60 × 45 / 100 = 27; E(Weak, Café) = 60 × 55 / 100 = 33.

χ²: (25−18)²/18 + (15−22)²/22 + (20−27)²/27 + (40−33)²/33 = 2.72 + 2.23 + 1.81 + 1.48 = 8.24.

df: (2−1) × (2−1) = 1.

p: 1 − chiCDF(8.24, 1)0.0041. At α = 0.05, we reject H₀ and conclude that coffee preference and study location are associated.

Cramér's V: √(8.24 / (100 × 1)) ≈ 0.287 — a small to medium effect size.

§3Reading the Expected Counts Table

The expected counts table shows what you would expect to observe in each cell if the null hypothesis (no association between row and column variables) were true. Compare the observed and expected; large discrepancies make that cell a "driver" of significance.

The contribution column, (O − E)² / E, reveals which cells contribute most to χ². A single large contribution can dominate the entire statistic. This table is your first clue to where your data diverges from the null hypothesis.

§4The Expected-Count Rule and What to Do When You Break It

The Rule

All expected counts should be at least 5. If any expected count falls below 5, the p-value may be inaccurate, and you should consider alternative tests.

Why? The chi-square test relies on a continuous approximation to a discrete distribution. Small expected counts make this approximation poor.

What to do:

  • For 2×2 tables: Use Fisher's exact test, which is always valid and makes no distributional assumptions.
  • For larger tables: Combine adjacent categories (collapse rows or columns) if they are logically similar. For example, if a rare category has an expected count below 5, merge it with a nearby category. Recompute and report the collapsed table.
  • Check your data: Ensure you have not double-counted or mislabeled observations.

§5Chi-Square Tests Frequencies, Never Percentages or Averages

Chi-square expects counts — the number of subjects in each cell. Do not enter:

  • Percentages (e.g., "35%" instead of the count "35")
  • Proportions (e.g., "0.35" instead of "35")
  • Means or other summary statistics

If your data are percentages or proportions, convert them back to counts using your sample size: count = proportion × N.

§6Assumptions

Conditions for a Valid Chi-Square Test

  • Independence of observations. Each subject or observation unit appears in exactly one cell. No repeated measures or paired data.
  • Mutually exclusive categories. Categories do not overlap; every observation belongs to one category only.
  • Random sample. Data are a random or representative sample from the population, not a convenience sample or the entire population of interest.
  • Adequate expected frequencies. All expected counts are at least 5 (or at least 80% of cells are ≥ 5 and none is < 1 in a large table).

§7How to Report Chi-Square in APA Style

In an APA-style report or paper, cite chi-square results as:

χ²(1, N = 100) = 8.24, p = .004, V = .29

Or for goodness of fit:

χ²(3) = 12.50, p = .006

Include a brief narrative: "Chi-square test of independence was conducted to examine the association between [row variable] and [column variable]. The variables were found to be significantly associated, χ²(df, N = n) = x.xx, p < .05, V = .xx."

§8FAQ

What is the difference between a test of independence and a goodness-of-fit test?

A test of independence examines whether two categorical variables are associated. You collect counts in a two-way table and ask: "Are these variables independent, or is knowing one variable's value predictive of the other's?" A goodness-of-fit test asks whether observed category counts match a predicted or null distribution. You have one categorical variable and compare observed counts to expected counts under a theory or uniform distribution. Both use χ², but the contingency table layout and interpretation differ.

What does Cramér's V tell me?

Cramér's V is an effect size measure for chi-square tests. It ranges from 0 (no association) to 1 (perfect association). Rough conventions (from Cohen) are: V ≈ 0.1 is a small effect, V ≈ 0.3 is medium, and V ≈ 0.5 is large. Report V alongside your χ² to show not just that an effect exists, but also how strong it is. Remember: statistical significance does not imply practical significance. A very large sample can yield a significant χ² with a tiny V.

What is Yates continuity correction?

Yates correction is a conservative adjustment for 2×2 tables in which 0.5 is subtracted from the absolute difference between observed and expected counts before squaring. It yields a smaller χ² and a larger p-value. Modern statisticians often omit it because Fisher's exact test is now computationally accessible; however, some journals and textbooks still recommend it for small samples. This calculator offers it as an option so you can see its effect.

Why do I get "—" in the results?

The results show "—" (an em-dash) when your input is incomplete or invalid. Common reasons: not all cells contain numeric values, a row or column is entirely zero (making expected counts undefined), expected proportions do not sum to 1, or you have fewer than 2 categories. Fix the highlighted issue and results will update immediately.

Can I use chi-square with expected percentages or proportions?

No. Chi-square works only with counts—the number of subjects or items in each category. If you have percentages, convert them to counts by multiplying each percentage by your total sample size. For example, if 35% of 100 students prefer coffee, enter 35 (not 0.35 or 35%), and ensure all counts sum to 100.

What should I do if an expected count is less than 5?

For a 2×2 table, use Fisher's exact test. For larger tables, try collapsing adjacent categories to increase expected counts. Ensure your data entry is correct and your categories are well-defined. Report any remedial steps in your write-up. Do not simply ignore the warning; the chi-square approximation will be unreliable.

§9Sources