Chapter12 - Chi Square Tests and Nonparametric
Statistics for Managers Using Microsoft® Excel 5th Edition
Chapter 12 Chi Square Tests and Nonparametric Tests
Learning Objectives In this chapter, you learn:
How and when to use the chi-square test for
contingency tables How to use the Marascuilo procedure for determining pair-wise differences when evaluating more than two proportions
How and when to use the McNemar test
How and when to use nonparametric tests
Contingency Tables Contingency Tables
Useful in situations involving multiple population proportions
Used to classify sample observations according to two or more characteristics
Also called a cross-classification table.
Contingency Table Example Hand Preference vs. Gender Dominant Hand: Left vs. Right Gender: Male vs. Female
2 categories for each variable, so the table is called a 2 x 2 table
Suppose we examine a sample of 300 college students
Contingency Table Example Sample results organized in a contingency table:
Hand Preference Gender Female Male
Left
12
24
36 Right 108 156 264 120 180 300 120 Females, 12 were left handed 180 Males, 24 were left handed sample size = n = 300:
Contingency Table Example
If H is true, then the proportion of left-handed females should be the same as the proportion of left-handed males.
The two proportions above should be the same as the proportion of left-handed people overall.
H : π 1 = π 2 (Proportion of females who are left handed is equal to the proportion of males who are left handed) H 1 : π 1 ≠ π 2 (The two proportions are not the same – Hand preference is not independent of gender)
The Chi-Square Test Statistic where: f o = observed frequency in a particular cell f e = expected frequency in a particular cell if H is true 2 for the 2 x 2 case has 1 degree of freedom
cells all
e
2 e o
2 f ) f (f
χ The Chi-square test statistic is:
Assumed: each cell in the contingency table has expected frequency of at least 5
The Chi-Square Test Statistic
2
test statistic approximately follows a chi-square The distribution with one degree of freedom
Decision Rule: 2 2 , reject H ,
If > U otherwise, do not reject
H Do not Reject H reject H 2
U Computing the Average Proportion
Here: 120 Females, 12 were left handed 180 Males, 24 were left handed
The proportion of left handers overall is 0.12, that is, 12% n
X n n
X X p
2
1
2
1 12 .
300
36 180 120
24
12 p
The average proportion is: Finding Expected Frequencies
To obtain the expected frequency for left handed females,
multiply the average proportion left handed (p) by the total number of females To obtain the expected frequency for left handed males,
multiply the average proportion left handed (p) by the total number of males
If the two proportions are equal, then P(Left Handed | Female) = P(Left Handed | Male) = .12 i.e., we would expect (.12)(120) = 14.4 females to be left handed (.12)(180) = 21.6 males to be left handed
Observed vs. Expected Frequencies
Hand Preference
Gender Female Male
Left Observed = 12
Expected = 14.4 Observed = 24
Expected = 21.6
36 Right Observed = 108
Expected = 105.6 Observed = 156
Expected = 158.4 264 120 180 300 The Chi-Square Test Statistic Gender Hand
Female Male Preference Observed = 12 Observed = 24 Left
36 Expected = 14.4 Expected = 21.6 Observed = 108 Observed = 156 Right
264 Expected = 105.6 Expected = 158.4 The test statistic is: 2 120 180 300 2 ( f f ) o e
all cells f 2 e 2 2 2
(
12 14 . 4 ) ( 108 105 . 6 ) (
24 21 . 6 ) ( 156 158 . 4 ) . 7576
14 . 4 105 .
6 21 . 6 158 .
4 The Chi-Square Test Statistic
2
2 The test statistic is . 7576 , with 1 d.f. 3.841
U Decision Rule: 2 > 3.841, reject H , otherwise, do
If
not reject H Here, 2 2 = 3.841,=.05 = 0..7576 < U so you do not reject H and Do not Reject H
conclude that there is reject H 2 insufficient evidence that the =3.841 U two proportions are different.
2 Test for The Differences Among
More Than Two Proportions
Extend the
2 test to the case with more than two independent populations:
H : π 1 = π 2 = … = π c H 1 : Not all of the π j are equal (j = 1, 2, …, c)
The Chi-Square Test Statistic The Chi-square test statistic is:
2 ( f f )
2 o e
f all cells e where: o f = observed frequency in a particular cell of the 2 x c table
e f = expected frequency in a particular cell if H is true
2 for the 2 x c case has (2-1)(c-1) = c - 1 degrees of freedom
Assumed: each cell in the contingency table has expected frequency of at
least 1Computing the Overall Proportion
X
X ...X X
The overall
1 2 c p
proportion is: n n ... n n
1 2 c Expected cell frequencies for the c categories are
calculated as in the 2 x 2 case, and the decision rule
is the same: 2 Decision Rule:is from the 2 2 Where U , reject H ,
If > U chi-square distribution otherwise, do not with c – 1 degrees of reject H freedom
2 Test with More Than Two
Proportions: Example The sharing of patient records is a
controversial issue in health care. A survey
of 500 respondents asked whether they objected to their records being shared byinsurance companies, by pharmacies, and by
medical researchers. The results are summarized on the following table:2 Test with More Than Two
Proportions: Example
Organization Object to
Insurance Pharmacies Medical Record
Companies Researchers Sharing Yes 410 295 335 No 90 205 165
2 Test with More Than Two
Proportions: Example 6933 .
500 500 500 410 335 295
...
...
2 1 2 1
c c n n n
X X
X p The overall proportion is:
Object to Record Sharing Organization
Insurance Companies Pharmacies Medical Researchers
Yes f o = 410 f e = 346.667 f o = 295 f e = 346.667 f o = 335 f e = 346.667 No f o = 90 f e = 153.333 f o = 205 f e = 153.333 f o = 165 f e = 153.333
2 Test with More Than Two
Proportions: Example Organization Object Insurance Pharmacies Medical to Companies
Researchers Record Sharing 2 2 2 f f
o e f f f f
o e o e 11 . 571 7 . 700 . 3926 f e f f e e
Yes 2 2 2 f f f f
o e o e
f f o e
17 . 409 . 888 26 . 159 f f f e e e
No 2 2 ( f f ) o e 64 . 1196
The Chi-square test statistic is: all cells f e
2 Test with More Than Two
Proportions: Example H : π = π = π 1 2 3 H : Not all of the π are equal (j = 1, 2, 3) 1 j 2 Decision Rule:
= 5.991 is from the chi- 2 2 U , reject H ,
If > U square distribution with 2 otherwise, do not reject H degrees of freedom.
Conclusion: Since 64.1196 > 5.991, you reject H and you conclude that at least one proportion of respondents who object to their records being shared is different across the three organizations j’ among all c(c-1)/2 pairs.
Second, compute the corresponding critical range for the Marascuilo procedure.
The Marascuilo Procedure The Marascuilo procedure enables you to make comparisons between all pairs of groups. First, compute the observed differences p j
- p
The Marascuilo Procedure
p / ( 1 p / ) p ( 1 p ) 2 j j j j Critical Range
Critical Range for the Marascuilo Procedure:
U n n / j j The Marascuilo Procedure Compute a different critical range for each
pair-wise comparison of sample proportions.
Compare each of the c(c - 1)/2 pairs of
sample proportions against its corresponding
critical range.Declare a specific pair significantly different
if the absolute difference in the sample
proportions |p – p | is greater than its critical
j j’ range.The Marascuilo Procedure Example
Organization Object to
Insurance Pharmacies Medical Record
Companies Researchers Sharing Yes 410 295 335
P = 0.82 P = 0.59 P = 0.67 1 2 3 No 90 205 165 The Marascuilo Procedure Example
MARASCUILO TABLE
AbsoluteProportions Differences Critical Range | Group 1 - Group 2 |
0.23 0.06831808 | Group 1 - Group 3 | 0.15 0.0664689 | Group 2 - Group 3 | 0.08 0.074485617
Conclusion: Since each absolute difference is greater than the critical range, you conclude that each proportion is significantly different that the other two.
Similar to the
2 Test of Independence
2 test for equality of more than two proportions, but extends the concept to contingency tables with r rows and c columns
H : The two categorical variables are independent (i.e., there is no relationship between them) H : The two categorical variables are dependent
1 (i.e., there is a relationship between them)
The Chi-square test statistic is:
2 Test of Independence
2 ( f f )
2 o e
f all cells e where:
f = observed frequency in a particular cell of the r x c table o f = expected frequency in a particular cell if H is true e
2 for the r x c case has (r-1)(c-1) degrees of freedom
Assumed: each cell in the contingency table has expected frequency of at least 1)
Expected Cell Frequencies Expected cell frequencies:
row total column tot al
f e
n
Where: row total = sum of all frequencies in the row column total = sum of all frequencies in the column n = overall sample size
Decision Rule
The decision rule is
If 2 > 2 U , reject H , otherwise, do not reject H
Where 2 U is from the chi-square distribution with (r – 1)(c – 1) degrees of freedom
Example: Test of Independence
10
70
40 Total
10
16
14
30 Senior
6
14
60 Junior
The meal plan selected by 200 students is shown below: Class
12
26
22
70 Soph.
14
32
24
Total 20/week 10/week none Fresh.
Standing Number of meals per week
88 42 200 Example: Test of Independence The hypothesis to be tested is:
H : Meal plan and class standing are independent (i.e., there is no relationship between them) H : Meal plan and class standing are dependent
1 (i.e., there is a relationship between them)
Example: Test of Independence
Class
Standing
14.0
n
30 al column tot x total row f e
70
10 200
5 .
Expected cell frequencies if H is true:
88 42 200
70
40 Total
8.4
17.6
30 Senior
Number of meals per week Total 20/wk 10/wk none
6.3
13.2
10.5
60 Junior
12.6
26.4
21.0
70 Soph.
14.7
30.8
24.5
Fresh.
Example for one cell:
Example: Test of Independence The test statistic value is: 2
( f f ) 2 o e
all cells f e 2 2 2 (
24 24 . 5 ) (
32 30 . 8 ) (
10 8 . 4 ) . 709
24 .
5 30 .
8 8 .
4
2
= 12.592 for α = .05 from the chi-square U distribution with (4 – 1)(3 – 1) = 6 degrees of freedom
Example: Test of Independence
2
2 The test statistic is . 709 , with 6 d.f. 12.592
U
Decision Rule: 2 > 12.592, reject H , otherwise,
If do not reject H
Here, 2 2 = 12.592, = 0.709 < U
=0.05 so do not reject H Do not Reject H
Conclusion: there is reject H 2 insufficient evidence that meal plan and class standing are
=12.592 U related. McNemar Test Used to test for the difference between two
proportions of related samples (not independent) You need to use a test statistic that follows
the normal distribution
McNemar Test Contingency Table Condition (Group) 1 Condition (Group) 2
Yes No Totals Yes A B A+B No C D C+D Totals A+C B+D n
Where A = number of respondents who answered yes to condition 1 and condition 2 B = number of respondents who answered yes to condition 1 and no to 2 C = number of respondents who answered no to condition 1 and yes to 2 D = number of respondents who answered no to condition 1 and condition 2 n = number of respondents in the sample
McNemar Test Contingency Table Condition (Group) 2 Condition (Group) 1 Yes No Totals Yes A B A+B
No C D C+D Totals A+C B+D n
The sample proportions are:
A B A C p p
1
2 n n McNemar Test Contingency Table Condition (Group) 2 Condition (Group) 1 Yes No Totals Yes A B A+B
No C D C+D Totals A+C B+D n
The population proportions are: π = proportion of the population who answer yes to condition 1 1
π = proportion of the population who answer yes to condition 2 2
McNemar Test Test Statistic To test the hypothesis: H : π = π
1
2 H : π ≠ π
1
1
2 Use the test statistic: B C
Z
B C
McNemar Test Example Suppose you survey 300 homeowners and ask
them if they are interested in refinancing their home. In an effort to generate business, a
mortgage company improved their loan terms and
reduced closing costs. The same homeowners were again surveyed. Determine if change in loanterms was effective in generating business for the
mortgage company. The data are summarized as
follows:McNemar Test Example Survey response after change Survey response Yes No Totals before change
Yes 118 2 120 No 22 158 180 Totals 140 160 300
Test the hypothesis (at the 0.05 level of significance): H : π ≥ π : The change in loan terms was ineffective 1 2 H : π < π : The change in loan terms increased business 1 1 2
McNemar Test Example Survey response after
The critical value (.05
change Survey
significance) is Z = -1.96
response Yes No Totals before change
The test statistic is:
B C
2
22 Z 4 .
08 Yes 118 2 120 B C
2
22 No 22 158 180 Totals 140 160 300
Since Z = -4.08 < -1.96, you reject H and conclude that the change in loan terms significantly increase business for the mortgage company.
Wilcoxon Rank-Sum Test Test two independent population medians
Populations need not be normally distributed
Distribution free procedure
Used when only rank data are available
Wilcoxon Rank-Sum Test
Can use when both n 1 , n 2 ≤ 10
Assign ranks to the combined n 1 + n 2 sample values
If unequal sample sizes, let n 1 refer to smaller-sized sample
Smallest value rank = 1, largest value rank = n 1 + n 2
Assign average rank for ties
Sum the ranks for each sample: T 1 and T 2
Obtain test statistic, T 1 (from smaller sample)
Checking the Rankings The sum of the rankings must satisfy the formula
below Can use this to verify the sums T and T
1
2 n(n 1)
T T
1
2
2
where n = n + n 1 2
Wilcoxon Rank-Sum Test
Hypothesis and Decision
H : M 1 = M 2 H 1 : M 1 ≠ M 2 H : M 1 ≤ M 2 H 1 : M 1 > M 2 H : M 1 ≥ M 2 H 1 : M 1 < M 2 Two-Tail Test Left-Tail Test Right-Tail Test M 1 = median of population 1; M 2 = median of population 2
Reject
T 1L T 1U
Reject Do Not Reject Reject
T 1L
Do Not Reject
T 1U
Reject Do Not Reject
Test statistic = T 1 (Sum of ranks from smaller sample)
Reject H if T 1 ≤ T 1L or if T 1 ≥ T 1U Reject H if T 1 ≤ T 1L Reject H if T 1 ≥ T 1U
Wilcoxon Rank-Sum Test Example with Small Samples
Sample data are collected on the capacity rates (% of capacity) for two factories.
Are the median operating rates for two factories the same?
For factory A, the rates are 71, 82, 77, 94, 88
For factory B, the rates are 85, 82, 92, 97
Test for equality of the population medians at the 0.05 significance level
Wilcoxon Rank-Sum Test Example with Small Samples Capacity Rank
Ranked
Factory A Factory B Factory A Factory B
Capacity
71
1
values: rd
77
2
82
3.5 Tie in 3 and th
82
3.5
4 places
85
5
88
6
92
7
94
8
97
9 Rank Sums:
20.5
24.5 Wilcoxon Rank-Sum Test Example with Small Samples Factory B has the smaller sample size, so the test statistic is the sum of the Factory B ranks:
T = 24.5
1 The sample sizes are:
n = 4 (factory B) 1 n = 5 (factory A) 2 The level of significance is α = .05
Wilcoxon Rank-Sum Test
Example with Small Samples n 1 Lower and n 2 One- Two-
Upper Critical
4
5 Values for T Tailed Tailed 1 from
4 Appendix
Table E.8:
.05 .10 12, 28 19, 36 .025 .05 11, 29 17, 38
5 T = 11 and 1L .01 .02 10, 30 16, 39
T = 29 1U
.005 .01 --, -- 15, 40
6 Wilcoxon Rank-Sum Test Example with Small Samples
= .05
Test Statistic (Sum of ranks 1 2 = 5
n = 4 , n
from smaller sample):
Two-Tail Test T = 24.5 1 H : M = M 1 2 H : M ≠ M 1 1 2 Decision:
Do not reject at a = 0.05 Do Not Reject Reject
Reject Conclusion: T =11 T =29 1L 1U
There is not enough evidence to prove
Reject H if T ≤ T = 11 1 1L that the medians are not equal. or if T ≥ T = 29 1 1U
Wilcoxon Rank-Sum Test
Using Normal Approximation For large samples, the test statistic T 1
is approximately normal
with mean and standard deviation:
1 T
Must use the normal approximation if either n 1 or n 2 > 10
Assign n 1 to be the smaller of the two sample sizes
Can use the normal approximation for small samples
2 ) ( 1 n n μ
1
12 ) ( 1 n n n σ
2
1 T 1 Wilcoxon Rank-Sum Test Using Normal Approximation The Z test statistic is
μ T
1 T
1 Z σT 1
Where Z approximately follows a standardized
normal distributionWilcoxon Rank-Sum Test Using Normal Approximation Use the setting of the prior example:
The sample sizes were: n 1 = 4 (factory B) n 2 = 5 (factory A) The level of significance was α = .05
The test statistic was T
1 = 24.5 Wilcoxon Rank-Sum Test Using Normal Approximation n ( n 1 ) 4 (
9 1 ) 1 μ
20 T
1
2
2 n n ( n 1 ) 4 ( 5 ) (
9 1 ) 1 2 σ 4 . 082 T 1
12
12
The test statistic is T μ
5
20
1 T
24 .
1 Z 1 .
10 σ 4.082
T 1 Z = 1.10 is less than the critical Z value of 1.96 (for α = .05)
so you do not reject H – there is not sufficient evidence that the medians are not equal
Kruskal-Wallis Rank Test
Tests the equality of more than 2 population medians
Use when the normality assumption for one-way ANOVA is violated
Assumptions:
The samples are random and independent
variables have a continuous distribution
the data can be ranked
populations have the same variability
populations have the same shape Kruskal-Wallis Rank Test
Obtain overall rankings for each value
In event of tie, each of the tied values gets the average rank
Sum the rankings for data from each of the c groups
Compute the H test statistic Kruskal-Wallis Rank Test
The Kruskal-Wallis H test statistic: (with c – 1 degrees of freedom)
) 1 ( 3 )
1 (
12
1
2
n n
T n n H c j
j
j where: n = total number of values over the combined samples c = Number of groups T j = Sum of ranks in the j th sample n j = Size of the j th sample Kruskal-Wallis Rank Test
Complete the test by comparing the calculated H value 2 value from the chi-square distribution to a critical with c – 1 degrees of freedom
Decision rule
Reject H
Otherwise do not reject H
2U if test statistic H >
reject H Do not Reject H 2 U Kruskal-Wallis Rank Test Example
Do different branch offices have a different number of employees?
72
34
18
40
30
70
45
60
Office size (Chicago, C) Office size (Denver, D)
55
66
78
54
41
23
Office size (Houston, H)
44 Kruskal-Wallis Rank Test Example
Do different branch offices have a different number of employees?
70
4
1
5
3
44
34
18
40
30
13
8
14
11
10
45
Office size (Chicago, C) Ranking Office size
66
(Denver, D) Ranking Class size (Houston, H)
Ranking
23
41
54
78
2
72
6
9
15
12
55
60
7 = 44 = 56 = 20 Kruskal-Wallis Rank Test Example
The H statistic is 72 .
A H D C
Medians equal are population all Not : H Median Median Median : H
T n n H c j j j
n n
2 2 2 1 2
6 )
12
3 ) 1 (
12 ) 1 (
15
1 15 (
44 )
5
56
5
20
5
3
1 15 (
Kruskal-Wallis Rank Test Example
Compare H = 6.72 to the critical value from the chi-square
distribution for 3 – 1 = 2 degrees of freedom and = .05:
2 χ 5.991
U 2
χ 5.991 U
Since H = 6.72 > , reject H There is evidence of a difference in the population median number of employees in the branch offices Chapter Summary
In this chapter, we have 2
two proportions 2 test for differences in more than Developed and applied the
test for the difference between Developed and applied the
two proportions 2
test for independence Examined the Used the McNemar test for differences in two related
proportions
Used the Wilcoxon rank sum test for two population medians
Small Samples
Large sample Z approximation
Applied the Kruskal-Wallis H-test for multiple population
medians