2. χ2 test definition
• χ2 test is commonly used for testing relationships between categorical
(nominal or non-numerical) data such as Gender {Men, Women} or
color {Red, Yellow, Green, Blue} etc, but not numerical data such as
height or weight.
• It compares the counts of categorical responses between two (or more)
independent groups. (note: Chi square tests can only be used on actual
numbers and not on percentages, proportions, means, etc.)
• The null hypothesis (H0) of the Chi-Square test is that no relationship
exists on the categorical (nominal or non-numerical) variables in the
population.
• The technique involves working out the frequency that would be
expected if the null hypothesis were true.
• The expected frequency is then compared to the observed frequency
3. χ2 test
Formula is :
1. For each observed (o) number in the table subtract the
corresponding expected (E) number (O — E).
2. Square the difference [ (O —E)2 ].
3. Divide the squares obtained for each cell in the table by
the expected number for that cell [ (O - E)2 / E ].
4. Sum all the values for (O - E)2 / E. This is the chi square statistic.
5. Evaluate the degrees of freedom (number of categories minus one)
6. Tally the χ2 value with the tabulated value (present at the end of
books) at the evaluated degrees of freedom
4. Example-data in one row
• Three traps have been designed to trap birds (A,B,C)
• Number of birds trapped (observed frequencies) by each
design are compared
• First step is to formulate a null hypothesis (Ho) =there is no
association between number of birds trapped and trap design
• If there is no association between number of birds trapped
and trap design, all the three types of traps will capture equal
number of birds
5. Example-contd.
Design A Design B Design C
Observed
frequencies
10 27 15
Expected
frequencies
17.33 =
(10+27+15)/3
17.33 17.33
(10-17.33)2/17.33
=3.10
(27-17.33)2/17.33
=5.40
(15-17.33)2/17.33
=0.313
=3.10+5.40+0.313 =8.813
•The degrees of freedom in this case is 3-1=2
•The χ2 value of 8.813 at 2 degrees of freedom is greater than the
tabulated value 5.99 at 0.05 level of significance (see next slide)
•It is concluded that there is association between trap design and
number of birds trapped
•Thus null hypothesis (H0) is rejected.
7. Example-data in two rows
• Suppose a drug trial was conducted on a group of animals and
it washypothesized that the animals receiving the drug would
show increased heart rates compared to those that did not
receive the drug.
• Ho (null hypothesis): The proportion of animals whose heart
rate increased is independent of drug treatment.
8. Heart Rate
Increased
No increase in heart
rate
total
Treated Observed=36
Expected =66X50/105
= 31.42
χ2=(36-31.42)2/31.42
= 0.66
Observed =14
Expected =39X50/105
=18.57
χ2=(14-18.57) 2/18.57
= 1.12
50
Not-treated Observed=30
Expected =66X55/105
= 34.57
χ2=(30-34.57) 2/34.57
=0.60
Observed=25
Expected =39X55/105
= 20.42
Χ2=(25-20.42) 2/20.42
= 1.02
55
Total 66 39 105
•χ2= 0.66+1.12+0.60+1.02 = 3.4
•Degrees of freedom = (columns-1)(rows-1) = (2-1)(2-1) =1
•The χ2 value of 3.4 at 1 degrees of freedom is less than the tabulated value 3.84
at 0.05 level of significance
•Therefore, the null hypothesis cannot be rejected
9. Uses of Chi-square test
• (a) To test the hypothesis of no association between two or
more groups, population or criteria (i.e. to check
independence between two variables);
• (b) and to test how likely the observed distribution of data fits
with the distribution that is expected (i.e., to test the
goodness-of-fit).
• It is used to analyze categorical data (e.g. male or female
patients, smokers and non-smokers, etc.),
• it is not meant to analyze parametric or continuous data (e.g.,
height measured in centimeters or weight measured in kg,
etc.).