Chi-Square Tests ($\chi^2$)
The comprehensive master guide covering contingency table independence, expected frequency matrices, Yates' continuity correction, distribution goodness-of-fit, and pooling rules.
01. Intuition: The Discrepancy Metric
Developed by Karl Pearson, the **Chi-Square ($\chi^2$) statistic** measures the normalized discrepancy between empirically observed counts ($O$) and theoretically expected counts ($E$ under $H_0$):
Test of Independence
Determines if two categorical attributes (e.g., Treatment vs Recovery, Smoker vs Lung Cancer) are statistically independent in an $r \times c$ contingency table.
Goodness of Fit Test
Evaluates whether an observed sample frequency distribution conforms to a theoretical probability model (Uniform, Poisson, Binomial, Mendelian genetic ratios).
1. **Total Sample Size:** $N \ge 50$.
2. **Minimum Expected Frequency (Rule of 5):** No expected cell frequency $E_i$ should be $< 5$. If $E_i < 5$, pool adjacent classes or apply Yates' correction.
3. **Raw Counts Only:** Observations MUST be raw counts/frequencies. Never apply $\chi^2$ directly to percentages, proportions, or averages.
4. **Mutually Exclusive & Random:** Each subject must belong to exactly one category, sampled independently.
02. Contingency Tables & Test of Independence
In an $r \times c$ contingency table with $r$ rows and $c$ columns, the expected frequency for cell $(i, j)$ under $H_0$ (Independence) is:
Direct $2 \times 2$ Table Shortcut Formula
For a standard $2 \times 2$ table $\begin{pmatrix} a & b \\ c & d \end{pmatrix}$ with $N = a + b + c + d$, Pearson's statistic simplifies without calculating individual $E_{ij}$:
$$\begin{aligned} \chi^2 = \frac{N (ad - bc)^2}{(a + b)(c + d)(a + c)(b + d)}, \quad df = (2 - 1)(2 - 1) = 1 \end{aligned}$$03. Yates' Correction for Continuity ($2 \times 2$ Table)
Because the discrete counts are approximated by a continuous $\chi^2$ distribution, Frank Yates introduced a continuity correction ($\pm 0.5$) for $2 \times 2$ tables, especially when cell counts are modest:
04. Goodness of Fit & Parameter Estimation Rules
Tests whether an observed frequency distribution $O_i$ matches expected frequencies $E_i = N \cdot P(X = x_i)$.
Degrees of Freedom in Goodness of Fit:
$$\begin{aligned} df = k - 1 - m \end{aligned}$$- $k$: Number of categories/classes after pooling small cells ($E < 5$).
- $1$: Subtracted because $\sum E_i = \sum O_i = N$ (Total frequency constraint).
- $m$: Number of population parameters estimated from the sample data:
- $m = 0$ for completely specified theoretical ratios (e.g. Mendelian 9:3:3:1 or Fair Die $1/6$).
- $m = 1$ when estimating mean rate $\lambda = \bar{x}$ (Poisson) or success rate $p$ (Binomial).
- $m = 2$ when estimating mean $\mu$ and standard deviation $\sigma$ (Normal).
05. 6 Deadly Exam Traps & Common Student Mistakes
Dividing by $O$ instead of $E$
The denominator MUST be Expected frequency: $\frac{(O - E)^2}{E}$. Writing $\frac{(O - E)^2}{O}$ is a fatal conceptual error.
Testing cells where expected frequency is $< 5$
If any expected cell has $E_i < 5$, you MUST pool it with an adjacent class. Failing to pool invalidates the large-sample $\chi^2$ approximation.
Using $df = N - 1$ on a Contingency Table
In contingency tables, $df = (r - 1)(c - 1)$, NOT $N - 1$. For a $2 \times 2$ table, $df = 1$. For a $3 \times 3$ table, $df = (2)(2) = 4$.
Using $df = k - 1$ when $\lambda$ was estimated
When you compute sample mean $\lambda = \sum fx / N$, you used up 1 degree of freedom! The correct $df$ is $k - 1 - 1 = k - 2$.
Applying $\chi^2$ to percentages like 40% and 60%
$\chi^2$ requires integer frequencies. Always multiply percentages by sample size to get raw headcounts ($O$) before computing $\chi^2$.
Dividing $\alpha$ by 2
$\chi^2$ is inherently a **one-tailed (right-tailed) test** because deviations are squared. For $\alpha = 0.05$ with $df = 1$, use $\chi^2_{0.05, 1} = \mathbf{3.841}$.
06. The Complete University Question Bank (All Problems Solved)
Every single Chi-Square question from past semester exams (May 2025, Dec 2024, Nov 2025) and class test materials:
Question 1: Epidemic Disease Treatment Effectiveness ($2 \times 2$ Table) (10 Marks)
Question Statement (Verbatim):
"In an epidemic of a certain disease, 92 children contracted the disease. Of these, 41 received no treatment and of these 10 showed after-effects. Of the remainder who did receive treatment, 17 showed after-effects. Test the hypothesis that the treatment was not effective at $\alpha = 0.05$. (10 Marks)"
View Complete Step-by-Step Solution (Pearson & Yates)
1. Construct the $2 \times 2$ Contingency Table:
Total children $N = 92$. Untreated = 41 (10 after-effects, $41 - 10 = 31$ no after-effects). Treated = $92 - 41 = 51$ (17 after-effects, $51 - 17 = 34$ no after-effects).
| Group | After-Effects | No After-Effects | Row Total |
|---|---|---|---|
| No Treatment | $a = 10$ | $b = 31$ | $a + b = \mathbf{41}$ |
| Treatment | $c = 17$ | $d = 34$ | $c + d = \mathbf{51}$ |
| Col Total | $a + c = \mathbf{27}$ | $b + d = \mathbf{65}$ | $N = \mathbf{92}$ |
2. Cross-Product Term:
$$\begin{aligned} ad - bc &= (10 \times 34) - (31 \times 17) = 340 - 527 = \mathbf{-187} \\[4pt] (ad - bc)^2 &= (-187)^2 = \mathbf{34,969} \end{aligned}$$3. Uncorrected Pearson Chi-Square ($\chi^2$):
$$\begin{aligned} \chi^2 &= \frac{N (ad - bc)^2}{(a + b)(c + d)(a + c)(b + d)} \\[6pt] &= \frac{92 \times 34,969}{41 \times 51 \times 27 \times 65} = \frac{3,217,148}{3,668,535} \approx \mathbf{0.8769} \end{aligned}$$4. With Yates' Continuity Correction:
$$\begin{aligned} |ad - bc| - \frac{N}{2} &= |-187| - \frac{92}{2} = 187 - 46 = \mathbf{141} \\[4pt] \chi_{\text{Yates}}^2 &= \frac{92 \times (141)^2}{3,668,535} = \frac{92 \times 19,881}{3,668,535} = \frac{1,829,052}{3,668,535} \approx \mathbf{0.4986} \end{aligned}$$Degrees of freedom: $df = (2 - 1)(2 - 1) = \mathbf{1}$. Critical value at $\alpha = 0.05$ is $\chi^2_{0.05, 1} = \mathbf{3.841}$.
Since $\chi^2_{\text{calc}} = 0.8769 < 3.841$ (and $\chi^2_{\text{Yates}} = 0.4986 < 3.841$), we fail to reject $H_0$.
There is no statistically significant evidence at the 5% level to show that the treatment was effective in reducing after-effects.
Question 2: Treatment Effectiveness & 4 Uses of Chi-Square (12 Marks)
Question Statement (Verbatim):
"Solve the 92 children epidemic disease problem and test the hypothesis that treatment was not effective. Also explain the uses of chi-square test in different scenarios. (12 Marks)"
View Complete 4 Methodological Uses Model Answer
(Numerical solution matches Question 1: $\chi^2 = 0.8769 < 3.841 \implies$ Fail to reject $H_0$).
4 Methodological Uses of the Chi-Square Test (Full Marks Criteria):
- Test of Independence of Attributes: Evaluates whether two qualitative variables in a contingency table ($r \times c$) possess an association or operate independently ($df = (r-1)(c-1)$).
- Test of Goodness of Fit: Assesses whether observed empirical frequencies conform to a hypothesized theoretical distribution (Poisson, Binomial, Normal, Uniform) ($df = k - 1 - m$).
- Test of Homogeneity: Tests whether multiple independent sub-populations are homogeneous with respect to a specific categorical characteristic.
- Test of a Single Population Variance: Tests whether a sample variance $s^2$ from a normal population conforms to a hypothesized population variance $\sigma_0^2$ via the test statistic: $$\begin{aligned} \chi^2 = \frac{(n - 1)s^2}{\sigma_0^2} \sim \chi^2(n - 1) \end{aligned}$$
Question 3: Poisson Distribution Goodness of Fit & Pooling (20 Marks)
Question Statement (Verbatim):
"Explain Chi square Test and how it is useful to solve a goodness of fit problem. Use the following data to explain (20 Marks)"
| x | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| f | 314 | 335 | 204 | 86 | 29 | 9 | 3 | 0 |
View Complete Step-by-Step Solution & Pooling Table
Step A: Parameter Estimation ($\lambda$):
$$\begin{aligned} N &= 314 + 335 + 204 + 86 + 29 + 9 + 3 + 0 = \mathbf{980} \\[4pt] \sum fx &= 0(314) + 1(335) + 2(204) + 3(86) + 4(29) + 5(9) + 6(3) + 7(0) \\[4pt] &= 335 + 408 + 258 + 116 + 45 + 18 = \mathbf{1,180} \\[4pt] \lambda &= \frac{\sum fx}{N} = \frac{1,180}{980} \approx \mathbf{1.2041} \end{aligned}$$Step B: Expected Frequencies $E_i = N \frac{e^{-\lambda} \lambda^x}{x!}$:
- $E(0) = 980 \times e^{-1.2041} = 980 \times 0.29997 = \mathbf{293.97}$
- $E(1) = 293.97 \times 1.2041 = \mathbf{353.96}$
- $E(2) = 353.96 \times \frac{1.2041}{2} = \mathbf{213.10}$
- $E(3) = 213.10 \times \frac{1.2041}{3} = \mathbf{85.53}$
- $E(4) = 85.53 \times \frac{1.2041}{4} = \mathbf{25.75}$
- $E(5) = 6.20, \; E(6) = 1.24, \; E(7) = 0.21$
Step C: Mandatory Pooling Rule ($E_i \ge 5$):
Because $E(6) = 1.24 < 5$ and $E(7) = 0.21 < 5$, classes $x \ge 5$ are pooled together:
$$\begin{aligned} O_{\text{pooled}} &= 9 + 3 + 0 = \mathbf{12} \\[4pt] E_{\text{pooled}} &= 980 - (293.97 + 353.96 + 213.10 + 85.53 + 25.75) = \mathbf{7.69} \end{aligned}$$Step D: Chi-Square Calculation Table:
| Class ($x$) | $O_i$ | $E_i$ | $O_i - E_i$ | $(O_i - E_i)^2$ | $\frac{(O_i - E_i)^2}{E_i}$ |
|---|---|---|---|---|---|
| 0 | 314 | 293.97 | $+20.03$ | 401.20 | $1.3648$ |
| 1 | 335 | 353.96 | $-18.96$ | 359.48 | $1.0156$ |
| 2 | 204 | 213.10 | $-9.10$ | 82.81 | $0.3886$ |
| 3 | 86 | 85.53 | $+0.47$ | 0.22 | $0.0026$ |
| 4 | 29 | 25.75 | $+3.25$ | 10.56 | $0.4102$ |
| $\ge 5$ | 12 | 7.69 | $+4.31$ | 18.58 | $2.4156$ |
| Total | 980 | 980.00 | 0 | - | $\chi^2_{\text{calc}} = \mathbf{5.5974}$ |
Step E: Degrees of Freedom & Decision:
$$\begin{aligned} df &= k - 1 - m = 6 - 1 - 1 = \mathbf{4} \\[4pt] \chi^2_{0.05, 4} &= \mathbf{9.488} \end{aligned}$$The Poisson distribution is an excellent fit for the observed data.
Question 4: Age Group vs Preferred Sport Activity ($3 \times 3$ Contingency)
Question Statement:
"A community sports center records 390 participants across 3 age tiers and 3 sports activities. Test at $\alpha = 0.05$ whether sport preference is independent of age group."
| Age Tier | Swimming (S) | Volleyball (V) | Table Tennis (TT) | Row Total |
|---|---|---|---|---|
| Adult | 80 (69.23) | 50 (64.62) | 40 (36.15) | $R_1 = \mathbf{170}$ |
| Teen | 30 (44.87) | 60 (41.87) | 20 (23.41) | $R_2 = \mathbf{110}$ |
| Child | 40 (44.87) | 30 (41.87) | 70 (23.41) | $R_3 = \mathbf{110}$ |
| Col Total | $C_1 = \mathbf{160}$ | $C_2 = \mathbf{150}$ | $C_3 = \mathbf{80}$ | $N = \mathbf{390}$ |
View Complete Step-by-Step Solution
1. Expected Frequencies $E_{ij} = \frac{R_i \times C_j}{N}$:
- Adult: $E_{11} = \frac{170 \times 160}{390} = 69.23; \; E_{12} = \frac{170 \times 150}{390} = 64.62; \; E_{13} = \frac{170 \times 80}{390} = 36.15$
- Teen: $E_{21} = \frac{110 \times 160}{390} = 44.87; \; E_{22} = \frac{110 \times 150}{390} = 41.87; \; E_{23} = \frac{110 \times 80}{390} = 23.41$
- Child: $E_{31} = 44.87; \; E_{32} = 41.87; \; E_{33} = 23.41$
2. Chi-Square Summation:
$$\begin{aligned} \chi^2 &= \frac{(80 - 69.23)^2}{69.23} + \frac{(50 - 64.62)^2}{64.62} + \dots + \frac{(70 - 23.41)^2}{23.41} \\[4pt] &= 1.676 + 3.308 + 0.410 + 4.928 + 7.850 + 0.497 + 0.529 + 3.366 + 92.74 \\[4pt] &\approx \mathbf{115.30} \end{aligned}$$3. Degrees of Freedom & Decision:
$$\begin{aligned} df = (r - 1)(c - 1) = (3 - 1)(3 - 1) = 2 \times 2 = \mathbf{4} \\[4pt] \chi^2_{0.05, 4} = \mathbf{9.488} \end{aligned}$$Sport preference is highly dependent on age tier (Children heavily prefer Table Tennis).
Question 5: Testing a Fair 6-Sided Die (Discrete Uniform Fit)
Question Statement:
"A six-sided die is rolled 120 times with observed outcomes: 1: 15, 2: 24, 3: 18, 4: 21, 5: 25, 6: 17. At $\alpha = 0.05$, test whether the die is fair."
View Complete Step-by-Step Solution
1. Theoretical Expected Frequencies: Under $H_0$ (fair die), each face has probability $1/6$.
$$\begin{aligned} E_i = 120 \times \frac{1}{6} = \mathbf{20} \quad \text{for all } i \in \{1, 2, 3, 4, 5, 6\} \end{aligned}$$2. Compute Chi-Square Statistic:
$$\begin{aligned} \chi^2 &= \sum_{i=1}^6 \frac{(O_i - 20)^2}{20} \\[4pt] &= \frac{(15-20)^2 + (24-20)^2 + (18-20)^2 + (21-20)^2 + (25-20)^2 + (17-20)^2}{20} \\[4pt] &= \frac{25 + 16 + 4 + 1 + 25 + 9}{20} = \frac{80}{20} = \mathbf{4.00} \end{aligned}$$3. Degrees of Freedom & Decision:
$$\begin{aligned} df &= k - 1 - 0 = 6 - 1 = \mathbf{5} \\[4pt] \chi^2_{0.05, 5} &= \mathbf{11.070} \end{aligned}$$The die is consistent with a fair, balanced six-sided die.
Dynamic 2x2 Contingency Table & Yates Calculator
Enter cell counts $\begin{pmatrix} a & b \\ c & d \end{pmatrix}$ to compute Pearson $\chi^2$ and Yates' corrected $\chi^2$ instantly:
08. Interactive Self-Test Quiz (Active Recall)
Test your contingency table, Yates' correction, and goodness of fit skills. Attempt all 4 questions:
In a study with a $3 \times 4$ contingency table, what are the degrees of freedom for testing independence?
Why is Yates' correction applied to a $2 \times 2$ contingency table?
Subtracting $N/2$ contracts the discrepancy towards zero, correcting for continuity and reducing Type I error inflation.
In a Chi-square test, what must be done if an expected frequency is $E_i = 3.2$?
Under Cochran's criteria, every expected cell frequency must be $\ge 5$. Small cells are pooled, reducing the number of effective classes $k$.
A sample of counts is classified into 7 categories after pooling, and the Poisson mean $\lambda$ is estimated from the data. What is the degrees of freedom?
One degree of freedom is lost for total frequency constraint, and another is lost for estimating $\lambda$.
Self-Test Progress
09. Exam Hall Answer Sheet Presentation Checklist
When solving a Chi-Square problem in the semester exam, follow this exact structure to guarantee maximum marks:
- State the Hypotheses: $H_0$: The two attributes are independent (or data follows specified distribution) vs $H_1$: Dependent.
- Contingency Table with Marginals: Draw the table with Row Totals, Column Totals, and Grand Total $N$.
- Expected Frequencies: Write $E_{ij} = \frac{R_i \times C_j}{N}$ and list all cell expectations.
- Check the Rule of 5: Explicitly note: "All expected frequencies $E_i \ge 5$, so Chi-square conditions are satisfied."
- Chi-Square Calculation: State formula $\chi^2 = \sum \frac{(O-E)^2}{E}$ (and Yates formula for $2 \times 2$). Show arithmetic table.
- Degrees of Freedom & Critical Value: State $df = (r-1)(c-1)$ or $df = k - 1 - m$ and look up $\chi^2_{\alpha, df}$.
- Final Decision & Contextual Conclusion: Compare $\chi^2_{\text{calc}}$ against $\chi^2_{\text{crit}}$ and write an unambiguous conclusion sentence.