Contingency Table Analysis
Chi square, G squared, odds ratio, risk ratio, McNemar, kappa, Cramer V and gamma online.
When to use it
Use to summarise the joint distribution of two categorical variables and test their independence. Standard pairing for survey data, epidemiology 2 by 2 tables, and ecology presence-absence matrices.
When NOT to use it
Do not use when expected cell counts fall below five and the table is small; use Fisher exact instead. Do not use chi-square on paired or matched binary data; use McNemar. For ordinal categorical variables prefer linear-by-linear or gamma rather than chi-square.
What you get
Pearson chi-square and likelihood-ratio G-squared with df and p; Cramer's V (effect size); for 2 by 2 tables: odds ratio with 95 percent CI, relative risk with 95 percent CI, Fisher exact p, and McNemar (paired); ordinal effect sizes (gamma, Kendall tau-b, Somers d); kappa for inter-rater reliability; row and column percentages; standardized residuals; low-expected-cell warnings.
Worked example
3 by 3 demo contingency table (fertiliser by soil class).
Fertilizer A: 30, 20, 10 Fertilizer B: 25, 35, 15 Fertilizer C: 10, 15, 40
Source: StatVeda built-in example.
How to interpret the output
Chi-square p below alpha means row and column variables are not independent. Cramer's V quantifies the strength of association: under 0.1 weak, 0.1 to 0.3 moderate, above 0.3 strong (Cohen 1988). Standardized residuals greater than |1.96| flag specific cells driving the association. For 2 by 2 outcomes report the OR or RR with CI, not just the chi-square. The five-per-cell rule of thumb (Cochran 1954) guides whether asymptotic chi-square is trustworthy; if not, use Fisher exact.
Common pitfalls
- Using chi-square when more than 20 percent of expected cells are below 5.
- Reporting only chi-square for a 2 by 2 outcome (no effect size).
- Using chi-square on paired binary data (use McNemar).
- Confusing odds ratio with relative risk for common outcomes (they diverge as baseline risk grows).
Try it in StatVeda
The Cross-Tabulation engine runs entirely in the browser. No signup, no install, no data sent to a server. Paste your data, hit Run, copy the output.
Open Cross-TabulationReferences
- Agresti, A. (2013). Categorical Data Analysis, 3rd edition. John Wiley and Sons, Hoboken.
- Fisher, R. A. (1922). On the interpretation of chi-square from contingency tables, and the calculation of P. Journal of the Royal Statistical Society, 85(1), 87 to 94.
- Cochran, W. G. (1954). Some methods for strengthening the common chi-square tests. Biometrics, 10(4), 417 to 451.