Chi Square Test
Effectiveness of Influenza Vaccine Against Life-threatening
RT-PCR-confirmed Influenza Illness in US Children, 2010–
2012
• This study involved children aged 6 months through 17 years during the 2010–2011
and 2011–2012 influenza seasons from 21 US pediatric intensive care units (PICUs)
participating in the Pediatric Acute Lung Injury and Sepsis Investigators (PALISI)
Network.
• Children admitted with acute severe respiratory illness of ≤7 days duration who
tested positive for influenza by real-time reverse-transcription polymerase chain
reaction (RT-PCR) were classified as cases; admitted children who tested negative
for influenza were classified as PICU controls. A secondary group of community
controls was created from a matched sample of children who resided in the same
geographic area and had not experienced an influenza-associated hospitalization
between September of the study year and the matched case's PICU admission date.
[Link]
Contingency table
Vaccinated
Yes No Total
Yes 51 69 120
Influenza
No 146 43 189
Total 197 112 309
Test of Independence
Two events are called independent if
P(A∩B)=P(A)*P(B)
or the equivalent:
P(A|B)=P(A)
In our case the two events ARE NOT independent.
Events and Independence
A: The child was vaccinated
AC: The child was not vaccinated
B: The child got influenza
BC :The child did not get influenza
Compare P(A∩B) with P(A) * P(B)
Chi Square Test of Independence
H0 : The two variables are independent.
HA : The two variables are not independent.
1. Calculate the Chi square value of the contingency table
2. Compute its corresponding p value.
3. If that p value is smaller than our threshold alpha, we will reject the
null hypothesis in favor of the alternative.
α=0.05
Expected probabilities
• If the two variables were independent each box in the table would be
the product of the corresponding probabilities.
• We want to figure out if the difference between the product and the
reported one is just statistical variation or there is indeed a connection.
Creating Expected probabilities
• To move from probabilities to numbers we need to multiply
(carefully) with the total.
Vaccinated
Yes No Total
Yes Observed P(A∩B) P(AC∩B) 120
Yes Expected P(A)*P(B) P(AC)*P(B)
Influenza
No Observed P(A∩BC) P(AC∩BC) 189
No Expected P(A)*P(BC) P(AC)*P(BC)
Total 197 112 309
Creating Expected probabilities
• In the expected boxes we put the product of the corresponding
probabilities i.e. the row and column marginal probabilities
Vaccinated
Yes No Total
Yes 51 69 120
Influenza
Expected P(A)*P(B)*309 P(AC)*P(B) *309
No 146 43 189
Expected P(A)*P(BC) *309 P(AC)*P(BC) *309
Total 197 112 309
Creating Expected probabilities
• In the expected boxes we put the product of the corresponding
probabilities i.e. the row and column marginal probabilities
Vaccinated
Yes No Total
Yes 51 69 120
Influenza
Expected 76.50 P(AC)*P(B) *309
No 146 43 189
Expected P(A)*P(BC) *309 P(AC)*P(BC) *309
Total 197 112 309
Creating Expected probabilities
• In the expected boxes we put the product of the corresponding
probabilities i.e. the row and column marginal probabilities
Vaccinated
Yes No Total
Yes 51 69 120
Influenza
Expected 76.50 43.50
No 146 43 189
Expected P(A)*P(BC) *309 P(AC)*P(BC) *309
Total 197 112 309
Creating Expected probabilities
• In the expected boxes we put the product of the corresponding
probabilities i.e. the row and column marginal probabilities
Vaccinated
Yes No Total
Yes 51 69 120
Influenza
Expected 76.50 43.50
No 146 43 189
Expected 120.50 P(AC)*P(BC) *309
Total 197 112 309
Creating Expected probabilities
• In the expected boxes we put the product of the corresponding
probabilities i.e. the row and column marginal probabilities
Vaccinated
Yes No Total
Yes 51 69 120
Influenza
Expected 76.50 43.50
No 146 43 189
Expected 120.50 68.5
Total 197 112 309
Degrees of Freedom
• Notice that after we computed the first expected value ALL other
expected values are fixed in order for the summations to work out.
Vaccinated
Yes No Total
Yes 51 69 120
Influenza
Expected 76.50 43.50
No 146 43 189
Expected 120.50 68.5
Total 197 112 309
Degrees of Freedom
• This means that our problem has one “free computation” and all other
relevant to that. It has as we say one degree of freedom.
• In general, for contingency tables the degrees of freedom are given by:
DF=(number or rows-1)*(number of columns-1)
DF=(2-1)*(2-1)=1*1=1
Chi square Statistic
• A family of distributions based on a parameter k=DF with various
shapes:
Chi Square DF=1
Computing the Chi Square Number
• It is not so hard to show that each difference is going to follow a
normal distribution (if we assume that the two numbers are almost
equal).
• So, we are looking at the sum of squares of normal distributions,
which as we learned earlier leads to a chi square distribution!
Computing the Chi Square Number
• Since our p value is MUCH less than 0.05, we must reject the
null hypothesis. This implies that in this experiment,
vaccination and getting influenza are dependent variables.
Vaccines and Influenza
• We established that the two variables are dependent. Let see how:
Vaccines and Influenza
• It is obvious that vaccination lowers your chances of getting influenza
significantly (statistically) if you are a kid in this dataset.
• Similar results exist for ALL other ages groups.
• Similar results exist for many years (dating back to the 80’s)
Thus, the results CAN be generalized!
SAS code
data Vaccines;
input Influenza $ Vaccination $ count;
datalines;
yes yes 51
yes no 69
no yes 146
no no 43
;
proc freq data=Vaccines;
tables Influenza*Vaccination / chisq nocol norow nopercent expected;
weight count;
run;
SAS Output
SAS Output
Statistic DF Value Prob
Chi-Square 1 38.3525 <.0001
Likelihood Ratio Chi- 1 38.3298 <.0001
Square
Continuity Adj. Chi- 1 36.8635 <.0001
Square
Mantel-Haenszel Chi- 1 38.2284 <.0001
Square
Phi Coefficient -0.3523
Contingency Coefficient 0.3323
Cramer's V -0.3523
Various useful links
• An app that does tables on the fly
[Link]
• Using proc freq in SAS
[Link]
efault/[Link]#statug_freq_sect030.htm
Do Vaccines Cause Autism
NO!
[Link]
.org/content/articles/do-vacci
nes-cause-autism
Age at First Measles-Mumps-Rubella Vaccination in Children With Autism
and School-Matched Control Subjects: A Population-Based Study in
Metropolitan Atlanta
• A case-control study was conducted in metropolitan Atlanta.
Case children (N = 624) were identified from multiple
sources and matched to control children (N = 1824) on age,
gender, and school. Vaccination data were abstracted from
immunization forms required for school entry.
[Link]
rect_count=1&nfstatus=401&nftoken=00000000-0000-0000-0000-000000
000000&nfstatusdescription=ERROR:+No+local+token
Autism and Vaccines
Vaccinated
Yes No Total
Yes Observed 440 184
Yes Expected
Autism
No Observed 1240 584
No Expected
Total
SAS Output
Statistic DF Value Prob
Chi-Square 1 1.3827 0.2396
Likelihood Ratio Chi- 1 1.3931 0.2379
Square
Continuity Adj. Chi- 1 1.2676 0.2602
Square
Mantel-Haenszel Chi- 1 1.3821 0.2397
Square
Phi Coefficient 0.0238
Contingency Coefficient 0.0238
Cramer's V 0.0238
Autism and Vaccines
P value is 0.2396
• Fail to reject the null hypothesis. There is not enough evidence to
suggest that Autism and Vaccination are dependent variables in this
dataset.
• Follow the link below to find hundreds of similar tests:
[Link]
Again, it is SAFE to generalize this result!