Math ClubMath Club
v1 · padrão canônico

Lesson 108 — Chi-squared test: goodness of fit and independence

Chi-squared statistics: asymptotic distribution, degrees of freedom, goodness-of-fit test and independence test in contingency tables. Yates correction, Cramér's V.

Used in: 3rd year High School · Stochastik LK German · H2 Statistics Singapore · Math B Japanese — inferential statistics

χ2=i=1k(OiEi)2Ei\chi^2 = \sum_{i=1}^{k} \frac{(O_i - E_i)^2}{E_i}

The chi-squared statistic measures the total discrepancy between observed counts OiO_i and expected counts EiE_i under H0H_0. The larger χ2\chi^2, the more evidence against the null hypothesis. For goodness of fit, it tests whether data follow a prescribed distribution; for independence, it tests whether two categorical variables are independent in an r×cr \times c table.

Choose your door

Rigorous notation, full derivation, hypotheses

Rigorous definition

Chi-squared distribution

"Chi-squared distributions have an additivity property: if X1χn12X_1 \sim \chi^2_{n_1} and X2χn22X_2 \sim \chi^2_{n_2} are independent, then X1+X2χn1+n22X_1 + X_2 \sim \chi^2_{n_1 + n_2}." — OpenStax Statistics, §11.1

Goodness-of-fit test

Independence test in r×cr \times c table

"Expected frequencies for an independence test are calculated assuming that the row proportions are equal across all columns. If the null hypothesis is true (variables independent), this assumption is satisfied." — OpenIntro Statistics, §6.4

