You are on page 1of 166

549 Chapter 2

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.

A test statistic that could be used in p lace of X - Y


is S = sum of the new-m ethod observation s.
T his statistic pro duces exactly the same p-value as
the difference in m eans:
S obs = 198
2
p-value = PH 0 ( S  198) = = 0.057
35 11
Equivalent Test Statistics
The following test statistics are equivalent in the
sense that the permutation p-values of all 3 statistics
are the same.
(1) X - Y
(2) S = sum of treatment #1 observations
X -Y -0
(3) T =
1 1
Sp +
n m
12
Proof that (1) and (2) are equivalent
T reatm ent O bservations S um M ean
1 X 1, X 2 , . . . , X m S X = S/m
2 Y1 , Y 2 , . . . , Y n W -S Y = (W - S )/n
w here W =  Xi + Y. i T hen
S W -S  1 1 W
D = - = S +  -
m n m n n
N ote:
(1) W is constant for all perm utations of the data.
(2) D is a 1 - 1 increasing function o f S .
It follow s that the p-value of a test ba sed on D w ill
b e the sam e as the p-value of a test base d on S.
13
Permutation Tests Based on Medians
• Since medians are not affected by outliers in
the data, it might be desirable to use the
difference in medians rather than the
difference in means to compare 2 treatments.
• When performing a permutation test we are
free to use any statistic that we feel best
describes the difference between groups.
• The power of tests based on means vs.
medians does differ; our text, however, does
not give a comparison of their power.
14
Ex 2 Same Situation as in Ex 1
Method Test Scores
(1) New 37, 49, 55, 57
(2)Standard 23, 31, 46
Use the difference of medians to test the
hypothesis of identical distns. vs. the one-
sided alternative that the new method
scores tend to be higher than the standard
method scores.
15
Solution to Ex 2
A = new method B = standard method
D = difference of medians = M1 - M2
Outcome 23 31 37 46 49 55 57 M1 M2 D
1 B B B A A A A 52 31 21
2 B B A B A A A 52 31 21
3 B B A A B A A 50.5 31 19.5
4 B B A A A B A 47.5 31 16.5
.
.
34 A A A B A B B 34 55 -21
35 A A A A B B B 34 55 -21 16
Soln to Ex 2 (Continued)
T h e o bserved valu e o f th e d ifferen ce in m ed ians
is D o bs = 2 1. T h u s, th e perm u tatio n p -valu e is

2
p -valu e = PH 0 ( D  2 1 ) = = 0 .0 57 1
35

w hich is n o t sig nificant at th e 5% level.


In this case, the p erm utatio n p -valu e based
o n th e d ifference o f m edians is id en tica l to th e
p erm u tatio n p -valu e based o n th e d iffere n ce
o f m ean s. T his is n o t tru e in g en eral.
17
Normal Approx. to the (Null) Permutation
Distribution
Treatment Sample Size Observations Sum
1 n X 1, X 2 , . . . , X m S
2 m Y1 , Y 2 , . . . , Yn

Form the combined set of N = m +n observations:


Z1 , Z 2 , . . . , Z N
The null hypothesis of identical distrib utions 
S is distributed like the total of a sam ple of size m
from the above population. The pop. mean & v ariance
2
  Z -  / N
N N
are  = 1
Zi / N  =
2
1 i
18
Normal Approx. (Continued)
By the CLT, the null permutation distn. of S is
approximately normal with mean and variance,

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

Recall: the exact p-value is 0.0571. T he


