Professional Documents
Culture Documents
Non Parametric Tests
Non Parametric Tests
Non Parametric Tests
Nonparametric Methods
If the assumptions such as normality or linearity are not satisfied and/or there are
extreme outliers, it is sometimes appropriate to use nonparametric methods, which
both do not involve statistical inference of parameters and also are distribution-free.
Most of the methods considered in this chapter involve the use of ranks. These
methods still require the important assumption of the independence of observations
though.
22.1 Ranks
We look at two nonparametric methods, both analogous to the two-sample t test, in
this section. One is the Wilcoxon rank-sum or Mann-Whitney statistic which is the
nonparametric version of the parametric (independent) two-sample t test. The other
is the Wilcoxon signed-rank test which is the nonparametric version of the (dependent)
paired t test.
213
214 Chapter 22. Nonparametric Methods (lecture notes 12)
Normal Q−Q Plot for Treatment Normal Q−Q Plot for Control
6
5
Sample Quantiles
Sample Quantiles
5
4
4
3
3
2
2
−1.0 −0.5 0.0 0.5 1.0 −1.0 −0.5 0.0 0.5 1.0
female 6 8 7 3 4 2 5 1
response 1.21 1.38 1.40 1.51 2.12 2.28 5.23 5.85
rank 1 2 3 4 5 6 7 8
female progesterone rank female control rank
1 5.85 8 5 5.23 7
2 2.28 6 6 1.21 1
3 1.51 4 7 1.40 3
4 2.12 5 8 1.38 2
sum Ttreat = 23 Tcontrol = 13
Calculate missing Ttreat and Tcontrol for other possible rankings:
female 1 2 3 4 Ttreat 5 6 7 8 Tcontrol
rank 1 2 3 4 10 5 6 7 8 26
rank 5 6 7 8 1 2 3 4 10
rank 1 6 3 8 18 5 2 7 4
rank 8 6 4 5 23 7 1 3 2 13
There are P8,4 = 1680 different rankings, all chosen at random.
In some / all cases,
Ttreat + Tcontrol = 1 + 2 + 3 + · · · + 7 + 8 = 9(8)
2
= 16 / 26 / 36,
so knowing one, the other is known, Ttreat = 36 − Tcontrol ,
so let’s use Tcontrol = 13.
Histogram of all.ranks
150
Frequency
100
50
0
10 15 20 25
all.ranks
female 5 6 7 2 3 4 1
response 1.40 1.40 1.40 1.50 1.50 5.23 5.85
rank 2 2 2 6 7
female progesterone rank female control rank
1 5.85 7 4 5.23 6
2 1.50 5 1.40 2
3 1.50 6 1.40 2
7 1.40 2
sum Ttreat = 16 Tcontrol = 12
There are P7,3 = 210 different rankings, all chosen at random.
In some / all cases,
Ttreat + Tcontrol = 1 + 2 + 3 + · · · + 7 = 8(7)
2
= 16 / 28 / 36,
choose T with smallest sample size, 3: Ttreat / Tcontrol .
so, chance observed Ttreat = 16 or less, if distributions are the same,
p-value = 0.03 / 0.10 / 0.13.
Level of significance α = (choose one) 0.01 / 0.05 / 0.10.
wilcox.test(treatment,control,alternative="greater") # p-value, use rank sum based on smallest sample size n
old (1) 6.22 8.11 5.44 5.76 4.87 5.46 9.33 9.45 8.34 6.23
8.14 5.43 8.98 8.27 7.66 9.34 10.99 10.22 8.88 7.77
6.66 5.55 7.89 8.94 6.02 6.81 8 9 7
new (2) 4.23 2.11 1.11 3 3.87 2.03 4.55 4.31 3.78 5.95
2.16 3.33 3.79 4.1 5.67 4.44 3.32 4.77 8.44
Section 1. Ranks (lecture notes 12) 219
−5.15 / 0 / 5.15
so p-value = 2 × P (Z < −5.15) ≈ 0.00 / 0.10 / 0.13
notice approximate and exact answers are different from one another, but both very very small
Level of significance α = 0.01 / 0.05 / 0.10.
wilcox.test(new,old,alternative="two.sided") # exact p-value, use rank sum based on smallest sample size n
2*pnorm(-5.15) # approximate p-value: 2 times P(Z < -5.15) because two-sided test
[1] 182
i. Statement.
If mean progesterone response, µ1 , is greater than average control re-
sponse, µ2 , µ1 > µ2 , difference in responses must be greater than zero,
µd = µ1 − µ2 > 0, so (circle one)
A. H0 : µd = 0 versus H1 : µd > 0
B. H0 : µd = 0 versus H1 : µd < 0
C. H0 : µd = 0 versus H1 : µd 6= 0
ii. Test.
Section 1. Ranks (lecture notes 12) 221
Paired t-test
ii. Test.
sum positive ranks: Ttreat > control = T + = 2 + 3 = 1 / 5 / 6,
sum negative ranks: = |Ttreat < control | = T − = | − 1| = 1 / 5 / 6,
ignore tied ranks: Ttreat = control so are / are not counted as zero,
test statistic (with smallest ranked sum): T − / T +
chance observed T − = 1 or less, if distributions are the same,
p-value = 0.03 / 0.13 / 0.21
level of significance α = 0.01 / 0.05 / 0.10.
wilcox.test(treatment,control,alternative="greater",paired=TRUE) # based on smallest signed-rank sum
(a) Statement.
i. H0 : µ1 = µ2 = µ3 vs H1 : µ1 6= µ2 , µ1 = µ3 .
ii. H0 : µ1 = µ2 = µ3 vs H1 : µ1 6= µ3 , µ1 6= µ2 .
iii. H0 : µ1 = µ2 = µ3 vs H1 : µi 6= µj , i 6= j; i, j = 1, 2, 3.
iv. H0 : means same vs H1 : at least one of the means different
(b) Test.
p–value = (circle one) 0.00 / 0.035 / 0.043.
summary(aov(response.A~drug.A))
(a) Statement.
i. H0 : at least one center different vs H1 : centers same
ii. H0 : µ1 = µ2 = µ3 vs H1 : µ1 6= µ3 , µ1 6= µ2 .
iii. H0 : centers same vs H1 : at least one center different
(b) Test.
since T1 = 15 / 40 / 65
and T2 = 15 / 40 / 65
and T3 = 15 / 40 / 65
tapply(combined.ranks,label.combined,sum) # sum ranks of separate treatments
12.5 / 15 / 17.3
so chance observed H =
calculated H here different H from R because R adjusted for ties
12.5 or more, if distributions the same,
p–value = P (H > 12.5) ≈ 0.001 / 0.035 / 0.043
226 Chapter 22. Nonparametric Methods (lecture notes 12)
[1] 5.991465
(a) Statement.
i. H0 : at least one center different vs H1 : centers same
Section 3. Kruskal-Wallace Test (lecture notes 12) 227
ii. H0 : µ1 = µ2 = µ3 vs H1 : µ1 6= µ3 , µ1 6= µ2 .
iii. H0 : centers same vs H1 : at least one center different
(b) Test.
since T1 = 7 / 11 / 12
and T2 = 7 / 11 / 12
and T3 = 7 / 11 / 12
and number of blocks b = 3 / 5
and number of treatments k = 3 / 5
test statistic
12
Ti2 − 3b(k + 1)
X
F =
bk(k + 1)
12
= T12 + T22 + T32 − 3b(k + 1)
bk(k + 1)
12
= 122 + 112 + 72 − 3(5)(3 + 1) =
3(5)(3 + 1)
data: drug
Friedman chi-squared = 2.8, df = 2, p-value = 0.2466
Level of significance α = 0.01 / 0.05 / 0.10.
(c) Conclusion.
Since p–value = 0.25 > α = 0.05,
do not reject / reject null H0 : means same
Data indicates
drug responses same
at least one of drug responses different
(d) Comments.
Parameter are / are not used in this analysis.
Normal distribution is / is not required assumption in analysis.
Random data is / is not required in this analysis.
upper critical value at 5% χ2k−1,α = χ23−1,0.05 = 5.99 / 6.99 / 7.99
qchisq(0.05,2,lower.tail=FALSE) # chi-square upper critical value at 5%
[1] 5.991465
228 Chapter 22. Nonparametric Methods (lecture notes 12)
and the other is Kendall’s Tau which looks at all pairwise points in a scatterplot and
compares the number discordant, nc (slopes between points are negative) and number
concordant, nc (slopes between points are positive) using the following formula,
nc − nd
τ= 1 .
2
n(n − 1)
In all three cases, −1 < rp < 1, −1 < rs < 1 and −1 < τ < 1, however, only
Pearson’s correlation measures linear association, whereas the other two measure
association alone. Pearson’s correlation is sensitive to outliers whereas the other two
are not.
600
100
200
550
180
95
500
160
90
Reading Ability
140
Pizza Sales
Grain Yield
450
85
120
400
80
100
350
75
80
300
60
70
2 4 6 8 10 0 50 100 150 5 10 15 20 25
par(mfrow=c(1,3))
plot(reading$brightness, reading$reading, pch=16,col="red",xlab="Brightness",ylab="Reading Ability")
plot( grain$distance, grain$yield,pch=16,col="red",ylab="Grain Yield",xlab="Distance from Water’s Edge")
plot(pizza$students, pizza$sales, pch=16,col="red",ylab="Pizza Sales",xlab="Number of Students")
par(mfrow=c(1,1))
[1] 0.7043218
[1] 0.5835893
[1] 0.4494666
(b) Grain yield versus distance from water
230 Chapter 22. Nonparametric Methods (lecture notes 12)
[1] -0.7851085
[1] -0.7907508
[1] -0.5889252
(c) Annual pizza sales versus student number
student number, x 2 6 8 8 12 16 20 20 22 26
pizza sales, y 58 105 88 118 117 137 157 169 149 202
Pearson correlation rp ≈ 0.796 / 0.920 / 0.950
Spearman correlation rs ≈ 0.796 / 0.920 / 0.950
Kendall’s tau r ≈ 0.796 / 0.920 / 0.950
So, in all three cases, association between reading ability and brightness is
negative / positive but it is strongest (closest to 1) for rp / rs / τ
cor(pizza$students,pizza$sales,method="pearson")
cor(pizza$students,pizza$sales,method="spearman")
cor(pizza$students,pizza$sales,method="kendall")
[1] 0.950123
[1] 0.9207488
[1] 0.7956601
brightness, x 1 2 3 4 5 6 7 8 9 10
rank(brightness) 1 2 3 4 5 6 7 8 9 10
reading ability, y 70 70 75 88 91 94 100 92 90 85
rank(ability) 1.5 1.5 3 5 7 9 10 8 6 4
Consider reading data. Scatterplot of ranks of data more / less able to fit a
line than data itself and so consequently rs = 0.584 < rp = 0.704. Spearman’s
correlation rs measures association / linear association.
# Import dataset "chapter22.reading.brightness.ranks"
reading.ranks <- chapter22.reading.brightness.ranks; attach(reading.ranks); head(reading.ranks)
reading <- chapter4.reading.brightness; attach(reading); head(reading)
Section 7. Spearman’s Rho (lecture notes 12) 231
95 100
10
Rank(Reading Ability)
8
Reading Ability
90
6
85
80
4
75
2
70
2 4 6 8 10 2 4 6 8 10
Brightness Rank(Brightness)
par(mfrow=c(1,2))
plot(reading$brightness, reading$reading, pch=16,col="red",xlab="Brightness",ylab="Reading Ability")
plot(reading.ranks$rank.brightness, reading.ranks$rank.reading, pch=16,col="red",xlab="Rank(Brightness)",ylab="Rank(Readi
par(mfrow=c(1,1))
3. Kendall’s tau.
brightness, x 1 2 3 4 5 6 7 8 9 10
reading ability, y 70 70 75 88 91 94 100 92 90 85
100
d
95
d d
Reading Ability
d
90
d
d
85
c
c
80
75
70
2 4 6 8 10
Brightness