Premed · Premed · Statistics Biostatistics
Lecture 17: Tests for Proportions and Chi-Square Tests
Statistics / Biostatistics
Learning Objectives
By the end of this lecture, students will be able to:
- Perform a one-sample z-test for a proportion
- Perform a two-sample z-test for comparing two proportions
- Construct and interpret a chi-square test for independence
- Perform a chi-square goodness-of-fit test
- Apply Fisher's exact test when sample sizes are small
- Interpret results in clinical and epidemiological contexts
Lecture Content
I. One-Sample Z-Test for a Proportion
The one-sample z-test for a proportion tests whether a population proportion equals a hypothesized value p_0. The hypotheses are H0: p = p_0 versus H1: p does not equal p_0. The test statistic is z = (p-hat - p_0) / sqrt[p_0(1 - p_0) / n], where the null value p_0 is used in the standard error calculation. The conditions require np_0 >= 5 and n(1 - p_0) >= 5.
As an example, a hospital claims its surgical infection rate is 5%. In a sample of 300 procedures, 24 infections occurred, giving p-hat = 0.08. The test statistic is z = (0.08 - 0.05) / sqrt(0.05 0.95 / 300) = 0.03 / 0.01258 = 2.385. The p-value is 2 P(Z > 2.385) = 2 * 0.0086 = 0.017. Since p < 0.05, we reject H0 and conclude the infection rate is significantly different from 5%.
II. Two-Sample Z-Test for Comparing Proportions
The two-sample z-test compares whether two population proportions are equal. The hypotheses are H0: p_1 = p_2 versus H1: p_1 does not equal p_2. The pooled proportion is p-hat = (x_1 + x_2) / (n_1 + n_2), and the test statistic is z = (p-hat_1 - p-hat_2) / sqrt[p-hat(1 - p-hat)(1/n_1 + 1/n_2)].
Consider Drug A with 45/100 responders and Drug B with 30/100 responders. The pooled proportion is 75/200 = 0.375. The test statistic is z = (0.45 - 0.30) / sqrt(0.375 0.625 (1/100 + 1/100)) = 0.15 / 0.0685 = 2.19. The p-value is 2 * P(Z > 2.19) = 0.029. We reject H0 and conclude there is a significant difference in response rates.
III. Chi-Square Test for Independence
The chi-square test for independence tests whether two categorical variables are associated. Data are organized in a contingency table (r rows by c columns). The hypotheses are H0: the two variables are independent versus H1: the two variables are associated. Expected frequencies are calculated as E_ij = (row_i total * column_j total) / grand total, and the test statistic is chi^2 = sum of [(O_ij - E_ij)^2 / E_ij], where O_ij and E_ij are the observed and expected frequencies respectively. The degrees of freedom are df = (r - 1)(c - 1). H0 is rejected if chi^2 exceeds the critical value chi^2_(alpha, df). All expected frequencies should be at least 5 (some sources accept at least 1 with no more than 20% of cells below 5).
<image>A worked example of a 2x2 chi-square test. A contingency table shows Treatment (Drug vs. Placebo) by Outcome (Improved vs. Not Improved). Observed counts are: Drug-Improved = 45, Drug-Not = 55, Placebo-Improved = 30, Placebo-Not = 70. Expected counts are calculated and shown in parentheses beside each observed count. The chi-square formula is applied step by step, yielding a test statistic of approximately 4.8. The p-value and conclusion are stated below the table.</image>
IV. Chi-Square Test: Larger Tables
The chi-square test extends naturally to any r by c table. For example, comparing three treatment groups (A, B, C) across four outcome categories yields df = (3 - 1)(4 - 1) = 6. A significant result indicates that some association exists but does not specify which cells contribute most to the departure from independence. Follow-up analysis should examine standardized residuals, where (O - E) / sqrt(E) values exceeding 2 indicate important cells, and post-hoc pairwise comparisons with correction for multiple testing can identify specific group differences.
V. Chi-Square Goodness-of-Fit Test
The chi-square goodness-of-fit test assesses whether observed frequencies for a single categorical variable match a hypothesized distribution. With k categories, the hypotheses are H0: the data follow the specified distribution versus H1: the data do not follow the specified distribution. The test statistic is chi^2 = sum of [(O_i - E_i)^2 / E_i], with df = k - 1. For example, one might test whether blood type distribution in a sample matches expected proportions of 45% O, 40% A, 11% B, and 4% AB by comparing observed counts to the expected counts based on these proportions. This test is also used to assess whether observed data follow a Poisson, binomial, or other theoretical distribution.
VI. Fisher's Exact Test
Fisher's exact test is used when sample sizes are small and the chi-square approximation may be unreliable. It calculates the exact probability of observing the data (or more extreme data) under H0. It is especially important for 2x2 tables with any expected count less than 5. The test is based on the hypergeometric distribution and reports an exact p-value rather than relying on the chi-square approximation. Although computationally intensive for large tables, Fisher's exact test is readily available in modern software.
<image>A decision flowchart for choosing between chi-square and Fisher's exact test. Start: "Is the data a contingency table?" Yes leads to "Check expected cell frequencies." If all expected >= 5, use "Chi-square test." If any expected < 5 in a 2x2 table, use "Fisher's exact test." If larger table with some expected < 5, consider "Fisher-Freeman-Halton exact test or collapse categories." Each endpoint includes a brief note on the test and its assumptions.</image>
VII. Yates' Continuity Correction
Yates' continuity correction is applied to the 2x2 chi-square test to improve its approximation to the exact test. The modified formula is chi^2 = sum of [(|O_ij - E_ij| - 0.5)^2 / E_ij]. This correction reduces the chi-square statistic, making the test slightly more conservative. The correction is somewhat controversial: some recommend always using it for 2x2 tables, while others recommend Fisher's exact test instead. Most modern software can compute Fisher's exact test directly, which has made Yates' correction less necessary in practice.
VIII. McNemar's Test
McNemar's test compares paired proportions, such as outcomes measured before and after treatment on the same subjects. Data are arranged in a 2x2 table of paired binary outcomes. Concordant pairs (both positive or both negative) contribute no information about change, while discordant pairs (one positive and one negative) drive the test. The test statistic is chi^2 = (b - c)^2 / (b + c), where b and c are the discordant cell counts, with df = 1.
As an example, suppose 25 patients had pain before treatment but not after (b = 25), while 10 had no pain before but pain after (c = 10). The test statistic is chi^2 = (25 - 10)^2 / (25 + 10) = 225 / 35 = 6.43, with p = 0.011, indicating a significant change in pain status after treatment.
IX. Measures of Association for Categorical Data
Beyond the chi-square test, it is important to quantify the strength of association. The phi coefficient measures association for 2x2 tables as phi = sqrt(chi^2 / n). Cramer's V generalizes phi for larger tables as V = sqrt(chi^2 / [n * min(r-1, c-1)]), with values ranging from 0 (no association) to 1 (perfect association). The odds ratio quantifies the strength of association in a 2x2 table and will be covered more thoroughly in Lecture 25. A measure of association should always be reported alongside the chi-square test to convey the effect size.
<image>A summary figure with three panels. Panel A: A mosaic plot for a 2x2 table showing the relationship between smoking status and lung cancer, with tile areas proportional to cell counts. Panel B: A grouped bar chart showing the same data. Panel C: A table listing the chi-square statistic, p-value, phi coefficient, and odds ratio. Annotations connect each visual element to its interpretation.</image>


