Two-Way Contingency Tables: Tests for Independence and Homogeneity 1. Test for Homogeneity (product multinomial sampling): Example 1 (2X2 table – test for equality of two population proportions, independent samples, both large). Based on the following case-control data: Smoker 15 8 Stroke No Stroke Non-Smoker 35 12 (a) Please test at the significance level of 0.05 whether smoking is a risk factor for stroke. (b) Please write up the entire SAS program necessary to answer the question raised in (a), including the data step. Solution: (a) Smoker Non-Smoker Total Stroke (case) 15 35 50 No Stroke (control) 8 12 20 π»0 : π π ππππππ πππππ πππ π (π π‘ππππ) π»πΌ : π π ππππππ πππππ πππ π (π π‘ππππ) πΜ = Z0 = pΜ1 − pΜ2 − 0 1 1 √pΜ(1 − pΜ) ( + ) n1 n2 = =π π ππππππ πππππ ππππ‘ππππ (ππ π π‘ππππ) ≠π π ππππππ πππππ ππππ‘ππππ (ππ π π‘ππππ) 15 + 8 ≈ 0.33 50 + 20 0.30 − 0.40 √0.33(1 − 0.33) ( 1 + 1 ) 50 20 ≈ −0.80 |Z0 | ≈ 0.08 < Z0.025 = 1.96 We can not reject H 0 at α = 0.05 and conclude that based on the given data, smoking is not confirmed as a risk factor for stroke. (a) SAS code: 1 Data smoking; Input stroke $ smoker $ count; Datalines; stroke yes 15 stroke no 35 nostrk yes 8 nostrk no 12 ; Run; Proc freq data=smoking; Tables stroke*smoker/chisq; Weight count; Run; Discussion: Now we examine the relations between the two possible Z-tests, and the Chi-square test for homogeneity as follows. The general format of the data is: Smoker Non-Smoker Stroke a (15) b (35) a+b (50) No stroke c (8) d (12) c+d (20) a+c (23) b+d (47) a+b+c+d (70) The two possible Z-tests are (*** although the one we have shown above in part (a) is the reasonable choice – but they indeed both lead to the same test statistic – which in turn is equivalent to the Chi-square test for homogeneity in this 2X2 table): π»0 : π π ππππππ πππππ πππ π (π π‘ππππ) π»πΌ : π π ππππππ πππππ πππ π (π π‘ππππ) =π Since πππππ π πππππ ≠π Μ2 − 0 πΜ1 − π 1 1 √πΜ(1 − πΜ)( + ) π1 π2 π π‘πππππ πππππ πππ− π ππππππ π»πΌ : ππ π‘πππππ ≠ π π ππππππ πππππ ππππ‘ππππ (ππ π π‘ππππ) πππππ π πππππ π π‘πππππ πππππ πππ− π ππππππ π0 (Large sample sizes) π0 = π»0 : ππ π‘πππππ = π π ππππππ πππππ ππππ‘ππππ (ππ π π‘ππππ) π»0 ~ π(0,1) = ∗ Μ2 ∗ − 0 πΜ1 − π 1 1 √πΜ∗ (1 − πΜ∗ )( ∗ + ∗ ) π1 π2 π»0 ~ π(0,1) Since 2 π π Μ2 = , π , π+π π+π π+π πΜ = π+π+π+π π1 = π + π, π2 = π + π π π Μ2 ∗ = , π , π+π π+π π+π πΜ ∗ = π+π+π+π π1 ∗ = π + π, π2 ∗ = π + π ∗ πΜ1 = πΜ1 = then then π π − −0 π + π π + π π0 = π+π π+π 1 1 √ ( + ) π+π+π+ππ+π+π+π π+π π+π π0 = π π − −0 π+π π+π π+π π+π 1 1 √ ( + ) π+π+π+ππ+π+π+π π+π π+π π+π+π+π = β― = (ππ − ππ)√ (π + π)(π + π)(π + π)(π + π) Now we denote the probabilities of the four table cells as follows: Smoker Non-Smoker Stroke π11 (= π1 ) π12 (= 1 − π1 ) No stroke π21 (= π2 ) π22 (= 1 − π2 ) The original null hypothesis of equal population proportions: π»0 : π1 = π2 is equivalent to the null hypothesis for the homogeneity test: π»0 : π11 = π21 , π12 = π22 The test statistic is: π02 = [π−πΜ(π+π)]2 πΜ(π+π) + [π−(1−πΜ)(π+π)]2 (1−πΜ)(π+π) + [π−πΜ(π+π)]2 πΜ(π+π) + [π−(1−πΜ)(π+π)]2 (1−πΜ)(π+π) (π + π)(π + π) 2 (π + π)(π + π) 2 ] [π − ] π+π+π+π π+π+π+π + (π + π)(π + π) (π + π)(π + π) π+π+π+π π+π+π+π [π − = 2 2 π+π+π+π 2 and π02 ~π(2−1)(2−1) (π + π)(π + π) (π + π)(π + π) [π − ] [π − ] π+π+π+π π+π+π+π 2 + + = π0 (π + π)(π + π) (π + π)(π + π) π+π+π+π π+π+π+π Where πΜ = π+π [For π1 × π2 table, ππ = (π1 − 1)(π2 − 1)] 3 The above example can be easily extended to other two-way contingency tables for testing homogeneity as follows: # of 0 1 2 ≥3 Stroke π11 π12 π13 π14 No stroke π21 π22 π23 π24 Children π»0 : π11 = π21 , π12 = π22 , π13 = π23 , π14 = π24 Note: The test for homogeneity is indeed a test of independence as well, that is why the two tests have the same Chi-square test statistic. 2. Test for Independence (multinomial sampling): Example 2. A university conducted a study concerning faculty teaching evaluation classification by students. A sample of 467 faculty is randomly selected, and each person is classified according to rank (Instructor, Assistant Professor, etc. ) and teaching evaluation (Above, Average, Below). Rank Teaching Evaluation Above Average Average Below Average Sum Relative Frequency Instructor Assistant Associate Relative Professor Professor Professor Sum Frequency 36 62 45 50 193 0.413 48 50 35 43 176 0.377 30 13 20 35 98 0.210 114 125 100 128 467 1.000 0.244 0.268 0.214 0.274 1.000 Ho: Teaching Evaluation and Rank are independent variables. Teaching Evaluation Instructor Above p11 Average Average p21 Below p31 Average Sum nο· j 114 Relative p.1 Frequency Rank Assistant Associate Relative niο· Professor Professor Professor Sum Frequency p12 p13 p14 193 p1. p22 p23 p24 176 p2. p32 p33 p34 98 p3. 125 100 128 467 p.2 p.3 p.4 1.000 nο·ο· 1.000 4 The independence assumption: p ij ο½ p iο·p ο· j for all ij Obserrved : nij Expected : Eij ο½ n ο΄ pˆij ο½ n ο΄ pˆi ο·pˆο· j ο½ π ni ο· ο΄ nο· j nο·ο· π (πππ −πΈππ ) π02 = ∑ ∑ πΈππ 2 π=1 π=1 df = (r-1)(c-1) For this example: r=#rows=3, c=#cols=4, 3X4 table Expected counts: Rank Teaching Evaluation Above Average Average Below Average Sum Instructor Assistant Associate Professor Professor Professor Sum 47.113 51.660 41.328 52.899 193 42.964 47.109 37.687 48.240 176 23.923 26.231 20.985 26.861 98 114 125 100 128 467 Individual cell chi-square values: Teaching Evaluation Above Average Instructor Assistant Associate Professor Professor Professor 2.6215 2.0698 0.3263 0.1589 Average 0.5904 0.1774 0.1916 0.5692 Below Average 1.5438 6.6740 0.0462 2.4663 ο£ 2 ο½ 2.62 ο« ο ο« 2.47 ο½ 17.44 οΎ ο£ 62,0.95 ο½ 12.59 5 ο Reject Ho There is evidence of an association between rank and evaluation. SAS Program: data eval; input job $ rating $ number; datalines; Instructor Above 36 Instructor Average 48 Instructor Below 30 Assistant Above 62 Assistant Average 50 Assistant Below 13 Associate Above 45 Associate Average 35 Associate Below 20 Professor Above 50 Professor Average 43 Professor Below 35 ; run; proc freq data=eval; weight number; tables job*rating / chisq ; run; The FREQ Procedure Statistics for Table of job by rating Statistic DF Value Prob ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Chi-Square 6 17.4354 0.0078 Likelihood Ratio Chi-Square 6 18.7430 0.0046 Mantel-Haenszel Chi-Square 1 10.8814 0.0010 Phi Coefficient 0.1932 Contingency Coefficient 0.1897 Cramer's V 0.1366 Sample Size = 467 6