Chi Square and McNemar Test
Chi Square and McNemar Test
Chi Square and McNemar Test
Chi-square test
McNemar’s Test
Section 12 Part 2 Overview
• Section 12, Part 1 covered two inference methods for
categorical data from 2 groups
– Confidence Intervals for the difference of two proportions
– Two sample z-test of equality of two proportions
• Section 12 Part 2 covers inference methods for
categorical data
– Chi-square test for comparisons between 2 categorical
variables (Fisher’s exact test)
– McNemar ‘s Chi-square (Binomial Test) test for paired
categorical data
Level=I
• When the cells contain frequencies of outcomes, the table is
called a contingency table.
Survival to
Discharge
Race YES NO Total
Caucasian 84 3123 3207
African- 24 2886 2910
American
Total 108 6009 6117
Statistical Hypothesis:
Ho: Race and survival to hospital discharge are independent in
cases of non-traumatic out-of-hospital cardiac arrest.
HA: Race and survival to hospital discharge are not
independent in cases of non-traumatic out-of-hospital cardiac
arrest.
0 4 8 12 16 20
Critical value for α = 0.05 and Critical value for α = 0.05 and
Chi-square with 1 df is 3.84 Chi-square with 4 df is 9.49
Since the Chi-square distribution is always positive, the rejection region is only in the right tail
PubH 6414 Section 12 Part 2 12
How to Identify the critical value
• The rejection region of the Chi-square test is
the upper tail so there is only one critical value
• First calculate the df to identify the correct Chi-
square distribution
– For a 2 X 2 table, there are (2-1)*(2-1) = 1 df
R commander:
> qchisq(0.95,1)
[1] 3.841459
PubH 6414 Section 12 Part 2 13
State the conclusion
The p-value for P( χ2 > X2 )
> 1-pchisq(X2,1)
Survival to
Discharge
Race YES NO Total
Caucasian 84 3123 3207
56.62
African- 24 2886 2910
American
Total 108 6009 6117
Under the assumption of independence:
P(YES and Caucasian) = P(YES)*P(Caucasian)
= 108/6117 * 3207/6117 = 0.009256
Expected cell count =eij = 0.009256 * 6117 = 56.62
PubH 6414 Section 12 Part 2 15
Racial Differences and Cardiac Arrest
Survival to
Discharge
Race YES NO Total
Caucasian 84 3123 3207
56.62 3151.43
African- 24 2886 2910
American 51.38 2854.82
Total 108 6009 6117
=
(84 − 56.62 )2 +
(3123 − 3151.43)
2
+
(24 − 51.38)
2
+
(2886 − 2854.82 )
2
> 1-pchisq(28.42,1)
[1] 9.765127e-08
Example
30 day Streptokinase Streptokinase Accelerated Accelerated t-PA
outcome and SC and IV t-PA and IV Streptokinase Total
Heparin Heparin Heparin with IV Heparin
Survived 9091 9609 9692 9605 37997
9112.95
Died 705 768 652 723 2848
Total 9796 10377 10344 10328 40845
Under the assumption of independence:
P(Streptokinase and SC Heparin and Survival) =
P(Streptokinase and SC Heparin )*P(Survival)
= 9796/40845 * 37997/40845 =0.223
Expected cell count =eij = 0.223 * 40845 = 9112.95
PubH 6414 Section 12 Part 2 21
Chi-square Test: Testing for Equality or
Homogeneity of Proportions
Example
30 day Streptokinase Streptokinase Accelerated Accelerated t-PA
outcome and SC and IV t-PA and IV Streptokinase Total
Heparin Heparin Heparin with IV Heparin
Survived 9091 9609 9692 9605 37997
9112.95 9653.44 9622.74 9607.86
Died 705 768 652 723 2848
683.05 723.56 721.26 720.14
Total 9796 10377 10344 10328 40845
> 1-pchisq(10.85,3)
[1] 0.01256526
The four treatment groups are not equal with respect to 30 day mortality.
The largest relative departure from expected was noted in patients
receiving accelerated t-PA and IV heparin, with fewer patients than
expected dying.
Control
Exposed Unexposed
Case Exposed a b
Unexposed c d
The counts in the table for a case-control study are numbers of pairs
not numbers of individuals.
After treatment
Before + -
treatment + a b
- c d
Ho: b = c
Ho: b/(b+c) =0.5
• Cells ‘a’ and ‘d’ are the concordant cells. These cells
do not contribute any information about a difference
between pairs or over time so they aren’t used to
calculate the test statistic.
PubH 6414 Section 12 Part 2 36
McNemar Statistic
• The McNemar’s Chi-square statistic is calculated using
the counts in the ‘b’ and ‘c’ cells of the table:
χ 2
=
(b − c)
2
b+c
• Rule of thumb: b + c ≥ 20
• If the null hypothesis is true the McNemar Chi-square
statistic = 0.
• For a test with alpha = 0.05, the critical value for the
McNemar statistic = 3.84.
• 1-pchisq(X2,1)
Periop. only
HO: b = c
( b − c ) 2
(17 − 5 ) 2
χ =
2
= = 6.54
b+c 17 + 5
• P-value = P(χ2> 6.54) = 0.01
> 1-pchisq(6.54,1)
[1] 0.01054753
• Decision: Reject Ho
– By the rejection region method: 6.54 > 3.84
– By the p-value method: 0.01 < 0.05
http://www.graphpad.com/quickcalcs/McNemar1.cfm