normal approximation should not generally be
used with such small samples.
23
Ex 4 Using SAS to obtain an Exact Permut. P-Value
Method Test Scores
A (New) 37, 49, 55, 57
B (Standard) 23, 31, 46
Use the NPAR1WAY procedure with the scores=
data option in the proc statement to request
an analysis using actual data values as scores.
Use an exact statement to request that the
p-value be based on all possible permutations
of the data.
24
Soln to Ex 4: The SAS Program
data d1;
input method $ score @@; (use double at signs to input
datalines; multiple observ. per line
A 37 A 49 A 55 A 57 of data)
B 23 B 31 B 46
;
proc npar1way data=d1 scores=data; /*Requests analysis using
data values as scores*/
class method; /*Identifies the classification variable*/
exact scores=data; /*Requests exact p-value using permut. of
scores/*
var score;
run; quit;
25
Soln to Ex 4: SAS Output
The NPAR1WAY Procedure
Sum of Expected Std Dev Mean
Method N Scores Under H0 Under H0 Score
A 4 198.0 170.2857 16.5935 49.500
B 3 100.0 127.7142 16.5935 33.333
 

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

Treatment Recovery Time (Days)


A 19 22 25 26 28 29 34 37 38
B 20 21 24 30 32 36 40 48 54
Use the NPAR1WAY procedure with the n =
number of samples option in the exact
statement 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

A 9 258.0 281.50 20.50 28.666


B 9 305.0 281.50 20.50 33.888
 
Data Scores Two-Sample Test
 
Statistic (S) 258.0000 (Sum of treatment A scores)
Z -1.1463
One-Sided Pr < Z 0.1258 (normal approx. p-value)
Two-Sided Pr > |Z| 0.2517
32
Soln to Ex 5: Output (Continued)
Monte Carlo Estimates for the Exact Test
 
One-Sided Pr <= S
Estimate 0.1470 (=estimated p-value)
99% Lower Conf Limit 0.1181 (CI for the p-value)
99% Upper Conf Limit 0.1759
 
Two-Sided Pr >= |S - Mean|
Estimate 0.3030
99% Lower Conf Limit 0.2655
99% Upper Conf Limit 0.3405
 
Number of Samples 1000 33
2.4 Wilcoxon Rank Sum Test
• The Wilcoxon rank sum test differs from the
permutation test of the previous section only
in that the scores are ranks rather than actual
data values.
• In this Sect. we assume the observations have
continuous distns. so the probability is
equal to zero that tied values will occur.
• In Sect. 2.5 we show how to adjust for ties.

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

Combined Set: 5.1 5.7 6.5 7.9 8.1 8.3 9.0


Ranks: 1 2 3 4 5 6 7

W = sum of ranks of diet A observations


Wobs = 4 + 6 + 7 = 17

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

(a) Using table A3 with significance level = 0.05


and n = m = 5,
Reject H 0 if W  19
(b) Using the exact null distn. discussed earlier,
the actual significance level is
PH0 ( W  19) = 0.0476

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

W = sum of ranks of the observations in the sample


of size m
W is distributed like the total of a sample of size m
taken without replacement from the population
1, 2, . . . , N. The population mean and variance are
N(N + 1)/2 N+1
 = (1 + 2 + . . . + N)/N = =
N 2
2 2 2 2 2
1 +2 +...+N  N + 1 N -1
 =
2
-  =
N  2  12 48
Null Mean and Variance (Continued)
m (N + 1 )
E H0 (W ) = m  =
2

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.

Consider the case n = m = 5. Let W = sum


of ranks of the observations in either sample.
n(N + 1) 5(10 + 1)
E H 0 (W) = = = 27.5
2 2
mn(N + 1) 5(5)(10 + 1)
VarH 0 (W) = = = 4.79
12 12

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

• We say that ties occur when two or more


observations have the same value.
• When assigning ranks to the values in the
combined ordered set, tied values are assigned
the average of the ranks they would
have received if they were distinct.
• These are called adjusted ranks (or average ranks
or midranks).

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

Wobs = 3.5 + 5 + 6 + 7 = 21.5


2 4
p-value = 2P(W  21.5) = (2) = = 0.1142
35 35
This p-value is based on the 35 possible
permutations shown on the next page.
54
Soln to Ex 10 (Continued)
Ranks
Outcome 1 2 3.5 3.5 5 6 7 W
1 B B B A A A A 21.5
2 B B A B A A A 21.5
3 B A B B A A A 20.0
. .
. .
33 A A B A A B B 11.5
34 A A A B A B B 11.5
35 A A A A B B B 10.0
55
A Note Concerning the Sum of the Midranks

Let R 1 , R 2 , . . . , R N denote the midranks of


the N observations in the combined set.


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

VarH 0 (W) = where  =


2 1
-  
N-1 N  2 
Thus,
m(N + 1)
E H 0 (W) =
2
2
mn (N + 1)

N 2
VarH 0 (W) = Ri -
N(N - 1) 1
4(N - 1)
59
Equivalent Form of the Variance in the Case
of Ties
In the case of ties our text (p. 70) gives the following
equivalent form of the variance of W:

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 ).

If th e c o rre c tio n fo r tie s is ig n o re d , t h e n


V a rH 0 ( W ) = 2 2 .9 2 a n d th e o b s e rv e d v a lu e
o f th e te s t s ta tis tic is
3 6 .5 - 2 7 .5
Z obs = = 1 .8 8
2 2 .9 2
T h is te s t is c o n s e rv a tiv e in th e s e n s e th a t
w e w ill re je c t H 0 le s s o fte n th a n w e w o u l d
h a v e if w e in c lu d e d th e c o rre c tio n fo r t ie s .
66
Ex 12 Using SAS to Perform the Wilcoxon
Test in the Case of Ties
T r e a t m e n t                   R e c o v e r y T i m e    
                A                    1  6 1  8   20  2 1  2 4
    B                     1  2   14 1  6     18 1  8
U s e p r o c n p a r 1 w a y w i t h t h e W i lc o x o n o p t i o n t o
te s t th e h y p o th e s is th a t th e tw o tre a tm e n ts d o n o t
d iffe r in th e d istn . o f re c o v e ry tim e . L e t W =
s u m o f m id ra n k s o f th e tre a tm e n t A o b s e r v a tio n s .
( a ) V e rify th a t th e S A S o u tp u t g iv e s th e s a m e
n u ll m e a n a n d v a r i a n c e o f W a s i n E x 1 1 .
(b ) U s t h e e x a c t s t a t e m e n t w i t h t h e W i lc o x o n
o p tio n to o b ta in th e e x a c t p -v a l u e .
67
Soln. to Ex 12: The SAS Program
data d1;
input treatment $ time @@;
datalines;
A 16 A 18 A 20 A 21 A 24
B 12 B 14 B 16 B 18 B 18
;
proc npar1way data=d1 wilcoxon;
class treatment;
exact wilcoxon;
var time;
run; quit;
68
Notes
Recall that in Ex 11 we obtained the following:
W = sum of midranks of treatment A observ.
WOBS = 36.5
n = m = 5 N = 10
E H 0 (W) = 27.5
VarH 0 (W) = 22.22 = 4.71
ZOBS = 1.91 The SAS output uses a continuity
correction and thus obtains ZOBS = 1.80
69
Soln. to Ex 12: The SAS Output
The NPAR1WAY Procedure
Wilcoxon Scores (Rank Sums) for Variable time
Classified by Variable treatment
 
Sum of Expected Std Dev Mean
Treatment N Scores Under H0 Under H0 Score

A 5 36.50 27.50 4.714045 7.30


B 5 18.50 27.50 4.714045 3.70
Average scores were used for ties.
(Continued next page)
70
Soln. to Ex 12: The SAS Output (Cont.)
Wilcoxon Two-Sample Test
Statistic (S) 36.5000
 
Normal Approximation
Z 1.8031
One-Sided Pr > Z 0.0357
Two-Sided Pr > |Z| 0.0714
 
Exact Test
One-Sided Pr >= S 0.0397
Two-Sided Pr >= |S - Mean| 0.0794
 
Z includes a continuity correction of 0.5.
71
2.6 Mann-Whitney Statistic and Confid. Limits
for the Shift Parameter
• In this Section we derive a confidence interval
for the parameter of the shift model.
• The shift model is nonparametric in that it
does not assume a particular form for the
distributions of the Xs and Ys.
• Throughout this Section we assume the
distributions are continuous so that tied
values cannot occur.
72
The shift Model
Dfn. A pair of independent rvs, X and Y, follow
ST
the shift model if X = Y +  where
 = shift parameter.

Shift model  E(X) = E(Y) + 


  = E(X) - E(Y)
= mean difference in response to
the two treatments
73
Notes Concerning the Shift Model
ST
(1)  > 0  X  Y
ST
 = 0  X  Y
ST
 < 0  X  Y
(2 ) T h e s h ift m o d e l c a n n o t b e d e s c rib e d b y th e
s ta te m e n t X = Y +  b e c a u s e th e n it is n o t
p o s s i b le f o r X a n d Y t o b e i n d e p e n d e n t r v s .
ST
( 3 ) If X = Y +  , t h e n
F (t) = P (X  t) = P (Y +   t)
= P (Y  t -  ) = G (t -  )
T h u s , a n e q u i v a le n t w a y t o d e s c r i b e t h e s h i f t
m o d e l is F ( t ) = G ( t -  ) f o r a ll t . 74
Notes (Continued)

(4) If X and Y are independent rvs and if


Y is N(1 ,  ), X is N(2 ,  ),  =  2 - 1
2 2

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

There are a total of mn (X, Y) pairs that can be


formed from the two samples:
X1 , X 2 , . . . , X m Y1 , Y2 , . . . , Yn

If all X's are smaller than all of the Y's, then


U xy takes the value mn. The possible values of U xy
are as follows: 0, 1, 2, . . . , mn

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

Pr oof: Combine the X's and Y's and rank them 1 - N.


The rank of Yj in the combined set is
R(Yj ) = (number of Y's  Yj ) + (number of X's  Yj )
Assume the Y's are ordered: Y1 < Y2 < . . . < Yn .
Then the rank of Y j in the combined set is
R(Yj ) = j + (number of X's  Yj ).

  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 )

(2) As noted earlier, the null distribu tion of W y is


sym m etric w ith
n(N + 1) m n(N + 1)
E H 0 (W y ) = V arH 0 ( W y ) =
2 12

(3) T hus, the null dist n. of U xy is also sym m etric w ith


mn
E H 0 (U xy ) = E H 0 (W y ) - n(n + 1)/2 =
2
m n(N + 1)
V arH 0 ( U xy ) = V arH 0 (W y ) =
12
79
Null Distn. of the U-Statistic
We have already pointed out that U xy = Wy - n(n + 1)/2
and thus the null distribution of U xy is that of Wy
with values shifted to the left by the amount n(n + 1)/2.
In the case m = n = 5, the null distn. of Wy = sum
of ranks the Ys is given on the next page.

Note: U yx and U xy take the values 0, 1, 2, . . . , mn


and have exactly the same null distribution. It is
possible to show that U yx = Wx - m(m + 1)/2
80
Null Distn. of the U-Statistic (Cont.)
E x act n u ll d istn . o f W y = su m o f ran k s o f Y s w h en
n = m = 5:
w 15 16 17 18 19 20 ...
1 1 2 3 5 7
p (w ) ...
252 252 252 252 252 252
(a) G ive , in tab le fo rm , th e lo w er a n d u p p er tails
o f th e n u ll d istn . o f U x y .
( b ) U se th is tab le to d ete rm in e th e lo w er 5 %
critical valu e an d th e u p p er 5 % critical valu e.
(c) C o m p are th e critical valu es o b tain ed in (b )
w ith th o se o b tain ed fro m T ab le A 4 .
81
A Counting Process
A ssum e the X 's and Y 's have continuous distns.
so the probability of tied values is zero.

Let D (1) < D ( 2 ) < . . . D ( m n ) denote the m n


ordered differences X i - Y j .
D fn. V ( ) = U X -  ,Y

= # of pai rs (X i , Y j ) for w hich X i -   Yj


= # of pairs (X i , Y j ) for w hich X i - Y j  
 # of D i  
82
Counting Process (Continued)
Similarly, we define V(  ) = # of D i >  .
Note the following:
(1) V( ) and V( ) are functions of the
variable  .
(2) V( ) + V( ) = mn
(3) V( ) = # of D i   is a right continuous
nond ecreasing step function (like a cdf)
(4) V( ) is a right continuous nonincreasing
step function.
83
Graph of V(t)
 
mn -- ---------

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

(1) In the discussion that follow s w e w ill som etim es


interpret  as the true value of th e shift param eter.
O ther tim es w e w ill interpret  as a variable
argum ent of the function V (  ).
(2) W hen  is the true value of the shift param eter,
V (  ) is distributed like the null distn. of U X Y .
T hat is, the distribution of V (  ) does not depend
on  . (A s noted on previo us page.)
(3) M ore specifically, V (  ) is distrib uted like the
null distribution of U X Y .

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

(1) Determine the mn differences X i - Y j and


order them: D (1) < D (2) < . . . < D (mn)
(2) Choose an integer r so that
P(  < D (r) ) = PH 0 (U XY  r - 1) =  /2
(3) Choose s = mn - (r - 1).
(4) Then a 100(1 -  )% CI for  = E(X) - E(Y)
is [D (r) , D (s) ].
91
Ex 1. Small Sample Case, m = 7, n = 10
Find r, s so that [D (r) , D (s) ] is a 95% CI
for  = E(X) - E(Y).
Note: Sample size of X's is m = 7.
Solution:
Use Table A4 with m = 7, n = 10.
0.025 = P(noncoverage on the left) = P(  < D (s) )
= PH 0 (U xy  r - 1)  r - 1 = 14  r = 15
Then s = mn - (r - 1) = 7(10) - 14 = 56
A 95% CI is given by [D 15 , D 56 ]
92
Ex 2. Large Sample Case, n = m =
25
Find r, s so that [D (r) , D (s) ] is a 95% C I for
 = E (X ) - E (Y ).
S olution:
mn 25(25)
E H 0 ( U xy ) = = = 312.5
2 2
m n(N + 1) 25(25)(50 + 1)
V arH 0 ( U xy ) = =
12 12
V arH 0 ( U xy ) = 51.54 (C ont.)

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
PZ    = -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

Method Mixing times


A (X) 7.3, 6.9, 7.2, 7.8, 7.2
B (Y) 7.4, 6.8, 6.9, 6.7, 7.1
n=m=5
Give a 95% CI for the difference  = E(X) - E(Y)
in mean mixing times.

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

= median of the set D(1) , D(2) , . . . , D(mn)


(2) The above estimator is called the Hodges-Lehmann
estimator of the mean difference.
(3) In Ex 3, the Hodges-Lehmann estimate of  is
ˆ = 13th ordered difference out of mn = 25
= 0.3
100
2.7 Scoring Systems
• Ranks can be thought of as scores that are used in
place of the original observations in a permutation
test.
• In Section 2.1 we saw that a two-sample
permutation test used actual data values as scores.
• Our text (p. 50) describes other types of scores
that are often used in permutation tests: normal
scores, Van der Waerdon scores, and exponential
or Savage scores.
• Whatever scoring system is used, a permutation
test is applied to the scores.
101
2.8 Other Nonparametric Tests
• In this Section we discuss the Siegel-Tukey test
of equality of scale parameters in the case of
samples selected independently from each of
two populations.
• We also discuss the Kolmogorov-Smirnov test
of the null hypothesis that two distributions
are identical versus the general alternative
that the two distributions may differ in some
way.
102
The General Location-Scale Paremeter Model
for Two Populations
T he general tw o-sam ple location-scale
param eter m odel can be w ritten in
the follow ing form :
X i =  1 +  1 i and Y j =  2 +  2 j
w here
(a) T he  ' s are iid w ith com m on cdf H (t)
w hich has m edian = 0.
(b)  i ,  i , i = , 2 are called location and scale
param eters, respectively
103
Location-Scale Model (Continued)
N otes:
(1) T he lo catio n-scale param eter m od el for tw o
popu lations assum es the cdfs of t h e X 's and Y 's
have th e sam e general form H (t).
X - 1
(2) T hat is, the m odel  Z1 =
1
Y - 2
an d Z2 = have as com m on cd f,
2
nam ely H (t).
(3) T he m odel is n on param etric in that a specific
form of H (t) is n ot being assu m e d .
104
Location-Scale Model (Continued)

(3 ) T h e assu m ption th at H (t) h as m ed ian = 0


  1 is th e m ed ian of th e X p o p u lat ion
an d  2 is th e m ed ian o f th e Y po p u lation

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

Use the Siegel-Tukey test to test the null hypothesis


that these samples are from populations with equal
variances. Use  = 0.05.

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

W = sum of scores of observations from treatment 1


= 1 + 8 + 10 + 3 + 2 = 24 111
Interpreting the Values of W
S m all valu es o f W  o b servatio n s fro m g ro u p 1
fall to th e left an d rig h t en d s o f th e c o m b in ed set
 1 >  2
L arg e valu es o f W  o b servatio n s fro m g ro u p 1
fall in th e m id d le o f th e co m b in ed set
 1 <  2
T h u s , fo r a tw o -sid ed altern ative w e sh o u ld
reject H o if W  a o r if W  b w h ere
th e lim its a, b can b e d eterm in ed fro m T ab le A 3 .
If th e sam p le sizes are b o th larg e, th en th e
n o rm al ap p ro x . can b e u sed .
112
Soln. to Ex 1 (Continued)
H 0:  2
= 1 H A:  2
 1  = 0 .0 5
w h ere  2
=  12 /  22
T est S tatistic:
W = su m o f ran k s o f o b serv.fro m treatm en t 1

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 )

C o n clu sio n : W o b s = 2 4 . D o n o t reject H 0 .


113
Ex 2. Siegel-Tukey Test Using the Normal
Approximation

Use the data in Ex1 and the normal approximation


to perform a 5% level test of the hypothesis of equal
population variances.

The sample sizes are too small to justify using the


normal approximation. Our only purpose is to
illustrate the use of the normal approx.

114
Solution to Ex 2
H 0:  2
= 1 H A:  2
 1  = 0 .0 5

W = su m o f ran k s o f o b serv.fro m treatm en t 1


m (N + 1 ) 5 (1 0 + 1 )
E H0 (W ) = = = 2 7 .5
2 2
m n (N + 1 ) 5 (5 )(1 0 + 1 )
V arH 0 ( W ) = = = 2 2 .9 2
12 12
W - 2 7 .5
T est S tatistic: Z =
2 2 .9 2
R eject H 0 if Z  -1 .9 6 o r if Z  1 .9 6
C o n clu sio n : Z o bs = 0 .7 3 . D o n o t reject H 0 .
115
Ex 3. Using SAS to Perform the Siegel-Tukey
Test
Same data as in Ex 1.
Treatment Observations
1 15.36, 15.94, 16.01, 16.43, 16.55
2 15.88, 15.91, 15.98, 16.05, 16.10

Use proc npar1way and the Siegel-Tukey option


to test the null hypothesis that these samples are
from populations with equal variances. Calculate
the exact p-value.
116
Soln to Ex 3: The SAS Program
d a ta d 1 ;
in p u t tre a tm e n t w e ig h t @ @ ;
d a ta lin e s ;
1 1 5 .3 6 1 1 5 .9 4 1 1 6 .0 1
1 1 6 .4 3 1 1 6 .5 5
2 1 5 .8 8 2 1 5 .9 1 2 1 5 .9 8
2 1 6 .0 5 2 1 6 .0 1
;
p ro c n p a r1 w a y d a ta = d 1 s t; /* R e q u e s ts S - T te s t* /
c la s s tr e a tm e n t ;
e x a c t s t;
v a r w e ig h t;
ru n ;
q u it;
117
Soln. to Ex 3: The SAS Output
 
The NPAR1WAY Procedure
Siegel-Tukey Scores for Variable weight
Classified by Variable treatment

Sum of Expected Std Dev Mean


treatment N Scores Under H0 Under H0 Score
----------------------------------------------------------------------------
1 5 24.0 27.50 4.787136 4.8
2 5 31.0 27.50 4.787136 6.20
Siegel-Tukey Two-Sample Test
Statistic (S) 24.0000 This agrees with the solution
Normal Approximation to Ex 1
Z -0.6267
One-Sided Pr < Z 0.2654
Two-Sided Pr > |Z| 0.5309
Exact Test
One-Sided Pr <= S 0.2738
Two-Sided Pr >= |S - Mean| 0.5476 Agrees with our solution to
Z includes a continuity correction 0.5 Ex 1. We accepted the null hyp. 118
The Squared Ranks Test

The assumption that the two samples come


from populations with a common median is
unrealistic and severely limits the application
of the Siegel-Tukey test.

One alternative to the Siegel-Tukey test


is the squared ranks test (Conover, 1999).
119
Squared Ranks Test (Continued)
D ata:
Pop. Pop. Sam ple
Pop. M ean V ariance Size Sa m ple
1 1  12 m X 1 , X 2 , . . ., X m
2 2  22 n Y1 , Y 2 , . . ., Y n
Assum ptions:
(1) T he sam ples are taken independently from
each of tw o populations.
(3) T he m easurem ent scale is at least interval.

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 ) ]

T is c a lle d th e s q u a re d ra n k s s ta tis tic .


T e s ts b a s e d o n T a r e c a lle d th e s q u a re d
ra n k s te s t.
123
Rationale Behind the Squared Ranks Test
Pop. 1 2
U i = |X i -  1 | V i = |Y i -  2 |
U i2 = (X i -  1 ) 2 V i2 = (Y i -  2 ) 2
 12 = E (U i2 )  2
2 = E (V i 2 )
ST
U 2
i  V i2  σ 12  σ 22
ST
U 2
i  V i2  σ 12  σ 22
ST
U 2
i  V i2  σ 12 = σ 22
S in c e U i = U i2 and Vi = V i2 , th e a b o v e
s ta te m e n ts re m a in tru e fo r U i a n d V i . (C o n t.)
124
Rationale (Continued)
Thus,
12 >  22  ranks of the Ui tend to be
larger than the ranks of the Vi
 T = i = 1[ R(Ui )]2 will tend to take
m

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.

The normal approx. is reasonably accurate for


sample sizes greater than 10 and can also be
used when ties occur. We will only discuss
using the normal approximation. The squared
ranks test is not available in SAS.
127
Null Mean and Variance of T (No Ties)
W e w ill la te r s h o w th e fo llo w in g :

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

C o m b . O rd ered S et Z (1) Z (2) . . . Z ( N)


M id ran k s R1 R 2 . . . RN


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

As mentioned earlier, the squared rank test is not


available in SAS. However, proc rank can
be used to make many of the calculations
needed to apply the squared rank test, as will
be shown in the next example.

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

W e w ill n o t fu r th e r a tte m p t to s im p lify


th e n u ll v a r ia n c e o f T s in c e w e w o u ld n e e d


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 ).

Y1 , Y 2 , . . . , Y n is a random sam ple of size n


from a popultion w ith cdf F2 ( x ).

T he tw o sam ples are selected inde pendently.

T he exact null distn. of the K -S statistic requires


F1 ( x ) and F2 ( x ) be continuous.
147
Notation, Hypotheses and the K-S Statistic:
ˆ # (X i  t)
F1 ( t ) = s a m p le c d f o f th e X 's =
m
ˆ # (Y i  t)
F 2 ( t) = s a m p le c d f o f th e Y 's =
n

H 0 : F1 ( t) = F 2 ( t) H A : F1 ( t)  F 2 ( t)

K o lm o g o ro v -S m irn o v S ta tis tic :


K S = m a x | Fˆ ( t) - Fˆ ( t) |
1 2

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:

Notation: Let Z (1)  Z (2)  . . .  Z (N) denote


th e ordered values of the combined set of N = m + n
data values.
Claim: max | Fˆ1 (t) - Fˆ 2 (t) | occurs at
t  {Z (1) , Z (2) ,. . . , Z (N) }
That is, the largest difference occurs at a point
in the combined or dered set. 149
Proof
m a x | Fˆ 1 ( t) - Fˆ 2 ( t)| = m a x { a 1 , a 2 , . . . , a N + 1 }
w h e re a = m a x
1 | Fˆ ( t) - Fˆ ( t)|
t < Z (1 ) 1 2

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

N ull D istribution of the K -S S tatistic (m = 3, n = 2):


t 1/3 1/2 2/3 1
PH 0 (K S = t) 0.1 0.3 0.4 0.2
156
Notes Concerning the Null Distn.
• The null distn. of the K-S statistic in the case
m = 3 and n = 2 is identical to the null distn.
of the K-S statistic when n = 3 and m = 2.
• This is because renaming each X as a Y and
each Y as an X does not affect the value of
the K-S statistic.
• The null distn. assumes no ties occur.
• If the cdf’s of the X’s and Y’s are continuous,
then the probability of tied values is zero.
157
Large Sample Approx. to the Null Distn. of
the K-S Statistic

O ur text does not include the tabled null distn.


of the K -S statistic for the case of sm a ll sam ples.
T he K olm ogorov-S m irnov test is im plem ented
in S A S , w hich calculates both exact and
approxim ate p-values.
Later in this S ection w e w ill discuss th e use of
S A S in perform ing the K olm ogorov-S m irnov test.
W e now discuss the asym ptotic null distribution of
the K -S statistic.
158
Large Sample Approx. (Continued)
mn
Let W = KS.
m+n

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)

Approximate upper tail quantiles of L(t) are


the following:
t 1.07 1.22 1.36 1.52 1.63
L(t) 0.80 0.90 0.95 0.98 0.99

These approximate quantiles are used when m = n  40 .


See Conover, 3rd Ed., p. 547 .

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

U se the S A S npar1w ay procedure w ith the K S


option to perform the K olm ogorov-S m irnov
test of the hypothesis that the sam ples com e
from populations w ith a com m on cdf.
C alculate the exact p-value of the test.
163
Notes
In Ex 3 we found KS OBS = 0.75 and
16
WOBS = 0.75 = 0.75 2 = 1.06
8
Using the asymptotic approximation mentioned
earlier (even though the sample sizes are not large)
we have PH 0 (W  1.06)  PH 0 (W  1.07)  0 .20.
This suggests the p-value is slightly larger than
0.20. See the SAS results for a comparison.

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

You might also like