Assumptions for validity (Cochran's rule)

Yates correction (2×22 \times 2 table)

Effect size: Cramér's V

xf(x)critical regioncritical valuechi-squared df=5

Chi-squared curve with df = 5. The yellow region to the right of the critical value is the rejection region for H0 at level alpha = 5%.

Worked examples

Exercise list

42 exercises · 10 with worked solution (25%)

Application 23Understanding 8Modeling 7Challenge 2Proof 2
  1. Ex. 108.1Application

    A six-sided die is rolled 60 times. What is the number of degrees of freedom in the goodness-of-fit test for the uniform distribution?

    Show solution
    df=k1=61=5df = k - 1 = 6 - 1 = 5. For 6 categories with no estimated parameters, we lose 1 degree of freedom due to the constraint Oi=n\sum O_i = n.
  2. Ex. 108.2Application

    For the die from the previous exercise rolled 60 times, what is the expected frequency per face?

    Show solution
    Ei=npi0=60×(1/6)=10E_i = n \cdot p_i^0 = 60 \times (1/6) = 10 for each face.
    Show step-by-step (with the why)
    1. Identify n=60n = 60 and pi0=1/6p_i^0 = 1/6 for each face. Why: under H0H_0 of a fair die, each face has equal probability.
    2. Calculate Ei=npi0=60×1/6=10E_i = n \cdot p_i^0 = 60 \times 1/6 = 10.

    Trick: in discrete uniform distributions, EiE_i is simply n/kn/k.

  3. Ex. 108.3Application

    A die is rolled 60 times: observing 12, 8, 11, 9, 13, 7 for faces 1 to 6. Calculate χ2\chi^2 and conclude at 5%.

    Show solution
    χ2=(1210)2/10+(810)2/10+(1110)2/10+(910)2/10+(1310)2/10+(710)2/10=(4+4+1+1+9+9)/10=28/10=2,8\chi^2 = (12-10)^2/10 + (8-10)^2/10 + (11-10)^2/10 + (9-10)^2/10 + (13-10)^2/10 + (7-10)^2/10 = (4+4+1+1+9+9)/10 = 28/10 = 2,8. Critical value at 5% with df=5df=5: 11.07. Do not reject H0H_0.
  4. Ex. 108.4Application

    Calculate the degrees of freedom for the independence test in a 3×43 \times 4 contingency table.

    Show solution
    Table $3 \times 4$: df=(31)(41)=2×3=6df = (3-1)(4-1) = 2 \times 3 = 6.
  5. Ex. 108.5Application

    In a contingency table with R1=80R_1 = 80, C1=120C_1 = 120, n=300n = 300, calculate E11E_{11}.

    Show solution
    E11=R1×C1/n=80×120/300=32E_{11} = R_1 \times C_1 / n = 80 \times 120 / 300 = 32. Under independence, the expected frequency is the product of the marginals divided by the total.
    Show step-by-step (with the why)
    1. Identify the margins: row total R1=80R_1 = 80, column total C1=120C_1 = 120, grand total n=300n = 300.
    2. Apply the formula: E11=R1C1/n=80×120/300=32E_{11} = R_1 C_1 / n = 80 \times 120 / 300 = 32. Why: under independence, P(A1B1)=P(A1)P(B1)=(80/300)(120/300)P(A_1 \cap B_1) = P(A_1) \cdot P(B_1) = (80/300)(120/300), and E11=nP(A1B1)E_{11} = n \cdot P(A_1 \cap B_1).

    Trick: Eij=row total×column total/grand totalE_{ij} = \text{row total} \times \text{column total} / \text{grand total}.

  6. Ex. 108.6Application

    In an independence test, we obtained χ2=8\chi^2 = 8 with df=2df = 2. The critical value at 5% is 5.99. What is the conclusion?

    Show solution
    χ2=8>χ0,05;22=5,99\chi^2 = 8 > \chi^2_{0,05;\,2} = 5,99. We reject H0H_0: there is significant association between the variables at the 5% level.
  7. Ex. 108.7ApplicationAnswer key

    Calculate Cramér's V: χ2=20\chi^2 = 20, n=200n = 200, table 3×43 \times 4 (so min(r1,c1)=2\min(r-1,c-1) = 2).

    Show solution
    V=χ2/(nmin(r1,c1))=20/(200×2)=0,050,224V = \sqrt{\chi^2 / (n \cdot \min(r-1, c-1))} = \sqrt{20 / (200 \times 2)} = \sqrt{0,05} \approx 0,224. Small to medium effect.
  8. Ex. 108.8ApplicationAnswer key

    In which situations should the Yates correction be applied to the chi-squared test?

    Show solution
    Yates correction applies to $2 \times 2$ tables when expected frequencies are small (close to 5). It subtracts $0,5$ from each OijEij\lvert O_{ij} - E_{ij} \rvert before squaring, making the test more conservative.
  9. Ex. 108.9ApplicationAnswer key

    A researcher has Ei=3E_i = 3 in two of five cells in a table. Is the chi-squared test appropriate? Justify.

    Show solution
    See the referenced source for the detailed solution.
  10. Ex. 108.10Application

    Observe O=(45,35,20)O = (45, 35, 20) in n=100n = 100 observations with expected proportions (0,5;  0,3;  0,2)(0,5;\; 0,3;\; 0,2). Calculate χ2\chi^2.

    Show solution
    O=(45,35,20)O = (45, 35, 20), E=(50,30,20)E = (50, 30, 20) since n=100n = 100 and p0=(0,5,0,3,0,2)p^0 = (0,5,\, 0,3,\, 0,2). χ2=(4550)2/50+(3530)2/30+(2020)2/20=25/50+25/30+0=0,5+0,833=1,333\chi^2 = (45-50)^2/50 + (35-30)^2/30 + (20-20)^2/20 = 25/50 + 25/30 + 0 = 0,5 + 0,833 = 1,333.
    Show step-by-step (with the why)
    1. Calculate expected: E1=100×0,5=50E_1 = 100 \times 0,5 = 50; E2=100×0,3=30E_2 = 100 \times 0,3 = 30; E3=100×0,2=20E_3 = 100 \times 0,2 = 20.
    2. Calculate each term: (4550)2/50=25/50=0,5(45-50)^2/50 = 25/50 = 0,5; (3530)2/30=25/300,833(35-30)^2/30 = 25/30 \approx 0,833; (2020)2/20=0(20-20)^2/20 = 0.
    3. Sum: χ21,333\chi^2 \approx 1,333. df=31=2df = 3 - 1 = 2. Critical at 5%: 5.99. Do not reject H0H_0.

    Trivia: the third category contributes nothing to χ2\chi^2 since O3=E3O_3 = E_3.

  11. Ex. 108.11Application

    For the previous exercise (3 categories, fully specified distribution), what is the number of degrees of freedom?

    Show solution
    df=k1=31=2df = k - 1 = 3 - 1 = 2.
  12. Ex. 108.12Application

    A study measures blood pressure (high/normal) in the same group of patients before and after an exercise program. Why is the standard independence chi-squared test inadequate?

    Show solution
    See the referenced source for the detailed solution.
  13. Ex. 108.13Application

    What is the critical value χ0,05;12\chi^2_{0,05;\,1} (chi-squared with 1 degree of freedom at the 5% level)?

    Show solution
    The critical value χ0,05;12=3,841\chi^2_{0,05;\,1} = 3,841. This value is fundamental: any χ2>3,84\chi^2 > 3,84 in a $2 \times 2$ table (with df=1df = 1) is significant at 5%.
  14. Ex. 108.14Application

    Calculate the expected frequencies for the 2×22 \times 2 table with cells a=80a = 80, b=20b = 20, c=60c = 60, d=40d = 40.

    Show solution
    Table $2 \times 2$: a=80,b=20,c=60,d=40a=80, b=20, c=60, d=40. R1=100R_1 = 100, R2=100R_2 = 100, C1=140C_1 = 140, C2=60C_2 = 60, n=200n = 200. E11=100×140/200=70E_{11} = 100 \times 140/200 = 70; E12=100×60/200=30E_{12} = 100 \times 60/200 = 30; E21=70E_{21} = 70; E22=30E_{22} = 30.
  15. Ex. 108.15Application

    With the expected values from the previous exercise, calculate χ2\chi^2 and conclude at 5%.

    Show solution
    Using the expected values from the previous exercise: χ2=(8070)2/70+(2030)2/30+(6070)2/70+(4030)2/30=100/70+100/30+100/70+100/30=1,429+3,333+1,429+3,333=9,524\chi^2 = (80-70)^2/70 + (20-30)^2/30 + (60-70)^2/70 + (40-30)^2/30 = 100/70 + 100/30 + 100/70 + 100/30 = 1,429 + 3,333 + 1,429 + 3,333 = 9,524. df=1df=1. Critical 5%: 3.84. Reject H0H_0.
    Show step-by-step (with the why)
    1. Use EijE_{ij} calculated in the previous exercise: 70, 30, 70, 30.
    2. Calculate each term: (8070)2/70=100/701,43(80-70)^2/70 = 100/70 \approx 1,43; (2030)2/30=100/303,33(20-30)^2/30 = 100/30 \approx 3,33; same for row 2.
    3. Sum: χ29,52>3,84\chi^2 \approx 9,52 > 3,84. Reject H0H_0.

    Trick: in $2 \times 2$ table, the four contributions are symmetric in pairs.

  16. Ex. 108.16ApplicationAnswer key

    Why is df=1df = 1 in every 2×22 \times 2 contingency table? Explain geometrically or algebraically.

    Show solution
    df=(r1)(c1)=(21)(21)=1df = (r-1)(c-1) = (2-1)(2-1) = 1. In a $2 \times 2$ table, there are 4 cells but 3 constraints (row 1 total, column 1 total, and grand total — but the grand total is a consequence of the other two, so only r1+c1=2r - 1 + c - 1 = 2 independent constraints, leaving 421=14 - 2 - 1 = 1 degree of freedom). By formula: (21)(21)=1(2-1)(2-1) = 1.
  17. Ex. 108.17Application

    What are the mean and variance of χk2\chi^2_k? For k=20k = 20, is the distribution approximately symmetric?

    Show solution
    The distribution χk2\chi^2_k has mean kk and variance 2k2k. For $k$ large, by CLT, χk2\chi^2_k approximates N(k,2k)\mathcal{N}(k, 2k). The distribution is right-skewed (positively skewed), not symmetric.
  18. Ex. 108.18Application

    In a goodness-of-fit test with kk categories, how do the degrees of freedom change when we estimate rr parameters of the distribution from the data itself?

    Show solution
    When estimating rr parameters from the data, we lose rr additional degrees of freedom. Therefore df=k1rdf = k - 1 - r. Example: goodness of fit to Poisson with λ\lambda estimated: df=k11=k2df = k - 1 - 1 = k - 2.
  19. Ex. 108.19Application

    Show that the chi-squared statistic χ2=(OiEi)2/Ei\chi^2 = \sum (O_i - E_i)^2 / E_i is always non-negative.

    Show solution
    The chi-squared statistic is always non-negative: each term (OiEi)2/Ei0(O_i - E_i)^2 / E_i \geq 0 because it is a square divided by a positive number. Therefore χ2=0\chi^2 = \sum \geq 0.
  20. Ex. 108.20ApplicationAnswer key

    Is the goodness-of-fit chi-squared test one-tailed (right tail) or two-tailed? Why?

    Show solution
    Chi-squared is one-tailed (right tail): we reject H0H_0 only when χ2\chi^2 is large. Discrepancies both positive and negative contribute positive terms to the sum — there is no direction distinction in the test statistic.
  21. Ex. 108.21Application

    O=(10,20,30,40)O = (10, 20, 30, 40) in n=100n = 100 with expected uniform distribution. Calculate χ2\chi^2 and conclude at 1%.

    Show solution
    O=(10,20,30,40)O = (10, 20, 30, 40), E=25E = 25 each (uniform, n=100n = 100). χ2=(1025)2/25+(2025)2/25+(3025)2/25+(4025)2/25=(225+25+25+225)/25=500/25=20\chi^2 = (10-25)^2/25 + (20-25)^2/25 + (30-25)^2/25 + (40-25)^2/25 = (225 + 25 + 25 + 225)/25 = 500/25 = 20. df=3df = 3. Critical 1%: 11.34. Reject H0H_0.
    Show step-by-step (with the why)
    1. Ei=100/4=25E_i = 100/4 = 25 for each category.
    2. (1025)2/25=225/25=9(10-25)^2/25 = 225/25 = 9; (2025)2/25=1(20-25)^2/25 = 1; (3025)2/25=1(30-25)^2/25 = 1; (4025)2/25=9(40-25)^2/25 = 9.
    3. χ2=9+1+1+9=20\chi^2 = 9 + 1 + 1 + 9 = 20. df=3df = 3. Critical value at 1%: 11.34. Reject H0H_0.

    Trivia: the observed distribution is increasing, while H0H_0 posits uniformity — the extremes contribute much more to χ2\chi^2.

  22. Ex. 108.22Application

    What is the conceptual difference between homogeneity test and independence test? Does the formula for χ2\chi^2 change?

    Show solution
    Homogeneity test checks whether kk populations have the same categorical distribution (independent samples drawn from each population). Independence test checks whether two variables are independent in a single random sample. The mathematics is identical (dfdf, EijE_{ij}, χ2\chi^2), but the interpretation and design differ.
  23. Ex. 108.23Application

    χ2=14,5\chi^2 = 14,5 with df=5df = 5. What is the conclusion at 5% and at 1%? (Critical values: 11.07 and 15.09 respectively.)

    Show solution
    For χ2=14,5\chi^2 = 14,5 and df=5df = 5: critical value at 5% is 11.07. Since 14,5>11,0714,5 > 11,07, we reject H0H_0 at 5%. At 1%, critical is 15.09; since 14,5<15,0914,5 < 15,09, we do not reject at 1%. The p-value is between 1% and 5%.
  24. Ex. 108.24Understanding

    What would it mean to obtain χ2=0\chi^2 = 0 in a goodness-of-fit test? Is this possible in real data?

    Show solution
    When χ2=0\chi^2 = 0, all Oi=EiO_i = E_i exactly — the data fit the null hypothesis perfectly. This is rare in real data (sampling variation always produces some discrepancy). An exact χ2=0\chi^2 = 0 indicates data entry error or fabricated data.
  25. Ex. 108.25Understanding

    Why do very large samples make χ2\chi^2 a problematic measure? What alternative should be used?

    Show solution
    See the referenced source for the detailed solution.
  26. Ex. 108.26UnderstandingAnswer key

    Describe the shape of the chi-squared curve for small dfdf (e.g. df=2df = 2) vs. large dfdf (e.g. df=20df = 20). How does this relate to its origin as a sum of squares?

    Show solution
    The chi-squared distribution is right-skewed and always positive. It is the distribution of sums of squares of independent standard normals. The right skew decreases as dfdf grows (for large $df$ it approaches normal). This justifies using larger critical values for more degrees of freedom.
  27. Ex. 108.27UnderstandingAnswer key

    Which formula below is Pearson's chi-squared statistic?

    Select the correct option
    Select an option first
    Show solution
    See the referenced source for the detailed solution.
  28. Ex. 108.28Understanding

    Explain why Cochran's rule (Ei5E_i \geq 5) is necessary for the validity of the chi-squared test.

    Show solution
    See the referenced source for the detailed solution.
  29. Ex. 108.29ModelingAnswer key

    Dihybrid cross in peas predicts phenotypes in ratio 9:3:3:1. In 160 offspring observe 95, 30, 27, 8. Test goodness of fit at 5%.

    Show solution
    Expected proportions: Smooth-yellow p1=9/16p_1 = 9/16, Smooth-green p2=3/16p_2 = 3/16, Wrinkled-yellow p3=3/16p_3 = 3/16, Wrinkled-green p4=1/16p_4 = 1/16. In n=160n = 160: E1=90E_1 = 90, E2=30E_2 = 30, E3=30E_3 = 30, E4=10E_4 = 10. χ2=(9590)2/90+(3030)2/30+(2730)2/30+(810)2/10=0,278+0+0,3+0,4=0,978\chi^2 = (95-90)^2/90 + (30-30)^2/30 + (27-30)^2/30 + (8-10)^2/10 = 0,278 + 0 + 0,3 + 0,4 = 0,978. df=3df = 3. Critical 5%: 7.81. Do not reject — compatible with Mendel.
    Show step-by-step (with the why)
    See the referenced source for the step-by-step walkthrough.
  30. Ex. 108.30Modeling

    Survey of 400 university students (200 men, 200 women) tabulates opinion on quotas (Favorable/Neutral/Against): men 70/60/70, women 110/50/40. Test independence at 5%.

    Show solution
    Table $2 \times 3$: df=(21)(31)=2df = (2-1)(3-1) = 2. Calculate EijE_{ij} with the provided margins, then χ2\chi^2. If χ2>5,99\chi^2 > 5,99 (critical 5%), there is significant association between gender and opinion.
  31. Ex. 108.31Modeling

    A sample of 200 M&M's from a package shows: 30 red, 35 orange, 22 yellow, 40 green, 55 blue, 18 brown. According to the manufacturer, proportions are 13%, 20%, 14%, 16%, 24%, 13%. Test goodness of fit at 5%.

    Show solution
    See the referenced source for the detailed solution.
  32. Ex. 108.32Modeling

    A/B/C test on landing page: 200 visitors per variation. Conversions: A = 24, B = 30, C = 40. Test homogeneity of conversion rates at 5%.

    Show solution
    Homogeneity table $3 \times 2$: each group (A, B, C) has 200 visitors, conversions (24, 30, 40) and non-conversions (176, 170, 160). df=(31)(21)=2df = (3-1)(2-1) = 2. EA,conv=600×94/600=94/331,33E_{A,conv} = 600 \times 94/600 = 94/3 \approx 31,33. Calculate χ2\chi^2 and compare with 5.99.
  33. Ex. 108.33Modeling

    Four machines produce defects: 30, 40, 25, 35 defects respectively (total 130). Test whether the defect rate is uniform among machines at the 5% level.

    Show solution
    4 machines, defect counts: 30, 40, 25, 35 (total 130). Under H0H_0 of uniformity: Ei=130/4=32,5E_i = 130/4 = 32,5. χ2=(3032,5)2/32,5+(4032,5)2/32,5+(2532,5)2/32,5+(3532,5)2/32,5=(6,25+56,25+56,25+6,25)/32,5=125/32,53,85\chi^2 = (30-32,5)^2/32,5 + (40-32,5)^2/32,5 + (25-32,5)^2/32,5 + (35-32,5)^2/32,5 = (6,25 + 56,25 + 56,25 + 6,25)/32,5 = 125/32,5 \approx 3,85. df=3df = 3. Critical 5%: 7.81. Do not reject — no significant difference between machines.
  34. Ex. 108.34ModelingAnswer key

    Clinical trial with 50 patients (25 per group): vaccine resulted in 18 cures, placebo in 12 cures. Build the 2×22 \times 2 table and apply the chi-squared test with Yates correction at 5%.

    Show solution
    Table $2 \times 2$. Apply Yates correction if any EijE_{ij} is close to 5. Calculate χY2\chi^2_Y and compare with χ0,05;12=3,84\chi^2_{0,05;\,1} = 3,84. If we reject, we conclude that treatment significantly alters the proportion of cures.
  35. Ex. 108.35Modeling

    Do DNIT highway accident data follow a Poisson distribution? Describe the complete flowchart for the goodness-of-fit test, including how to handle the unknown parameter.

    Show solution
    Monthly highway accident data by state is categorized into ranges (0-2, 3-5, 6-10, 11+). Fit mean λ^\hat{\lambda} (Poisson) from data, calculate EiE_i, check Ei5E_i \geq 5 (merge categories if necessary), compute χ2\chi^2 with df=k2df = k - 2 (estimated λ\lambda). Compare with table.
  36. Ex. 108.36Understanding

    Which condition below is necessary for the validity of the independence chi-squared test?

    Select the correct option
    Select an option first
    Show solution
    See the referenced source for the detailed solution.
  37. Ex. 108.37Understanding

    In a before-after study, the same 80 patients are classified as hypertensive or normal before and after intervention. Why use McNemar instead of standard chi-squared?

    Show solution
    McNemar tests whether bcb \neq c in a $2 \times 2$ table of paired data (where bb and cc are the discordances). The statistic is χ2=(bc)2/(b+c)\chi^2 = (b-c)^2/(b+c) with df=1df = 1. Standard chi-squared would ignore the correlation between repeated measures, violating the independence assumption.
  38. Ex. 108.38Understanding

    A survey of 500 Brazilians records region (North, Southeast, South) and payment preference (cash vs. installment). Which test is most appropriate to verify whether preference and region are independent?

    Select the correct option
    Select an option first
    Show solution
    Two categorical variables (region: 3 categories × preference: 2 categories) in a single random sample → independence test with df=(31)(21)=2df = (3-1)(2-1) = 2. Not goodness of fit (no prescribed distribution). Not paired t-test (no pairing). Not linear regression (categorical response).
  39. Ex. 108.39Challenge

    An emergency room recorded 210 visits in one week (30 per day expected). Observed: Sun=18, Mon=40, Tue=28, Wed=25, Thu=29, Fri=42, Sat=28. Is the flow uniform across days? Test at 5%.

    Show solution
    H0H_0: weekdays are equally requested. n=210n = 210, k=7k = 7, Ei=30E_i = 30 each. χ2=(Oi30)2/30\chi^2 = \sum (O_i - 30)^2/30. Depending on observed counts, compare with χ0,05;62=12,59\chi^2_{0,05;\,6} = 12,59. If the ER prefers Monday and Friday (common care pattern), expect high χ2\chi^2 and rejection of H0H_0.
  40. Ex. 108.40Challenge

    Electoral survey in 3 Brazilian states (SP, RJ, MG) with 600 voters (200 per state) records candidate preference (A, B, C). Data: SP=(80,70,50), RJ=(60,90,50), MG=(70,60,70). Test independence between state and candidate at 5% and calculate Cramér's V.

    Show solution
    Table $3 \times 3$ (3 candidates × 3 states). df=(31)(31)=4df = (3-1)(3-1) = 4. Calculate Eij=RiCj/nE_{ij} = R_i C_j / n for each cell. Compute χ2\chi^2. If χ2>χ0,05;42=9,49\chi^2 > \chi^2_{0,05;\,4} = 9,49, conclude that candidate preference varies by state. Report V=χ2/(n2)V = \sqrt{\chi^2/(n \cdot 2)} as effect size.
    Show step-by-step (with the why)
    1. Organize the $3 \times 3$ table with counts by state × candidate.
    2. Calculate row margins (RiR_i) and column margins (CjC_j).
    3. Calculate each Eij=RiCj/nE_{ij} = R_i C_j / n. Check Eij5E_{ij} \geq 5.
    4. Calculate χ2=(OijEij)2/Eij\chi^2 = \sum (O_{ij} - E_{ij})^2 / E_{ij}. df=4df = 4.
    5. Compare with 9.49 and calculate VV to report the effect.

    Trick: in large $r \times c$ tables, identify which cells have standardized residuals greater than 1.96 to pinpoint where association is strongest.

  41. Ex. 108.41ProofAnswer key

    Show that for k=2k = 2 categories, χ2=Z2\chi^2 = Z^2 where ZZ is the bilateral zz statistic for proportion test. This explains why χ0,05;12=(1,96)23,84\chi^2_{0,05;\,1} = (1,96)^2 \approx 3,84.

    Show solution
    For k=2k = 2 categories with probabilities pp and 1p1-p: O1+O2=nO_1 + O_2 = n, E1=npE_1 = np, E2=n(1p)E_2 = n(1-p). χ2=(O1np)2/(np)+(O2n(1p))2/(n(1p))\chi^2 = (O_1 - np)^2/(np) + (O_2 - n(1-p))^2/(n(1-p)). Since O2E2=(O1E1)O_2 - E_2 = -(O_1 - E_1), each term is (O1np)2×(1/(np)+1/(n(1p)))=(O1np)2/(np(1p))(O_1 - np)^2 \times (1/(np) + 1/(n(1-p))) = (O_1 - np)^2/(np(1-p)). This is exactly Z2Z^2 where Z=(O1np)/np(1p)Z = (O_1 - np)/\sqrt{np(1-p)} is the test statistic for binomial proportion — showing equivalence between chi-squared with df=1df=1 and bilateral zz test for proportion.
  42. Ex. 108.42Proof

    Prove the formula df=(r1)(c1)df = (r-1)(c-1) for the independence test in an r×cr \times c table, explaining how many independent constraints the margins impose on the count vector.

    Show solution
    For $r \times c$ table: there are rcrc cells, with rr row constraints (jOij=Ri\sum_j O_{ij} = R_i) and cc column constraints (iOij=Cj\sum_i O_{ij} = C_j), but the rr row and cc column constraints share the global constraint ijOij=n\sum_{ij} O_{ij} = n, totaling r+c1r + c - 1 independent constraints. Therefore df=rc(r+c1)=rcrc+1=(r1)(c1)df = rc - (r + c - 1) = rc - r - c + 1 = (r-1)(c-1). Each constraint "costs" one degree of freedom because it fixes a dimension in the count vector space.

Sources

Updated on 2026-05-11 · Author(s): Clube da Matemática

Found an error? Open an issue on GitHub or submit a PR — open source forever.