Statistics and research
Chi-square test of independence calculator
Chi-square test for a contingency table of counts: expected counts, adjusted residuals, likelihood-ratio G², Cramér’s V and Yates’s correction for 2×2.
Runs in your browser. What you enter stays on this page and is not uploaded.
Results
- Pearson chi-square
- 30.070149
- Degrees of freedom (r − 1)(c − 1)
- 2
- p-value
- 2.954e-7
- Likelihood-ratio G²
- 30.016693 (p 3.034e-7)
- Cramér’s V
- 0.104436
- Total count n
- 2,757
- Conclusion
- Row and column variables are associated (significant at the 5% level).
| Column 1 | Column 2 | Column 3 | |
|---|---|---|---|
| Row 1 | 762 | 327 | 468 |
| Row 2 | 484 | 239 | 477 |
| Column 1 | Column 2 | Column 3 | |
|---|---|---|---|
| Row 1 | 703.67 | 319.65 | 533.68 |
| Row 2 | 542.33 | 246.35 | 411.32 |
| Column 1 | Column 2 | Column 3 | |
|---|---|---|---|
| Row 1 | 4.502 | 0.6995 | -5.316 |
| Row 2 | -4.502 | -0.6995 | 5.316 |
Expected count = row total × column total / n. Cramér’s V = √(χ² / (n (min(r, c) − 1))) uses the uncorrected χ².
Method and limits
How to use it
Paste a table of counts — one row per line, columns separated by spaces, tabs or commas. Each cell is the number of cases with that combination of row and column categories. Yates’s correction applies only to 2×2 tables (as R’s default).
Formulas
- Expected count Eij = (row i total × column j total) / n.
- Pearson χ² = Σ (O − E)² / E with (r − 1)(c − 1) degrees of freedom; p is the right tail of the chi-square distribution.
- Yates (2×2): Σ (|O − E| − min(0.5, |O − E|))² / E.
- Likelihood ratio G² = 2 Σ O ln(O / E).
- Cramér’s V = √(χ² / (n (min(r, c) − 1))); for 2×2 the signed phi coefficient is also shown.
- Adjusted standardized residual = (O − E) / √(E (1 − row share)(1 − column share)); values beyond ±1.96 point to the cells driving the association.
Assumptions and limits
- Counts of independent cases; each case in exactly one cell. Not for percentages, means or repeated measurements of the same people (use McNemar’s test for paired 2×2 data).
- Expected counts: at least 80% of cells 5 or more and none below 1 (Cochran 1954). Otherwise combine categories, or use Fisher’s exact test for 2×2 tables.
- A significant result shows association, not causation, and with large n even trivial associations are significant — report Cramér’s V.
Worked example
R’s chisq.test example (Agresti 2007: gender by party identification, 2,757 people): χ² = 30.07 with 2 df, p = 2.954e-7, Cramér’s V = 0.104. Adjusted residuals of ±4.5 and ±5.3 show the association lies in the first and third columns.
References
- R documentation: chisq.test
- SciPy documentation: scipy.stats.chi2_contingency
- Pearson (1900), On the criterion…, Philosophical Magazine 50
- Yates (1934), Contingency tables involving small numbers and the χ² test, Supplement to JRSS 1(2)
- Agresti, A. (2007), An Introduction to Categorical Data Analysis, 2nd ed., Wiley
Related tools
- Chi-square goodness-of-fit calculatorTest whether observed category counts fit equal or specified expected proportions, with each category’s contribution and residual.
- Fisher’s exact test calculatorExact test for a 2×2 table: two-sided and one-sided p-values, the conditional maximum likelihood odds ratio and its exact confidence interval.
- Cohen’s kappa calculatorAgreement between two raters beyond chance: Cohen’s κ, linear or quadratic weighted κ, standard error, confidence interval and z-test.
- Effect size calculatorCohen’s d, Hedges’ g and Glass’s Δ from group means, or odds ratio, risk ratio and risk difference from a 2×2 table, each with confidence intervals.
- Standard deviation calculatorPaste data to get the standard deviation (sample and population), variance, mean, median, mode, quartiles with the method stated, IQR, outliers, skewness and kurtosis.
- T-test calculatorOne-sample, independent two-sample (Welch and pooled) and paired t-tests from raw data or summary statistics, with confidence intervals and Cohen’s d.