Prob. y EstadísticaInference

Chi-Square Tests

Test goodness of fit and association in two-way tables.

Sin empezar Ir a la práctica

Esta lección aún no está traducida. Por ahora se muestra en inglés; la versión en español está en camino.

Some questions are about counts in categories: Is a die fair? Is preferring cats or dogs related to age? The chi-square statistic measures how far observed counts are from the counts a model expects. It extends the logic of significance tests to whole tables, including the two-way tables you already know.

Idea clave

$$\chi^2 = \sum \dfrac{(O - E)^2}{E},$$ with observed counts $O$ and expected counts $E$ (always counts, never percents). Goodness of fit: $E = n \times$ (model proportion), and $df = k - 1$ for $k$ categories. Independence in a two-way table: $df = (r - 1)(c - 1)$ and $$E = \dfrac{\text{row total} \times \text{column total}}{\text{grand total}}.$$ The p-value is the area to the right of $\chi^2$ under the chi-square curve. Expected counts should all be at least 5.

Por qué funciona

Each term compares a gap with the size expected: a gap of 10 is huge if 20 were expected and tiny if 1,000 were. Under $H_0$ a count varies with standard deviation about $\sqrt{E}$, so $(O - E)/\sqrt{E}$ acts like a z-score and each term is roughly a squared z-score. A sum of squared z-scores follows a chi-square distribution, which is skewed right; its degrees of freedom count how many cells are free to vary once the totals are fixed. For independence, the expected count gives each row the same column percents as the whole table, which is exactly what independence means.
The chi-square curve with 5 df. For the die example, χ² = 4.2 sits in the middle of the curve: a large p-value.

Ejemplo resuelto: Is the die fair?

A die is rolled 60 times: the faces 1 to 6 come up 8, 12, 9, 14, 6 and 11 times. Test whether it is fair.
  1. $H_0$: each face has probability $\frac16$. Expected count for each face: $60 \times \frac16 = 10$ (all at least 5).
  2. $$\chi^2 = \dfrac{4 + 4 + 1 + 16 + 16 + 1}{10} = 4.2$$ with $df = 6 - 1 = 5$.
  3. The p-value (right tail of the chi-square curve with 5 df) is about $0.52$.
  4. Fail to reject: these counts are typical for a fair die.

Respuesta: $\chi^2 = 4.2$, p ≈ 0.52: no evidence the die is unfair.

Observed counts with expected counts in parentheses.
Took reviewDid notTotal
Passed45 (33.75)90 (101.25)135
Did not pass5 (16.25)60 (48.75)65
Total50150200

Ejemplo resuelto: A test of independence

Use the table to test whether passing is independent of taking the review class.
  1. Expected for "passed and took review": $\dfrac{135 \times 50}{200} = 33.75$; the others follow the same way (shown in parentheses).
  2. Each gap is 11.25 in size: $$\chi^2 = \dfrac{11.25^2}{33.75} + \dfrac{11.25^2}{101.25} + \dfrac{11.25^2}{16.25} + \dfrac{11.25^2}{48.75} \approx 3.75 + 1.25 + 7.79 + 2.60 = 15.38$$
  3. $df = (2 - 1)(2 - 1) = 1$. The p-value is about $0.0001$.
  4. Reject independence: passing is associated with the review class (an association; the students chose whether to take it).

Respuesta: $\chi^2 \approx 15.4$, df 1, p ≈ 0.0001.

Error común

Using percentages instead of counts. The same percents are much stronger evidence from 1,000 observations than from 100, and $\chi^2$ grows with the counts to reflect that. Converting to percents hides the sample size. Check that every O and E is a count of individuals.

Práctica

Apruebas con 3 respuestas correctas, las 2 últimas seguidas. Cada respuesta correcta da 3 XP.

Cargando la práctica…

Se apoya en

Lleva a

Este es uno de los peldaños más altos de Probabilidad y Estadística.

Fuentes y lecturas

  • OpenStax, Introductory Statistics 2e, section 11.2 Goodness-of-Fit Test
  • OpenStax, Introductory Statistics 2e, section 11.3 Test of Independence