What Is the Chi-Square Test of Independence?
The Pearson chi-square test of independence asks whether two categorical variables are associated. It uses an r × c contingency table — one variable defines the rows, the other defines the columns — and compares the observed counts in each cell with the counts expected if the variables were independent.
It is a test of association, not causation. A significant result means the data are inconsistent with independence; it does not mean one variable causes the other.
When to Use It
Use it when both variables are categorical, the observations are independent, and you have a contingency table of counts. Typical examples: smoking status vs disease status, education level vs employment category, or treatment arm vs outcome.
Do not use it when the variables are continuous, when observations are paired or repeated, or when expected counts are extremely small.
Chi-Square Formula
Expected frequency under independence: Eᵢⱼ = (Row totalᵢ × Column totalⱼ) / N.
Pearson chi-square statistic: χ² = Σ (Oᵢⱼ − Eᵢⱼ)² / Eᵢⱼ, summed over every cell.
Degrees of freedom: df = (r − 1)(c − 1).
Each cell's term (O − E)² / E is a contribution; the statistic is their sum. Larger discrepancies in cells with more expected observations weigh more.
How Expected Counts Are Calculated
The expected count for a cell is the row total times the column total, divided by the grand total. Under independence, this is the count the cell would be expected to have if the row and column variables were unrelated.
Every expected count must be greater than zero. An empty row or column makes the expected counts undefined.
How Degrees of Freedom Are Calculated
For an r × c table, df = (r − 1)(c − 1). A 2×2 table has df = 1. A 2×3 table has df = 2. A 3×4 table has df = 6. The degrees of freedom depend on the table shape, not on N.
How to Interpret the Chi-Square Statistic
χ² measures the total discrepancy between observed and expected counts. A value of zero means observed and expected match exactly. Larger values mean the observed table departs further from independence.
χ² cannot be interpreted on its own — it depends on df. The same χ² can be significant at df = 1 and non-significant at df = 10.
What Does the p-Value Mean?
The p-value is the upper-tail probability P(X² ≥ χ²) under the chi-square distribution with df degrees of freedom, assuming H₀ (independence) is true. A small p-value is evidence against independence.
It is not the probability that H₀ is true, and it is not a measure of association strength.
Chi-Square Critical Value and Significance Level
The critical value χ²crit is the threshold at which the upper-tail probability equals α. Reject H₀ if χ² > χ²crit, or equivalently if p < α. The two rules always agree.
Common α values are 0.10, 0.05, and 0.01, with 0.05 as the default.
Cramér's V: Strength of Association
Cramér's V measures the strength of association on a roughly 0-to-1 scale. It is calculated as V = √(χ² / (N × min(r − 1, c − 1))). A value near 0 indicates no association; a value near 1 indicates a strong one.
Rough benchmarks: ~0.10 small, ~0.30 medium, ~0.50 large for 2×2 tables. For larger tables the maximum possible V is still 1, but interpretation depends on the table dimensions.
A significant p-value does not imply a large V. With a large sample, a trivial association can be statistically significant.
Phi Coefficient for 2×2 Tables
For a 2×2 table, Phi equals Cramér's V: φ = √(χ² / N). It is only defined for 2×2 tables. Signed Phi ranges from −1 to 1, but this calculator reports the non-negative magnitude.
Residuals and Cell Contributions
The standardized (Pearson) residual for a cell is (O − E) / √E. It shows how far a cell's observed count is from its expected count, in units of standard deviations under independence.
Cells with |residual| around 2 or higher are often flagged as contributing disproportionately to the association. The χ² contribution (O − E)² / E shows the same information on a different scale.
Chi-Square Assumptions
- Independence of observations. Each observation falls into exactly one cell. Repeated measures or paired data require a different method.
- Mutually exclusive and exhaustive categories. Every observation belongs to one and only one row and one and only one column.
- Counts, not percentages. The chi-square formula requires actual frequencies, not derived values.
- Sufficient expected counts. A common rule of thumb is expected counts of at least 5 in most cells.
Expected Count Requirements
The chi-square approximation assumes expected counts are large enough for the sampling distribution of the statistic to be close to a chi-square distribution. A widely used rule of thumb is that at least 80% of cells should have expected counts of 5 or more, and no cell should have an expected count below 1.
When expected counts are small, the p-value from the asymptotic chi-square may be inaccurate. The calculator flags any cell with an expected count below 5.
Yates Continuity Correction
For 2×2 tables only, Yates correction adjusts each contribution by subtracting 0.5 from |O − E| before squaring: (|O − E| − 0.5)² / E. It was designed to make the chi-square approximation more accurate for small expected counts in 2×2 tables, and it is conservative — it reduces χ².
Yates correction is optional and is not always recommended. Modern statistical practice often prefers Fisher's Exact Test for sparse 2×2 tables instead. When Yates is enabled, the uncorrected Pearson χ² is still shown in the calculation steps.
When Fisher's Exact Test May Be Preferable
Fisher's Exact Test computes an exact p-value for 2×2 tables and does not rely on the chi-square approximation. When expected counts are small — especially when any expected count is below 5 — the exact test is often more appropriate than the asymptotic chi-square.
This calculator flags sparse 2×2 tables but does not run the exact test. Use a dedicated Fisher's Exact Test calculator for that workflow.
Statistical Significance vs Strength of Association
A significant chi-square result means the data are inconsistent with independence at the chosen α. It does not mean the association is strong or practically meaningful.
With a large N, even a weak association can produce a significant χ². Cramér's V is the appropriate measure of strength; the p-value alone does not distinguish a trivial from a substantial association.
Worked Example
A 2×2 table of smoking status vs disease status: 60 smokers with disease, 40 smokers without, 30 non-smokers with disease, 70 non-smokers without. N = 200.
Expected counts under independence: 45, 55, 45, 55. Each Pearson contribution is (60 − 45)² / 45 ≈ 5, and the four contributions sum to χ² ≈ 18.18.
df = 1. The upper-tail p-value is < .001. Cramér's V = √(18.18 / 200) ≈ 0.30, a moderate association. The calculator flags no sparse expected counts.
The result: strong evidence of association between smoking status and disease status in this sample. Causation is not implied.
How to Report a Chi-Square Test of Independence
APA-style format: χ²(df, N = n) = value, p = value, Cramér's V = value.
For the example above: χ²(1, N = 200) = 18.18, p < .001, Cramér's V = .30.
Report the direction of the association separately, usually by describing which cells have higher or lower observed counts than expected.
Common Mistakes
- Entering percentages instead of counts. The formula requires actual frequencies.
- Interpreting a significant result as proof of causation. It is evidence of association only.
- Treating p > α as proof of independence. The data may simply be insufficient to detect a real association.
- Ignoring the expected-count assumption. Small expected counts invalidate the asymptotic p-value.
- Reporting p without Cramér's V. Significance and strength are separate.
- Using chi-square for paired or repeated measures. McNemar's test is the paired alternative.
Chi-Square Independence vs Goodness-of-Fit
Both use the Pearson chi-square statistic, but they test different things. Goodness-of-fit compares one categorical variable against a hypothesized distribution — one row of observed counts and one set of expected proportions. Independence uses a two-way table and asks whether two variables are related.
Goodness-of-fit has df = k − 1 for k categories. Independence has df = (r − 1)(c − 1).
Chi-Square Independence vs Homogeneity
The homogeneity test compares whether the distribution of one variable is the same across multiple populations. The independence test asks whether two variables are related within a single population.
Mathematically the two tests are identical — same formula, same df — but they differ in how the data were collected. In a homogeneity study you sample separate groups; in an independence study you sample one population and cross-classify.
What This Calculator Is For
This calculator runs the Pearson chi-square test of independence for r × c contingency tables. It provides the χ² statistic, degrees of freedom, upper-tail p-value, critical value, decision, Cramér's V, Phi for 2×2 tables, expected counts, cell contributions, standardized residuals, expected-count diagnostics, and an optional Yates correction for 2×2 tables.
It does not run goodness-of-fit, homogeneity, Fisher's Exact Test, McNemar's test, or power/sample-size calculations for chi-square. Those are separate SILDIL calculators.