Statistical Methods
Check Expected Counts Before a Contingency-Table Test
Define what one observation represents
Write the two categorical variables, their levels, and the population contributing to the table. For an ordinary independence analysis, each independent observation belongs to one cell. Repeated visits, matched pairs, or multiple specimens from one participant need methods that recognize their dependence.
Check that the table contains counts rather than percentages or survey-weighted totals. Reconcile its grand total with the relevant analysis population. Keep missing categories and excluded observations documented rather than quietly dropping them while building the table.
Distinguish observed from expected counts
An observed count comes from the data. Under the independence model, a cell's expected count is its row total multiplied by its column total, divided by the grand total. It is a model-based reference quantity and can be fractional even when every observed count is an integer.
The official R chi-squared test documentation describes the independence hypothesis, expected counts, asymptotic calculations, and simulation options. Inspect the expected table before accepting a default approximate p-value.
Recalculate a fictional table
Imagine two groups with rows of counts 12, 18 and 8, 22. Row totals are 30 and 30, column totals are 20 and 40, and the grand total is 60. The expected counts are therefore 10, 20 and 10, 20.
The expected-counts tool reproduces these values. Notice that a larger observed count does not necessarily imply a larger discrepancy from expectation: the reference depends on both margins. These invented counts illustrate the arithmetic, not a finding about a real population.
Investigate sparse and empty categories
Use the categorical-table audit worksheet to record small expected counts, empty margins, and whether an impossible cell reflects the design rather than an ordinary sampling zero. A table with an all-zero row or column needs its category structure reviewed before a routine calculation.
Expected counts below five are a common warning about the chi-squared approximation, not an automatic universal rule that selects the correct test. Exact or simulation-based methods may be appropriate for some independent count tables; complex surveys, matching, and clustering raise different issues. Do not merge categories solely to remove a warning without a defensible substantive rationale.
Record the chosen method, any continuity correction, and simulation settings where relevant. Report the observed distribution and an appropriate measure of association with uncertainty, not just whether a threshold was crossed. Before finalizing, have another analyst reconstruct the margins and confirm that the study design matches the proposed test. A numerically tidy expected table cannot establish independence or repair a biased sample.
Source checked on 1 November 2026; fictional expected counts independently recalculated.