Observed and expected counts

Topic of Chi-squared tests, part of Statistical inference · Also in Chi-squared examples

Observed and expected counts

Type Topic
Taught in Chi-squared tests · Chi-squared examples
Part Statistical inference · Data analysis
Questions using it 12

In a chi-squared test the count O_i observed in each category is set against the count E_i=n\pi_i expected under the null hypothesis. Pearson’s statistic is \sum_i(O_i-E_i)^2/E_i; the chi-squared approximation is trusted when the expected counts are not too small, a usual rule being all E_i\ge5.

In Chi-squared tests

where O_i is the observed count and E_i=n\pi_i is the expected count.

In Chi-squared examples

Example 1 (A hundred balls in ten boxes) Throw n=100 balls at random into k=10 boxes, each equally likely. The counts are multinomial, and each expected count is 10.

Question. What is the distribution of the Pearson statistic, and does it match \chi^2_9?

Solution. One throw gave the counts 14, 6, 13, 12, 11, 12, 5, 11, 7, 9, for which

T=\sum_{i=1}^{10}\frac{(x_i-10)^2}{10}=\frac{16+16+9+4+1+4+25+1+9+1}{10}=8.6.

Repeating the experiment many times gives the distribution of T:

R <- 10000
t <- replicate(R, {
  counts <- tabulate(sample(1:10, size = 100, replace = TRUE), nbins = 10)
  sum((counts - 10)^2 / 10)
})
hist(t, breaks = 40, freq = FALSE)
curve(dchisq(x, df = 9), add = TRUE, col = 2, lwd = 2)
mean(t > qchisq(0.95, df = 9))     # close to 0.05

The histogram follows the \chi^2_9 density closely, and about 5% of the simulated statistics exceed the \chi^2_9 quantile 16.92, as they should under the null hypothesis. With 10 balls instead of 100, each expected count would be 1, far below the rule of thumb of 5, and the approximation would visibly fail.

Figure 1: Pearson statistics from 10 000 simulated throws of 100 balls into 10 equally likely boxes, against the \chi^2_9 density. The approximation is already good with expected counts of 10.

Used in

See also

Null and alternative hypotheses · Pearson statistic · Poisson regression · Pearson chi-squared approximation · Pearson test with estimated parameters · Chi-squared test of independence · Counts in categories · Chi-squared test with known cell probabilities

Glossary and index