Professional Documents
Culture Documents
Two-Sample Methods
1
Main Topics
2.1-2.3 Two-Sample Permutation Tests
2.4 Wilcoxon Rank Sum Test
2.5 Wilcoxon Rank Sum Test Adjusted for Ties
2.6 The Mann-Whitney Statistic and
Confidence Limits for the Shift Parameter
2.7 Scoring Systems
2.8 Other Nonparametric Tests
2
2.1-2.3 Two-Sample Permutation Tests
Populations and Samples:
Sample
Population Cdf Size Sample
#1 F1 ( x ) m X1 , X 2 , . . . , X m
#2 F2 ( x ) n Y1 , Y2 , . . . , Y n
Assumptions:
(1) Both samples are random samples from the
respective populations.
(2) The samples are selected independently
3
Hypotheses
Let X have cdf F1 ( x). Let Y have cdf F2 ( x).
Hypothesis Equivalent Statement
ST
H 0 : F1 ( x) = F2 ( x) X = Y
ST
H A : F1 ( x) F2 ( x) X Y
ST
H A : F1 ( x) F2 ( x) X Y
ST ST
H A : F1 ( x) F2 ( x) X Y or X Y
or F1 ( x) F2 ( x)
(1) The null hypothesis states that the distns. are identical,
not just that the two population means are equal.
(2) A 2-sided alternative is not equivalent to F1 ( x) F2 ( x)
4
Summary of Steps Used in a Two-Sample
Permutation Test
1. Randomly assign the experimental units to the 2
treatment groups, m to group #1 and n to group #2.
2. Calculate the observed , D obs , difference, D,
of two sample means.
3. Permute the N = m + n observations between
the two treatments so there are m observ. on
treatment 1 and n on treatment 2. The number
N
of possible permutations is k = . (Cont.)
n
5
Summary (Continued)
4. For each permutation of the data, calculate
the value of the test statistic (e. g., the
difference, D, of the sample means)
5. For an upper-tail test, calclulate
p-value = (number of D's D obs ) / k
6. For a two-sided test, if D obs falls in upper tail,
then p-value = 2(number of D's D obs ) / k
7. Reject H 0 if p-value specified
6
Ex 1. To compare two different methods
of instruction, 4 of 7 employees are
randomly assigned to a new method and
the other 3 to a standard method.
Method Test Scores
(1) New 37, 49, 55, 57
(2)Standard 23, 31, 46
7
Ex 1 (Continued)
Use a permutation test to test the hypothesis
that the new and standard methods do not
differ in the distn. of test scores versus the
one-sided alternative that the new method
gives higher test scores than the standard
method.
8
Solution to Ex 1
If there is no difference between the two methods,
then all outcomes obtained by randomly assigning
4 scores to one method and 3 scores to the other
method are equally likely.
The number of ways of assigning 4 of the 7 data values
7
to one method and 3 to the other method is = 35
4
To calculate the p-value for the permutation test, we
list all possible outcomes and count the number of
outcomes for which X - Y 16.2
9
Solution to Ex 1 (Continued)
A = new method B = standard method
S = sum of new-method scores
Outcome 23 31 37 46 49 55 57 X -Y S
1 B B B A A A A 21.4 207
2 B B A B A A A 16.2 198
3 B B A A B A A 14.4 195
4 B B A A A B A 10.9 189
.
.
34 A A A B A B B -17.7 140
35 A A A A B B B -19.4 137 10
Solution to Ex 1 (Continued)
2
p-value = PH 0 ( X - Y 16.2) = = 0.057
35
T he result is not significant at the 5% level.
2
p -valu e = PH 0 ( D 2 1 ) = = 0 .0 57 1
35
mn 2
E H0 ( S ) = m VarH 0 (S) =
(N - 1)
19
Ex 3 Same Situation as Ex 1
Method Test Scores
(1) New 37, 49, 55, 57
(2) Standard 23, 31, 46
Use the normal approximation and a
permutation test to test the null hypothesis that
the new and standard method scores have
identical distns. vs. the one-sided alternative
that the new method scores tend to have higher
values.
20
Note Concerning the Normal Approx.
• To illustrate the use of the normal approx. we
will often use it when the sample sizes are
small. The approximation may then not give a
p-value close to the true value.
• In problems of practical interest, the sample sizes
are usually large enough so that the normal
approximation is fairly accurate.
• For moderate size samples SAS can be used to
estimate the p-values by random sampling the
permutations, as we will discuss later.
21
Solution to Ex 3
S = sum of new m ethod observations
S obs = 37 + 49 + 55 + 57 = 198
C om bined set: 23, 31, 37, 46, 49, 55, 57
m =4 n=3 N =7
Z / N = 42.57
N
= 1 i
2
= Z - / N = 137.67
N
2
1 i
E H 0 ( S ) = m = 4(42.57) = 170.28
m n 2 4(3)137.67
V arH 0 ( S ) = = = 275.34
N -1 6
22
Solution to Ex 3 (Continued)
Using the normal approx. without a continuity
correction,
198 - 170.28
p-value = PH 0 ( S 198) = P Z
275.34
P( Z 1.67) = 0.0475
Continued
26
Soln to Ex 4 (Cont.): SAS Output
Data Scores Two-Sample Test
Statistic (S) 100.0000
(S =sum of scores in smaller sample)
Normal Approximation
Z -1.6702
One-Sided Pr < Z 0.0474
Two-Sided Pr > |Z| 0.0949
(approx. p-values)
27
Soln to Ex 4 (Cont.): SAS Output
Exact Test
One-Sided Pr <= S 0.0571
Two-Sided Pr >= |S - Mean| 0.1143
(exact p-values)
Data Scores One-Way Analysis
Chi-Square 2.7895
DF 1
Pr > Chi-Square 0.0949
28
Random Sampling the Permutations
If n = m = 8, then the total number of possible
permutaions is
16
= 1 2 ,8 7 0
8
Calculating p-values by listing all possible
permutations is not feasible even for moderate
size samples.
29
Ex 5. Use SAS to Estimate the P-Value by
Random Sampling the Permutations
30
Soln to Ex 5: The SAS Program
data d1;
input treatment $ time @@;
datalines;
A 19 A 22 A 25 A 26 A 28 A 29 A 34 A 37 A 38
B 20 B 21 B 24 B 30 B 32 B 36 B 40 B 48 B 54
;
proc npar1way data=d1 scores=data;
class treatment;
exact scores=data/n=1000;
var time;
run; quit;
31
Soln to Ex5: The SAS Output
The NPAR1WAY Procedure
Data Scores for Variable time
Classified by Variable treatment
Sum of Expected Std Dev Mean
treatment N Scores Under H0 Under H0 Score
34
Layout:
Sample
Population Cdf Size Sample
#1 F1 ( x) m X1 , X 2 , . . . , X m
#2 F2 ( x) n Y1 , Y2 , . . . , Yn
Assumptions:
(1) Both samples are random samples from the
respective populations.
(2) The samples are selected independently
(3) No tied values
35
Summary of Steps in the Rank Sum Test
(1) Form the combined ordered set of N = m + n
observations and rank them 1 - N:
Ordered Values: Z1 Z2 Z3 . . . ZN
Ranks: 1 2 3 . . . N
(2) Identify the sample values from treatment #1.
Calulate: W = sum of ranks of the observ. in group #1
(3) Find all possible permutations of the ranks in
which m are assigned to group #1 and n to group #2.
N
(4) Upper tail test p-value = # W wobs /
m
36
Ex 6 Weight Loss Data
Diet Weight Loss (pounds)
A 7.9 8.3 9.0
B 5.1 5.7 6.5 8.1
Use the Wilcoxon rank sum test to test the null
hypothesis of identical weight loss distributions
versus the one-sided alternative that weight
loss with diet A tends to be larger than weight
loss with diet B.
37
Solution to Ex 6
38
Solution to Ex 6 (Continued)
H 0 : The weight loss distns. are identical
H A : Diet A wt. loss scores tend to be larger than
diet B wt. loss scores
Test Statistic: W = sum of ranks of diet A scores
Reject H 0 if W c
Conclusion: Wobs = 17
2
p-value=P(W 17) = = 0.057; (next page)
35
Do not reject at the 5% level.
39
Soln to Ex 6: All Possible Permutations
W = s u m o f ra n k s a llo c a te d to d ie t A
O u tc o m e 1 2 3 4 5 6 7 W
1 B B B B A A A 18
2 B B B A B A A 17
3 B B A B B A A 16
4 B B B A A B A 16
.
.
34 A A B A B B B 7
35 A A A B B B B 6
40
Null Distribution of W: (m = 3, n = 4)
w 6 7 8 9 10 11 12
1 1 2 3 4 4 5
f(w )
35 35 35 35 35 35 35
w 13 14 15 16 17 18
4 4 3 2 1 1
f(w )
35 35 35 35 35 35
N o te s :
(1 ) T h e n u ll d is tn o f W is s y m m e tric
(2 ) E (W ) = c e n te r o f s y m m e try = 1 2
41
Properties of the Rank Sum Statistic
m
(1) The smallest value that W1 = 1
R(X i ) can
take is 1 + 2 + . . . + m = m(m + 1)/2
(2) The null distn. of W1 is symmetric w ith mean
E H 0 (W1 ) = m(N + 1)/2
n
(3) The smallest value tha t W2 = 1
R(Yi ) can
take is 1 + 2 + . . . n = n(n + 1)/2
(4) W1 + W2 = 1 + 2 + . . . + N = N(N + 1)/2
(5) The null distn. of W 2 is also symmetric with
mean E H 0 (W 2 ) = n(N + 1 )/2
42
Exact Null Distn When n = m = 5
w 15 16 17 18 19 20 . . .
1 1 2 3 5 7
p(w) ...
252 252 252 252 252 252
12
PH 0 ( W 19) = = 0.0476
252
19
PH 0 (W 20) = = 0.0754
252
W hat should be the rejection re gion for a
5% level lower tailed test?
43
Table A3: Critical Values for the Wilcoxon
Rank Sum Test
• Table A3 gives critical values for W = sum of
ranks of observations in a sample of the size
given at the top of the table.
• The table gives upper and lower tail critical
values for one-sided tests with significance
levels 5%, 2.5%, 1% and n, m = 1 – 10.
• The tabled values are the ones closest to the
stated significance level without going over.
44
Ex 7 Use of Table A3
Suppose n = m = 5. Let W = sum of ranks of the
observations in the sample of n = 5.
(a) Use Table A3 to determine the rejection
region for a lower tailed test with significance
level 0.05.
(b) Use the exact null distribution discussed
earlier to determine the actual significance
level of the test in part (a).
45
Soln to Ex 7
46
Ex 8. Use of Table A3
Suppose m = 7 and n = 9. Let
W = sum of ranks of observations in the sample
of size n = 7.
Use table A3 to determine the rejection region
in the following cases:
(a) Upper tail test, = 0.05.
(b) Lower tail test, = 0.05.
(c) Two-sided test, = 0.10.
(d) Two-sided test, = 0.05.
47
Null Mean and Variance of the Wilcoxon Rank Sum Statistic
m n 2 m n (N 2 - 1 )/1 2
V a rH 0 (W ) = =
N - 1 (N - 1 )
m n (N + 1 )
=
12
F o r n a n d m la rg e , th e C L T W h a s a p p ro x .
a n o rm a l d is trib u tio n w ith th e a b o v e m e a n
a n d v a ria n c e .
49
Ex 9: Accuracy of the Normal Approx.
50
Ex 9. Continued
Recall for n = m = 5, the exact null distribution
gives PH0 ( W 19) = 0.0476.
Normal approx. and continuity correction
19.5 - 27.5
PH0 ( W 19) = P Z
4.79
= P(Z -1.67) = 0.0475.
Thus, the normal approx. is at least moderately accurate
even though the sample sizes are small. We will use the
normal approx. whenever the sample sizes are outside
of the range of Table A3. 51
2.5 The Rank Sum Test Adjusted for Ties
52
Ex 10 The recovery times (in days) of 9 patients
randomly allocated to one of two treatments is
as follows:
Treatment Recovery Time
A 20 21 24 27
B 15 18 20
Use the Wilcoxon rank sum statistic, adjusted for
ties, to test the null hypothesis of no difference
in the distns. of recovery time versus a
two-sided alternative.
53
Soln to Ex 10
Combined Set: 15 18 20 20 21 24 27
Ranks: 1 2 3.5 3.5 5 6 7
Test Statistic:
W = sum of midranks of treatment A observations
N
Claim that 1
R i = 1 + 2 + . . . + N = N(N + 1)/2
Proof: Let the distinct data values and numbers of
tied values be denoted as follows:
Distinct ordered data values: a 1 a 2 . . . ak
Number of tied values: t1 t2 . . . tk
Midranks: v1 v2 . . . vk
56
Note (Continued)
1 + 2 + . . . + t1
v1 = = midrank of values tied at a1
t1
(t1 + 1) + (t1 + 2) + . . . + (t1 + t 2 )
v2 =
t2
(t1 + t 2 + 1) + (t1 + t 2 + 2) + . . . + (t1 + t 2 + t 3 )
v3 =
t3
and so on.
Thus, 1 R i = 1 t i vi = 1 + 2 + . . . + N
N k
57
Mean and Variance of the Rank Sum Statistic
in the Case of Ties
W = su m o f m id ran k s o f th e o b se rv atio n s
in th e sam p le o f siz e m
T h e n u ll d is tn . o f W is th a t o f th e to ta l o f a sam p le
o f siz e m fro m th e fo llo w in g p o p u la tio n :
M id ran k s : R 1 R 2 . . . R N
N
Ri N + 1
= p o p . m ean = 1
=
N 2
N
R i2 N + 1
2
2
= p o p . v arian ce = 1
-
N 2
(C o n tin u e d )
58
Mean and Variance (Continued)
N+1
E H 0 (W) = m where =
2
N
mn 2 R i2 N + 1
2
mn(N + 1
VarH0 (W) = - AF
12
where
mn i = 1 t i (t - 1)
k 2
i
AF = adjustment factor =
12N(N - 1)
60
Note:
N o tie s ti = 1, i = 1, 2, . . . , k
mn
k 2
t
1 i
( t i - 1)
AF = i =
= 0
1 2 N (N - 1 )
m n (N + 1 )
V a rH 0 ( W ) = - AF
12
m n (N + 1 )
=
12
T h e la t t e r i s t h e v a r i a n c e g i v e n e a r li e r
fo r th e c a s e o f n o tie s .
61
Ex 11. Treatment Recovery Time
A 16 18 20 21 24
B 12 14 16 18 18
Determine
(a) W = sum of midranks of treatment A observ.
(b) The null mean and variance of W.
(c) A test of the null hypothesis of identical distns.
vs. a two-sided alternative. Use the normal
approx. and significance level = 0.05. Show all 4
steps and label each part.
(d) The adjustment factor, AF, due to the presence of
ties. 62
Soln. to Ex 11 (a), (b).
Combined
Set: 12 14 16 16 18 18 18 20 21 24
Midranks: 1 2 3.5 3.5 6 6 6 8 9 10
Wobs = sum of midranks of treatment A observations = 36.5
10
N = 10 n=m=5 1
Ri = N(N + 1)/2 = 55
= 1 Ri / N = 55/10 = 5.5
N 10
1
Ri2 = 382.5
N
Ri2 382.5
2
= 1
- 2
= - (5.5)2 = 8
N 10
63
Soln. to Ex 11 (b), (c)
E H 0 ( W ) = m = 5 (5 .5 ) = 2 7 .5
m n 2 5 (5 )(8 )
V a rH 0 ( W ) = = = 2 2 .2 2
N -1 9
H 0 : th e re c o v e ry tim e d is tn s . a re id e n tic a l
H A : tre a tm e n t A re c o v e ry tim e s te n d to b e la rg e r
o r s m a lle r th a n tre a tm e n t B re c o v e ry tim e s .
W - 2 7 .5
T e s t S ta tis tic : Z = = 0 .0 5
2 2 .2 2
R e je c t H 0 if Z -1 .9 6 o r Z 1 .9 6
3 6 .5 - 2 7 .5
C o n c lu s io n : Z o b s = = 1 .9 1 ;
2 2 .2 2
D o n o t re je c t H 0 .
64
Soln to Ex 11 (d)
m n (N + 1 )
V ar(W ) = - AF
12
m n 1 t i ( t i2 1)
k
AF =
1 2 N (N - 1 )
k = 7 d istin ct valu e s w ith th e n u m b ers o f tied
valu e s b ein g 1 , 1 , 2 , 3 , 1 , 1 , 1
k
T h u s, 1
t i ( t i2 1) = 2 (2 2 1) + 3 (3 2 1) = 3 0
5 (5 )(3 0 ) 150
AF = = = 0 .6 9
1 2 (1 0 )(9 ) 216
m n (N + 1) 5 (5 )(1 1 )
V ar(W ) = - AF = - 0 .6 9
12 12
= 2 2 .9 2 - 0 .6 9 varian c e w h en n o ties are p resen t
65
Ignoring the Correction for Ties Gives a
Conservative Test
R e c a ll E x 1 1 (b ).
ST
then X = Y + .
Proof:
Y is N(1 , 2 ) Y + is N(2 , 2 )
ST
That is, X = Y + , as was to be shown.
75
The Mann-Whitney Statistic
T he statistic W introduced earlier is th e W ilcoxon
rank sum statistic.
T he M ann-W hitney statistic is
m n
U xy = i=1 j=1
(X i , Y j )
w here
1 if x < y
(x, y) =
0 otherw ise
N ote that
U xy = num ber of pairs (X i , Y j ) for w hich X i < Y j
76
Properties of the Mann-Whitney Statistic
77
How is the Mann-Whitney Statistic Related
to the Rank Sum Statistic?
Claim: U = W - n(n + 1)/2 where W = R(Y ).
n
xy y y 1 i
j + (number of X's Yj
n n
Wy = j=1
R (Y j ) = j=1
= (1 + 2 + . . . + n) + U xy
which gives U xy = W y - n(n + 1)/2
78
Properties of the U-Statistic
n
(1) U xy = W y - n(n + 1)/2 w here W y = 1
R (Y i )
mn – 1 -- --------------
V(t)
2 -- -----------
1 -- ---------------
___________________________________________________
0 D(1) D(2) D(3) . . . D(mn - 1) D(mn)
t 84
Implications of the Shift Model
ST
T h e sh ift m o d el X = Y + can also b e w ritten
ST
X - = Y (N o te: = E (X ) - E (Y ) )
S h ift m o d el
X 1 - , X 2 - , . . . , X m - , Y1 , Y 2 , . . . , Y n
are all iid w ith co m m o n cd f F (t).
If is th e tru e valu e o f th e p aram eter ,
th en U X - ,Y is d istrib u ted lik e th e n u ll d is tn o f U X Y .
85
Notes
86
Confidence Limits for the Shift Parameter
Suppose we want 100(1 - )% confidence limits for the
parameter = E(X) - E(Y).
Solution:
Let D(1) < D(2) < . . . < D(mn) denote the
ordered mn differences Xi - Yj. We will choose
nonnegative integers r and s so that
P( D(r) < < D(s) ) = 1 - (Continued)
87
Solution (Continued)
T h e in te rv a l, [D (r) , D (s) ] is th e n a 1 0 0 (1 - ) %
c o n fid e n c e in te rv a l fo r .
C h o o se r a n d s s o th e p ro b a b ility o f
n o n c o v e rag e o n th e le ft a n d rig h t a re e q u a l.
T h a t is, c h o o se r a n d s so th a t
P ( < D (r) ) = /2
and P ( D (s) < ) = /2
88
Solution (Continued)
D (r) r - 1 or fewer of the differences
X i - Yj V( ) r - 1
Thus,
P( D (r) ) = P(V( ) r - 1) = PH 0 (U XY r - 1)
Similarly,
D (s) < s or more differences
X i - Yj < V( ) s U XY s
Thus, P(D (s) < ) = PH 0 (U XY s)
= PH 0 (U XY mn - s)
(because U XY has symmetric distn.) 89
Summary
C h o o s e r, s s o th a t
( 1 ) /2 = P ( n o n c o v e ra g e o n th e le f t)
= P ( < D (r) ) = PH 0 (U XY r - 1)
(2 ) /2 = P (n o n c o v e ra g e o n th e rig h t)
= P( D (s) < ) = PH 0 (U XY m n - s)
If w e h a v e a lr e a d y c a lc u la te d r in ( 1 ) ,
th e n m n - s = r - 1 a n d w e h a v e a s im p le
w a y t o c a lc u la t e s a s s = m n - (r - 1 ).
T h i s v a lu e o f s is th e s a m e a s th e r t h
d iffe re n c e c o u n te d fro m th e u p p e r e n d :
m n, m n - 1, m n - 2, . . . , m n - ( r - 1)
90
Summary of Procedure for Constructing a CI
for the Shift Parameter
93
Soln. to Ex 2 (Continued)
w ant
0 .0 2 5 = P (n o n c o v e ra g e o n th e le ft)
= P ( < D (r) ) = P (U x y r - 1 )
= P (U x y r - 1 + 0 .5 )
U x y - 3 1 2 .5 r - 0 .5 - 3 1 2 .5
= P
5 1 .5 4 5 1 .5 4
r - 313 r - 313
PZ = -1 .9 6
5 1 .5 4 5 1 .5 4
r = 2 1 1 .9 8 R o u n d o u tw a rd to r = 2 1 1 .
s = m n - (r - 1 ) = 2 5 (2 5 ) - 2 1 0 = 4 1 5 .
A 9 5 % C I fo r is g iv e n b y [D (2 1 1 ) , D 4 1 5 ]
94
Ex 3. Mixing Times (in Minutes) Needed to
Achieve Consistency of a Mixture
95
Soln. to Ex 3
Choose r, s so that
0.95 = P(D ( r ) D ( s ) )
Want 0.025 = P( < D ( r ) ) = PH0 (U xy r - 1)
Table A4 r - 1 = 2 r = 3
s = mn - (s - 1) = 5(5) - 2 = 23.
Thus, a 95% CI for is given by [D (3) , D (23) ]
96
Soln to Ex 3 (Continued)
C o n s tr u c t a ta b le a s f o llo w s a n d
c a lc u la te th e d if f e r e n c e s X i - Yj:
X Y 6 .7 6 .8 6 .9 7 .1 7 .4
6 .9 0 .2 0 .1 0 .0 -0 .2 -0 .5
7 .2 0 .5 0 .4 0 .3 0 .1 -0 .2
7 .2 0 .5 0 .4 0 .3 0 .1 -0 .2
7 .3 0 .6 0 .5 0 .4 0 .2 -0 .1
7 .8 1 .1 1 .0 0 .9 0 .7 0 .4
D (3) = -0 .2 D (23) = 0 .9
9 5 % C I fo r : -0 .2 < < 0 .9
97
Notes
( 1 ) In g e n e r a l a 9 5 % C I f o r = E ( X ) - E ( Y ) w i ll
d iffe r fro m a 9 5 % C I fo r * = E (Y ) - E (X ).
(2 ) W h e n c o n s tru c tin g a C I fo r = E (X ) - E (Y ),
w e m u s t c a lc u la t e t h e o r d e r e d d i f f e r e n c e s
D (1 ) < D ( 2 ) < . . . D ( m n ) o f X i - Y j .
( 3 ) T h e n u ll d i s t r i b u t i o n o f U XY w hen m = 7
a n d n = 1 0 i s i d e n t i c a l t o t h e n u ll d i s t n .
of U XY w hen m = 10 and n = 7.
( 3 ) T h u s , w h e n s o lv i n g f o r r , s s o t h a t
0 .0 2 5 = P ( < D ( r) ) = P (U XY r - 1)
i t d o e s n o t m a t t e r w h e t h e r w e u s e T a b le A 4
w ith n = 7 a n d m = 1 0 o r w h e th e r w e u s e
T a b le A 4 w i t h m = 7 a n d n = 1 0 .
98
Ex 4. What is the actual confidence level
for the CI in Ex 3?
Solution:
Exact null distn. of U xy when n = m = 5:
u 0 1 2 3 4 5 ...
1 1 2 3 5 7
p(u) ...
252 252 252 252 252 252
P(noncoverage on the left) = P( < D (3) )
4
PH 0 (U xy 2) =
252
P(noncoverage on the right)
8
Actual confidence level = 1 - 0.968
252
99
The Hodges-Lehmann Estimator
(1) A point estimate of the shift parameter is given by
ˆ = median of the mn pairwise differences X - Y i j
X - 1 STY - 2 V ar(X ) 12
(4 ) = = 2
1 2 V ar(Y ) 2
T h us, a test o f th e h ypo th esis o f eq u a l scale
p aram eters is eq u ivalen t to a tes t o f eq u al
varian ces in the settin g o f th e g eneral
lo catio n-scale param eter m o del.
105
Main Parameter of Interest
The main parameter of interest is the ratio of
the scale parameters,
2
Var(X)
= 2 =
2 1
2 Var(Y)
=1
2
Var(X) = Var(Y)
2 > 1 Var(X) > Var(Y)
< 1
2
Var(X) < Var(Y)
106
Assumptions of the Siegel-Tukey Test
A1 X1 , X 2 , . . . , X m are iid with cdf F1 (t).
A2 Y1 , Y2 , . . . , Yn are iid with cdf F2 (t)
A3 The two samples are selected independently
A4 The cdfs follow the location-scale parameter
t - 1 t - 2
model: F1 (t) = H F2 (t) = H
1 2
where H(t) is a continuous cdf.
A5 The two populations have a common median,
= 1 = 2
107
Note
The assumption that the two populations have
a common median severely restricts the use of
the Siegel-Tukey test.
If the population medians have unequal but
known values, then the Siegel-Tukey test
can be applied with the X's replaced by
X = X i - 1 and the Y's replaced by
'
i
Y j' = Y j - 2 .
108
The Siegel-Tukey Test
1 . O rd e r th e o b s e rv a tio n s in th e c o m b in e d
s a m p le s fro m s m a lle s t to la rg e s t.
2 . A s s ig n a s c o re o f 1 to th e s m a lle s t o b s e rv a tio n ,
a s c o re o f 2 to th e la rg e s t o b s e rv a tio n , a s c o re
o f 3 to th e n e x t la rg e s t, a n d s o o n . T h e a rra y
o f a s s ig n e d s c o re s is th e n
1, 4, 5, 8, 9, . . . , 11, 10, 7, 6, 3, 2
3 . T h e S ie g e l-T u k e y s ta tis tic is
W = s u m o f ra n k s (i.e ., s c o re s ) o f s a y th e X 's
4 . T h e n u ll d is trib u tio n o f W is id e n ti c a l to
th a t o f th e W ilc o x o n ra n k s u m s ta ti s tic .
5 . S m a ll v a lu e s o f W X 's h a v e la rg e r v a ria b ility
109
Ex 1 The Siegel-Tukey Test
Treatment Observations
1 15.36, 15.94, 16.01, 16.43, 16.55
2 15.88, 15.91, 15.98, 16.05, 16.10
110
Solution to Ex 1.
Form the combined ordered set and assign ranks
as described in step #1. The data values from
treatment 1 are boxed as indicated below.
Ordered Values:15.36 , 15.88, 15.91, 15.94 , 15.98,
Ranks: 1 4 5 8 9
Ordered Values: 16.01 , 16.05, 16.10, 16.43 , 16.55
Ranks: 10 7 6 3 2
R eject H 0 if W 1 7 o r if W 3 8
(U sed th e 2 .5 % case o f tab le A 3 )
114
Solution to Ex 2
H 0: 2
= 1 H A: 2
1 = 0 .0 5
120
Squared Ranks Test: The Hypotheses
H 0 : 12 = 22 H A : 12 22
(tw o-sided alternative)
H 0 : 12 22 H A : 12 > 22
(one-sided alternative)
H 0 : 12 22 H A : 12 < 22
(one-sided alternative)
121
Squared Ranks Test: Procedure
(1 ) If th e p o p u la tio n m e a n s h a v e k n o w n v a lu e s ,
c a lc u la te :
U i = |X i - 1 | i = 1 , 2 , . . . , m
V i = |Y i - 2 | i = 1 , 2 , . . . , n
(2 ) If th e p o p u la tio n m e a n s d o n o t h a v e k n o w n
v a lu e s , c a lc u la te :
U i = |X i - X | i = 1 , 2 , . . . , m
V i = |Y i - Y | i = 1 , 2 , . . . , n
(3 ) F o rm th e c o m b in e d o rd e re d s e t o f th e
N v a lu e s o f U i a n d V i , a n d a s s ig n r a n k s
o r m id ra n k s . N = m + n.
122
Squared Ranks Test: Procedure
(4) D e te rm in e th e r a n k s o f th e U i :
R (U 1 ), R (U 2 ), . . . , R (U m )
a n d th e ra n k s o f th e V i :
R (V 1 ), R (V 2 ) , . . . , R (V m )
m 2
(5) C a lc u la te T = i = 1
[R (U i ) ]
large values
Similarly,
12 = 22 ranks of the Ui distributed
like in the case of the Wilcoxon rank sum test.
125
Null Distribution of T when Pop. Means are
Known
U n d e r th e tw o -p o p u la tio n lo c a tio n -s c a le
p a r a m e te r m o d e l w ith k n o w n p o p u la tio n
m eans and under H 0: 1
2
= 2
2 ,
m 2
T = i = 1
[ R ( U i ) ]
is d is tr ib u te d lik e th e s u m o f s q u a r e s o f
th e o b s e rv a tio n s in a s a m p le o f s iz e m
ta k e n w ith o u t re p la c e m e n t fro m th e
p o p u la tio n 1, 2, . . . , N . (N = m + n )
G e n e r a tin g th e n u ll d is tn . o f T b y lis ti n g
o u tc o m e s is v e r y s im ila r to th a t o f th e r a n k
s u m s ta tis tic s o w e w ill n o t re p e a t th is
p ro c e d u re .
126
Tables of the Null Distribution
Tables of the null distribution of T are
available in Conover (1999) for sample sizes n
and m less than or equal to 10.
m (N + 1 )(2 N + 1 )
E H 0 (T ) =
6
m n (N + 1 )(2 N + 1 ) (8 N + 1 1 )
V a rH 0 ( T ) =
180
In th e lim it a s m ,n ,
T - E H 0 (T )
Z =
V a rH 0 ( T )
h a s a p p ro x . (u n d e r H 0 ) a s ta n d a rd n o rm a l d is tn .
128
Null Mean and Variance in the Case of Ties
R e call U i = |X i - 1 | i = 1 , 2 , . . . , m an d
V i = |Y i - 2 | i = 1, 2, . . . , n N = m + n
N 2
R2 = i= 1
R i / N E H 0 (T ) = m R 2
mn
N 4 2
V ar H 0 (T ) = ( R i - N R 2)
N (N - 1 ) i= 1
129
Ex 1. Squared Rank Test with Ties
X = amount of cereal dispensed by machine A
Y = amount dispensed by machine B
Machine Observations
A (1) 10.1, 10.4, 10.8, 11.1, 11.3
B (2) 10.5, 10.7, 10.8, 10.8, 10.8, 10.9, 11.0
Use the squared ranks test (adjusted for ties) and
the normal approximation to test the hypothesis
of equal variances versus the alternative that the
amounts dispensed by B have smaller variance.
Use = 0.05.
130
Solution to Ex. 1
A (X) B (Y) U = |X - X | V = |Y - Y |
10.1 10.5 0.64 0.29
10.4 10.7 0.34 0.09
10.8 10.8 0.06 0.01
11.1 10.8 0.36 0.01
11.3 10.8 0.56 0.01
10.9 0.11
11.0 0.21
X = 10.74 Y = 10.79
131
Soln. to Ex 1. (Continued)
Comb. Set 0.01 0.01 0.01 0.06 0.09 0.11
Midrank 2 2 2 4 5 6
Comb. Set 0.21 0.29 0.34 0.36 0.56 0.64
Midrank 7 8 9 10 11 12
m = 5 n = 7 Deviations for machine A boxed.
TOBS = sum of squared midranks of deviations
for machine A
= 426 N = m + n = 12
132
Soln. to Ex 1 (Continued)
N
1
R2 = 2
R /N =
i
12
( 2 ) 2
+ (2 ) 2
+ . . . + (1 2 ) 2
i 1
648
= 54
12
N
i 1
R i4 = 2 4 + 2 4 + . . . + 1 2 4 = 6 0 ,6 6 0
E H 0 (T ) = m R 2 = 5 (5 4 ) = 2 7 0
mn N 2
V arH 0 (T ) =
N (N - 1 ) i 1
4
R i - NR 2
5(7 )
=
(1 2 )1 1
6 0 ,6 6 0 - 1 2 (5 4 ) 2 = 6 8 0 5 .9 1
133
Soln. to Ex 1. (Continued)
H0 : A2 = B2 HA : A2 > B2 = 0.05
HA amounts dispensed by machine A have
larger variance.
T - 270
Test Statistic: Z =
6805.91
T = sum of squared midranks of machine A dev.
Reject H0 if Z 1.645
462 - 270
Conclusion: ZOBS = = 2.33
6805.91
Reject H0 .
134
Using SAS to Apply the Squared Rank Test
135
E x 2 . T h e p a in th r e s h o ld fo r 1 2 m a le s a n d
1 2 fe m a le s w e re a s fo llo w s :
G ro u p
M a le s 6 .8 7 .2 7 .4 7 .5 7 .8 7 .8
F e m a le s 6 .4 6 .6 7 .1 7 .3 7 .4 7 .7
M a le s 7 .9 8 .0 8 .0 8 .1 8 .5 8 .6
F e m a le s 7 .7 7 .7 8 .0 8 .1 8 .3 8 .9
U s e th e s q u a re d r a n k s te s t a n d th e n o rm a l
a p p ro x . to th e n u ll d is tn . to te s t th e h y p o th e s is
o f e q u a l p o p u la ti o n v a r ia n c e s .
136
Soln. to Ex 2: The SAS Program
data d1;
input group $ x @@;
if group='M' then dev=abs(x - 7.8);
else if group='F' then dev=abs(x - 7.6);
datalines;
M 6.8 M 7.2 M 7.4 M 7.5
M 7.8 M 7.8 M 7.9 M 8.0
M 8.0 M 8.1 M 8.5 M 8.6
F 6.4 F 6.6 F 7.1 F 7.3
F 7.4 F 7.7 F 7.7 F 7.7
F 8.0 F 8.1 F 8.3 F 8.9
;
137
Soln. to Ex 2: The SAS Program
proc rank data=d1 out=ranks;
var dev;
ranks rdev;
run;
data d2;
set ranks;
r2=rdev*rdev;
r4=r2*r2;
run;
proc print data=d2;
sum r2 r4;
run; quit;
138
Soln. to Ex 2: The SAS Output
Obs group x dev rdev r2 r4
1 M 6.8 1.0 21.5 462.25 213675.06
2 M 7.2 0.6 17.0 289.00 83521.00
3 M 7.4 0.4 13.0 169.00 28561.00
4 M 7.5 0.3 11.0 121.00 14641.00
5 M 7.8 0.0 1.5 2.25 5.06
6 M 7.8 0.0 1.5 2.25 5.06
7 M 7.9 0.1 4.5 20.25 410.06
8 M 8.0 0.2 8.5 72.25 5220.06
9 M 8.0 0.2 8.5 72.25 5220.06
10 M 8.1 0.3 11.0 121.00 14641.00
11 M 8.5 0.7 18.0 324.00 104976.00
12 M 8.6 0.8 20.0 400.00 160000.00
139
Soln. to Ex 2: The SAS Output
13 F 6.4 1.2 23.0 529.00 279841.00
14 F 6.6 1.0 21.5 462.25 213675.06
15 F 7.1 0.5 15.5 240.25 57720.06
16 F 7.3 0.3 11.0 121.00 14641.00
17 F 7.4 0.2 7.0 49.00 2401.00
18 F 7.7 0.1 4.5 20.25 410.06
19 F 7.7 0.1 4.5 20.25 410.06
20 F 7.7 0.1 4.5 20.25 410.06
21 F 8.0 0.4 14.0 196.00 38416.00
22 F 8.1 0.5 15.5 240.25 57720.06
23 F 8.3 0.7 19.0 361.00 130321.00
24 F 8.9 1.3 24.0 576.00 331776.00
======= ==========
sum(R2) = 4891.00 1758616.75 = sum (R4 ) 140
Soln. to Ex 2 (Continued)
T = sum of squared ranks of male deviations
= 462.25 + . . . + 400.00 = 1983.2 5
4891
R2 = i = 1Ri / N =
N 2
= 244.55
20
i = 1 i = 1,758,616,.75
N 4
R and so on.
T o finish we would need to calculate
E H 0 ( T ) = mR 2 and
VarH 0 (T ) =
mn
N(N - 1)
i=1 i
N
R 4
- NR 2
2
141
Derivation of the Null Mean and Variance of
The Squared Rank Statistic
A ssu m e th e sa m p les a re ta k e n fro m c o n tin u o u s
d istrib u tio n s so th e p ro b ab ility o f tied v alu e s is
z e ro .
L e t W 1 , W 2 , . . . , W m d e n o te a ra n d o m sa m p le
o f siz e m ta k e n w ith o u t rep la c em e n t fro m th e
d isc re te u n ifo rm d istrib u tio n (o f th e ra n k s):
w 1 2 3 .. . N
1 1 1 1
f(w ) ...
N N N N
U n d e r H 0 th e sq u a red ra n k sta tistic is
m
d istrib u te d lik e T =
i 1
W i2 .
142
Derivation (Continued)
E q u i v a le n t ly , T i s d i s t r i b u t e d li k e t h e t o t a l
o f a s a m p le o f s i z e m t a k e n w i t h o u t r e p l a c e m e n t
f r o m t h e f o llo w i n g p o p u la t i o n :
v 11 22 32 . . . N2
1 1 1 1
f(v ) . . .
N N N N
L e t V d e n o te a rv h a v in g th is p d f.
T h e p o p u la t i o n m e a n i s
1 n 2 1 N (N + 1 )(2 N + 1 )
= E (V ) =
N i 1
i =
N 6
( N + 1 )(2 N + 1 )
=
6
m (N + 1 )(2 N + 1 )
T hu s, E H 0 (T ) = m =
6 143
Derivation (Continued)
S im ila r ly ,
mn
V a rH 0 ( T ) = 2
N - 1
w h e r e 2 = p o p u la t io n v a r i a n c e .
= V a r(V ) = E (V 2
) - 2
1
2 N 4
E (V ) = i
N i = 1
N 4
to k n o w i = 1
i .
144
Summary
In th e c a s e o f n o tie s ,
m (N + 1 )(2 N + 1 )
E H 0 (T ) =
6
m n (N + 1 )(2 N + 1 )(8 N + 1 1 )
V a rH 0 ( T ) =
180
145
The Kolmogorov-Smirnov Test
• The K-S test was designed to detect any
difference between two distributions
regardless of the nature of the differences.
• The chi-square test of homogeneity can also
be used to detect general differences between
two distributions, but was designed for use
with frequency data.
• The K-S test compares the empirical cdf’s of
two independently selected samples.
146
Assumptions:
X 1 , X 2 , . . . , X m is a random sam ple of s ize m
from a population w ith cdf F1 ( x ).
H 0 : F1 ( t) = F 2 ( t) H A : F1 ( t) F 2 ( t)
O n ly la rg e v a lu e s o f K -S s u p p o rt H A
R e je c t H 0 if KS c
148
Calculating the K-S Statistic
We could plot the empirical cdfs of the X's and
Y's and visually determine the maximum absolute
difference. A simpler way is based on the following:
a 2 = m ax | ˆ ( t) - Fˆ ( t)|
F
Z (1 ) t < Z (2 ) 1 2
a 3 = m ax Z (2 ) t < Z (3 ) | Fˆ 1 ( t) - Fˆ 2 ( t)|
a n d s o o n w h e re
a N + 1 = m ax Z (N ) t | Fˆ1 ( t) - Fˆ 2 ( t)| = 0
B o th Fˆ 1 ( t) a n d Fˆ 2 ( t) a re c o n s ta n t o v e r th e
in te rv a l Z (k ) t < Z (k + 1 ) a n d a re rig h t
c o n tin u o u s . 150
Proof (Continued)
T hus, a k = m ax Z (k ) t < Z (k + 1)
| Fˆ 1 ( t) - Fˆ 2 ( t)|
= | Fˆ 1 ( Z ( k ) ) - Fˆ 2 ( Z ( k ) )|
fo r k = 1 , 2 , . . . , N .
K S = m a x | Fˆ 1 ( t) - Fˆ 2 ( t)|
= m ax {a 1, a 2 , . . . , a N }
= m a x k = 1 , 2 , . . . , N | Fˆ1 ( Z ( k ) ) - Fˆ 2 ( Z ( k ) )|
a s w a s to b e s h o w n .
151
Ex 1. Calculating the K-S Statistic
T re a tm e n t O b s e rv a tio n s
1 0 .0 2 .1 2 .8 4 .4
2 3 .1 4 .2 4 .9 6 .8
n = m = 4
C a lc u la te th e o b s e rv e d v a lu e o f th e K -S s ta tis tic .
152
Solution to Ex1
T reatm ent #1 observations are enclosed in
rectangles.
C om bined
Set: 0.0 2.1 2.8 3.1 4.2 4 .4 4.9 6.8
R ank: 1 2 3 4 5 6 7 8
1 2 3 3 3 4 4 4
F̂1 ( t):
4 4 4 4 4 4 4 4
0 0 0 1 2 2 3 4
F̂2 ( t):
4 4 4 4 4 4 4 4
3 3
K S = m ax difference = | - 0| =
4 4
153
The Null Distn. of the K-S Statistic
T h e calcu lated valu e o f th e K -S statistic d epen d s
o n ly o n the ord er o f th e X 's an d Y 's an d it is
th erefo re a ran k statistic.
U n d er H 0 each o rd erin g o f th e X 's an d Y 's is
eq u ally lik ely.
8
In E x 1 th ere are 7 0 d istin ct o rd ering s o f
4
th e X 's and Y 's. T o g et th e n u ll d istn . w e w ill
list all o f th ese an d , in each case, calculate th e
valu e o f th e K -S statistic.
154
Ex 2. Determine the null distribution of the K-S
statistic when the sample consists of 3 X's and 2 Y's.
Solution:
5
The = 10 possible arrangements of the combined
2
set of X's and Y's are shown on the next page.
The calculated value of the K-S statistic for the
first outcome (ordering) is as follows:
Combined Set: X X X Y Y
F̂1 (t): 1/3 2/3 3/3 3/3 3/3
F̂2 (t): 0/2 0/2 0/2 1/2 2/2
KS = largest absolute difference = | 3/3 - 0/2 | = 1
155
Soln. to Ex 2 (Continued)
O utcom e KS P rob. O utcom e K S P rob.
XXXYY 1 0.1 XYXYX 1/3 0.1
XXYXY 2/3 0.1 YXXYX 1/2 0.1
XYXXY 1/2 0.1 XYYXX 2/3 0.1
YXXXY 1/2 0.1 YXYXX 2/3 0.1
XXYYX 2/3 0.1 YYXXX 1 0.1
As m , n , W converges in distribution to
the follow ing cdf:
L(t) = 1 - 2 i = 1 (-1) i - 1exp(-2i 2 t 2 ),
0 t <
T hat is,
lim P W t = L(t)
m, n
159
Large Sample Approx. (Continued)
160
Ex 3. Using the Asymptotic Distn of the K-S
Statistic to Perform the K-S Test
R e c a ll t h e d a t a f r o m E x 1 :
T re a tm e n t O b s e rv a tio n s
1 0 .0 2 .1 2 .8 4 .4
2 3 .1 4 .2 4 .9 6 .8
n = m = 4 . U s e t h e a s y m p t o t i c n u ll d i s t n . o f
t h e K -S s t a t i s t i c t o t e s t t h e h y p o t h e s i s t h a t
th e tw o tre a tm e n ts d o n o t d iffe r in th e d is tn .
o f t h e r e s p o n s e . U s e = 0 .0 5 . E v e n
t h o u g h t h e s a m p le s i z e s a r e n o t la r g e i n
t h i s e x a m p le , w e w i ll u s e t h e a s y m p t o t i c n u ll
d i s t n . t o i llu s t r a t e i t s u s e . 161
Solution to Ex 3.
H 0 : T he distn. of the response does not differ
betw een the tw o treatm ents
H A : T he tw o distns. do differ = 0.05
mn
T est S tatistic: W = KS w here
m +n
K S = m ax |Fˆ1 ( t) - Fˆ 2 ( t)| is t he K -S statistic
R eject H 0 if W 1.36
4(4)
C onclusion: K S O BS = 0.75 W O BS = 0.75
4 +4
1.06. D o not reject H 0 .
162
Ex 4. Using SAS to Perform the K-S Test
S am e data as in E x 1.
T reatm ent O bservations
1 0.0 2.1 2.8 4.4
2 3.1 4.2 4.9 6.8
164
Soln to Ex 4: The SAS Program
data d1;
input treatment score @ @ ;
datalines;
1 0.0 1 2.1 1 2.8 1 4.4
2 3.1 2 4.2 2 4.9 2 6.8
;
proc npar1way data=d1 ks; /*Requests K-S test*/
class treatment;
exact ks; /*Requests exact p-value*/
var score;
run;
quit;
165
Soln to Ex 4: The SAS Output
T h e N P A R 1 W A Y P ro c e d u re
K o l m o g o r o v - S m i r n o v T e s t f o r V a r i a b le s c o r e
E D F at D e v ia tio n fro m M e a n
tre a tm e n t N M a x im u m a t M a x im u m
1 4 0 .7 5 0 0 0 .7 5 0
2 4 0 .0 0 0 0 -0 .7 5 0
T o ta l 8 0 .3 7 5 0
M a x im u m D e v ia tio n O c c u rre d a t O b s e rv a tio n 3
V a lu e o f s c o r e a t M a x i m u m = 2 . 8 0
K S 0 .3 7 5 0 K S a 1 .0 6 0 7 (T h is is W OBS )
K o lm o g o r o v - S m i r n o v T w o - S a m p le T e s t
D = m a x |F 1 - F 2 | 0 .7 5 0 0
A s y m p to tic P r > D 0 .2 1 0 6
E xact Pr >= D 0 .2 2 8 6
166