Outline Introduction Comparing Two Means Comparing Two Proportions

advertisement

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Lesson 10

Chapter 9: Comparing Two Populations

Michael Akritas

Department of Statistics

The Pennsylvania State University

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

1

Introduction

2

Comparing Two Means

3

Comparing Two Proportions

4

Power and Sample Size Calculation – NOT COVERED

5

The Rank-Sum Test Procedure

6

Comparing Two Variances – NOT COVERED

7

Paired Data

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

The comparisons will be based on a simple r.s. from each of the two populations: and X

21

, . . . , X

2 n

2

X

11

, . . . , X

1 n

1 from population 2.

from population 1,

In the Bernoulli case only p i

(or T i

= n i b i

) is typically given.

With the exception of the section on paired data, we will make the further assumption that the two samples are independent.

The sample mean and sample variances are denoted by

X i

=

1 n i n i

X j = 1

X in i

, S i

2

= n i

1

− 1 n i

X j = 1

X ij

− X i

2

, i = 1 , 2 .

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

The Two Approaches

One approach for comparing means is based on the contrast

X

1

− X

2

An alternative approach for comparing means uses the ranks of the observations.

We will distinguish the cases where σ

1

= σ

2 and σ

1

= σ

2

:

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

1 If σ

2

1

= σ

2

2

, under normality and for any n

1

, n

2

,

X

1

− X

2

− ( µ

1

− µ

2

) r

S

2 p

1 n

1

+

1 n

2

∼ t n

1

+ n

2

− 2

.

2 where S 2 p

= [( n

1

− 1 ) S 2

1

+ ( n

2

− 1 ) S 2

2

] / ( n

1

+ n

2

− 2 ) .

( Smith-Satterthwaite ) Under normality and for any n

1

, n

2

,

X

1

− X

2

− ( µ

1

− µ

2

) q

S

2

1 n

1

+

S

2 n

2

2

·

∼ t

ν

, where ν =

S

2

1 n

1

 ( S

2

1

/ n

1 n

1

− 1

) 2

+

+

S

2

2 n

2

2

( S

2

2

/ n

2 n

2

− 1

) 2

.

Without normality, both hold approximately if

n

1

,

n

2

30.

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

T

CIs for µ

1

µ

2

Let σ

2

1

= σ

2

2

. Under normality a ( 1 − α ) 100 % CI is:

X

1

− X

2

± t

α/ 2 , n

1

+ n

2

− 2 s

S

2 p

1 n

1

1

+ n

2

.

Under normality an approximate ( 1 − α ) 100 % CI is:

X

1

− X

2

± t

α/ 2 ,ν s

S

2

1 n

1

+

S

2

2

, n

2 where ν is the Smith-Satterthwaite DF (rounded down!).

Without normality, both hold approximately if

n

1

,

n

2

30.

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

A rule of thumb, for deciding if σ

2

1 approximately equal, is:

' σ

2

2

, i.e. that σ

2

1

, σ

2

2 are

 max { S 2

1

, S 2

2

} min { S 2

1

, S 2

2

}

<

5 if n

1

, n

2

3 if n

1

, n

2

2 if n

1

, n

2

'

'

7

15

' 30

Rule of thumb for checking if

σ

2

1

' σ

2

2

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

T

Tests for

µ

1

− µ

2

We will test H

0

: µ

1

− µ

2

= ∆

0 vs

H a

: µ

1

− µ

2

> ∆

0

, or µ

1

− µ

2

< ∆

0

, or µ

1

− µ

2

= ∆

0

.

The test statistic is T

H

0

=

X

1

− X

2

− ∆

0

, where

σ b

X

1

− X

2

If σ

2

1

= σ

2

2

, σ b

X

1

− X

2

= s

S 2 p

1 n

1

1

+ n

2

.

Without assuming σ

2

1

= σ

2

2

, σ b

X

1

− X

2

= s

S 2

1 n

1

+

S 2

2 n

2

.

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Rejection Rules

µ

1

− µ

2

> ∆

0

µ

µ

1

1

H a

− µ

2

− µ

2

< ∆

= ∆

0

0

RR at level α

|

T

T

T

H

0

H

0

H

0

|

> t

<

>

− t

α

∗ t

α

α/ 2

, where

If σ

2

1

= σ

2

2

, t

α

= t

α, n

1

+ n

2

− 2

, t

α/ 2

= t

α/ 2 , n

1

+ n

2

− 2

.

Without assuming σ

2

1

= σ

2

2

, t

α

= t

α,ν denotes the Smith-Satterthwaite DF.

, t

α/ 2

= t

α/ 2 ,ν

, where ν

Without normality these test procedures require n

1

, n

2

≥ 30.

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

p

-values

The p -values are computed in a way similar to that for the one-sample T -test:

P − value =

1 − G

ν

( T

H

0

) for upper-tailed test

G

ν

( T

H

0

) for lower-tailed test

2 1 − G

ν ∗

( | T

H

0

| ) for two-tailed test where ν

= n

1

+ n

2

− 2 if σ

2

1

= σ

2

2

, and

ν

= ν , the Smith-Satterthwaite DF, if σ

2

1

= σ

2

2 is not assumed.

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Example

A simple r.s. of n

1

= average strength X

1

32 specimens of cold-rolled steel give

= 29 .

8 ksi, and S

1

= 4. A simple r.s. of n

2

X

2

= 35 specimens of two-sided galvanized steel give

= 34 .

7 ksi, and S

2

= 6 .

74. Construct a 99% CI for µ

1

− µ

2

.

Solution.

Assuming σ

2

1

S

2 p

= 5 .

6029

2 and use t

= σ

2

2

, we calculate the pooled variance

0 .

005 , 65

= 2 .

653. This gives a 99% CI of

( − 8 .

54 , − 1 .

26 ) . [NOTE: By the rule of thumb σ

1

= σ

2

.]

Without the assumption of to be ν = 56 .

12, and use t

σ

2

1

= σ

0 .

005 , 56

2

2

, we find the Smith-Satt. DF

= 2 .

666. This gives a 99% CI of ( − 8 .

48 , − 1 .

32 ) .

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Example (Cold-rolled and two-sided galvanized steel)

Are the strengths of the two types of steel different? Test at

α = 0 .

01 and compute the p-value.

Solution.

Since zero is not included in the 99% CIs,

H

0

: µ

1

= µ

2 is rejected at α = 0 .

01 with both test statistics.

As illustration, without the assumption of σ

2

1

= σ

2

2

, the TS is

T

H

0

= X

1

− X

2

/ q

S

2

1 n

1

+

S

2

2 n

2

= − 3 .

65 .

Since | T

H

0

| = 3 .

65 > t

0 .

005 , 56

= 2 .

666, p -value is 2 1 − G

56

( 3 .

65 ) = 0 .

0006.

H

0 is rejected. The

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

The R command ”t.test”

The default is to assume σ

1 p -value for H

0

= σ

2

, do 95% CI, and give the

: µ

1

− µ

2

= 0 vs H a

: µ

1

− µ

2

= 0: t.test(y ∼ x) # For values in y and sample index in x t.test(y[1:32],y[33:67]) # Specify the two samples separately or: x1=y[which(x==1)]; x2=y[which(x==2)]; t.test(x1,x2)

For the pooled variance T test, and 99% CI do: t.test(y ∼ x, var.equal = TRUE, conf.level = 0.99)

To test H

0

: µ

1

− µ

2

= 1 .

8 vs H a

: µ

1

− µ

2

< 1 .

8 do: t.test(y ∼ x,mu=1.8, alternative = ”less”)

Other options: alternative = ”greater” or the default

”two.sided”

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Z

CIs for

p

1

− p

2

When n i p i

≥ 8, n i

( 1 − p i

) ≥ 8 for both i = 1 , 2, p

1

− p

2

·

∼ N p

1

− p

2

, σ b

2 p

1

− b

2

, where

σ b

2 p

1

− p

2

= p

1

( 1 − p

1

) n

1

+ p

2

( 1 − p

2

)

.

n

2

Thus the (approximate) ( 1 − α ) 100 % CI for p

1

− p

2 is p

1

− p

2

± z

α/ 2 s p

1

( 1 − n

1 p

1

)

+ p

2

( 1 − p

2

)

.

n

2

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Z

Tests for

p

1

− p

2

We will test H

0

: p

1

− p

2

= ∆

0 vs

H a

: p

1

− p

2

> ∆

0

, or p

1

− p

2

< ∆

0

, or p

1

− p

2

= ∆

0

.

The test statistic for testing this null hypothesis is

Z

H

0

σ b p

1

− b

2

=

= p

1

− p

2

− ∆

0

, where

σ b p

1

− p

2 s b

1

( 1 − b

1

) n

1

+ p

2

( 1 − p

2

)

.

n

2

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

For testing H

0

: p

1

= p

2

(so ∆

0

= 0), it is customary to use:

σ e p

1

− b

2

= s p b

( 1 − p b

)

1 n

1

1

+ n

2

.

where b

= n

1 p

1 n

1

+ n

2 p

2

.

+ n

2

Thus the TS for testing H

0

: p

1

= p

2 is:

Z

H

0

= p

1

− p

2

.

σ e p

1

− b

2

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Rejection Rules and

p

-values

The rules for rejecting H

0 in favor of H a are: p p p

1

1

1

− p

H a p

− p

2

2

2

>

<

= ∆

0

0

0

RR at level α

Z

Z

H

0

H

0

> z

α

< − z

α

| Z

H

0

| > z

α/ 2

The p -value is computed the same way as for the one-sample Z -test:

P − value =

1 − Φ( Z

H

0

) for upper-tailed test

Φ( Z

H

0

)

2 1 − Φ( | Z

H

0 for lower-tailed test

| ) for two-tailed test

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Example

Tractors are assembled in assembly lines L

1 and L

2

. A simple r.s. of

200 tractors from L

1 yield 16 tractor requiring adjustment. A simple r.s. of 400 tractors from L

2 yield 14 requiring extensive adjustments.

Do a 99% CI for p

1

− p

2

, the difference of the two proportions.

Solution.

z

α/ 2

= z

Here

.

005 p b

1

= 16 / 200 = 0 .

08, p b

2

=

= 2 .

575. Thus the 99% C.I. is

14 / 400 = 0 .

035, and

0 .

08 − .

035 ± 2 .

575 r

( .

08 )( .

92 )

200

+

( .

05 )( .

95 )

400

= ( − 0 .

012 , 0 .

102 ) .

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Example (Assembly lines L

1 and L

2 continued)

It is suspected that a higher proportion of tractors from L

1 require adjustments. Formulate a hypothesis testing problem, test at α = .

01, and calculate the p -value.

Solution.

We want to test H

0

: p

1

= p

2 vs H a

: p

1 pooled estimate of the common (under H

0

) p is b

= ( 16 + 14 ) / 600 = 0 .

05. The TS is

> p

2

. The

Z

H

0

=

.

08 − .

035 p

( .

05 )( .

95 )( 1 / 200 + 1 / 400 )

= 2 .

38 .

Since 2 .

38 > z

.

01

= 2 .

33, H

0 is rejected. The p -value is p -value = 1 − Φ( 2 .

38 ) = 1 − .

9913 = .

0087 .

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

The R command ”prop.test”

Set the number of successes and the number of trials adj=c(16,14); tract=c(200,400)

# X

1

= 16, X

2

= 14, n

1

= 200, n

2

= 400.

prop.test(adj,tract) # is equivalent to prop.test(adj, tract, alternative = ”two.sided”, conf.level =

0.95, correct = TRUE)

It tests H

0

: p

1

− p

2

= 0 vs alternative = ”two.sided”, ”less”, or ”greater”. No option for testing, e.g.

H

0

: p

1

− p

2

= 0 .

1

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Probability of Type II Error,

β (∆

1

)

, when

µ

1

− µ

2

= ∆

1

H a

β (∆

1

)

µ

µ

1

1

− µ

− µ

2

2

>

<

0

0

Φ z

α

1

σ b

X

− ∆

0

1

− X

2

Φ − z

α

1

σ b

X

− ∆

0

1

− X

2

µ

1

− µ

2

= ∆

0

Φ z

α/ 2

1

− ∆

0

σ b

X

1

− X

2

− Φ − z

α/ 2

σ b

1

X

− ∆

1

− X

2 where σ b

X

1

− X

2 is either of its two versions. These hold under normality with known variances (in which case be replaced by σ

X

1

− X

), but can also be used when n

2

Michael Akritas

σ b

X

1

− X

2

1

should

,

n

2

30.

Lesson 10 Chapter 9: Comparing Two Populations

0

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Formulas for Sample Size

We will give the formula for the common sample size n = n

1

= n

2

II error, β (∆) , at alternative µ

H

0

: µ

1

− µ

2 required to achieve a specified level, β , of type

− µ

2

= ∆ when testing

= ∆

0

.

1

1 For a one-sided alternative, the formula is

2 n = ( σ

2

1

+ σ

2

2

) z

α

+ z

β

∆ − ∆

0

2 For a two-sided test the simple size formula is as above except that α is replaced by α/ 2.

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Example

Consider the data from the comparison of cold-rolled steel and two-sided galvanized steel. a) What is the probability of type II error when µ

1

− µ

2

= 5 ? Use α = 0 for 95% power at µ

1

− µ

2

= 5 ?

.

01 . b) What sample size is needed

Solution.

a) The formula for the probability of Type II error, without the assumption that σ

1

= q

S

2

1

/ n

1

+ S

2

2

/ n

2

= σ

=

2

(so σ b

X

1

− X

2

1 .

798 ), with ∆

0

= 0 , ∆

1

= 5 yields

β ( 5 ) = Φ( − 1 .

15 ) − Φ( − 6 .

31 ) = 0 .

1251 .

b) 95% power means β = 0 .

05 . The formula for the common sample size needed yields n = 4

2

+ 6 .

74

2

[( 2 .

Michael Akritas

576 + 1 .

645

Lesson 10 Chapter 9: Comparing Two Populations

) / 5 ]

2

= 43 .

7778 , or n = 44 .

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Comparison of Proportions

The formulas for the probability of type II error remain the same but with the following substitutions:

Substitute µ

1

, µ

2

Substitute σ b

X

1

− X

2 by p

1

, p

2

, respectively.

by σ b p

1

− p

2

.

The formula for the sample size remains the same with the following substitution:

Substitute σ where p i

2

1

, σ

2

2 by e

1

( 1 − p

1

) , p

2

( 1 − p is a preliminary estimator of p i

,

2 i

) , respectively,

= 1 , 2.

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Example

Consider the data from the tractor assembly lines L

1 is the probability of type II error when p

1

− p

2 and L

2

. a) What

= 0 .

04 ? Use

α = 0 .

01 . b) What sample size is needed for 95% power at p

1

− p

2

= 0 .

04 ?

Solution.

a) According to the formula for β (∆

1

) for the alternative

H a

: p

1

> p

2

, we have β ( 0 .

04 ) = Φ( z

Φ( 2 .

326 − 0 .

04 / 0 .

0189 ) = 0 .

5819 .

0 .

01

− 0 .

04 / σ b p

1

− ˆ

2

) = b) The desired level of probability of type II error is 0.05. According to the formula for common sample size we have n = ( 0 .

08 × 0 .

92 + 0 .

035 × 0 .

965 )

2 .

326 + 1 .

645

0 .

04

2

= 1058 .

24 , or n = 1059 .

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

R for Power and Sample Size: Two Proportions

library(pwr) # For new R sessions with package pwr installed

Set h: h=2*asin(sqrt( p

1

))-2*asin(sqrt( p

2

))

There are two commands: pwr.2p.test(h = , n = , sig.level =, power = )

# For n

1

= n

2

= n . See ?pwr.2p.test for documentation.

pwr.2p2n.test(h = , n1 = , n2 = , sig.level = , power = )

# For n

1

= n

2

. See ?pwr.2p2n.test for documentation.

alternative = ”two.sided” is the default; ”less” or ”greater” are other options.

See also ?power.prop.test for the documentation of this function. It does not require installation of a package but it works only for n

1

= n

2

= n .

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

R for Power and Sample Size: Two Means

library(pwr) # For new R sessions with package pwr installed

There are two commands (both assume σ

1

= σ

2

): pwr.t.test(n = , d = , sig.level = , power = , type =

”two.sample”))

# For n

1

= n

2

= n . Type ?pwr.t.test for the documentation.

pwr.t2n.test(n1 = , n2= , d = , sig.level =, power = )

# For n

1

= n

2

. Type ?pwr.t2n.test for the documentation.

alternative = c(”two.sided”,”less”,”greater”); ”two.sided” is default.

The command: power.t.test(n = NULL, delta = NULL, sd = 1, sig.level = 0.05, power = NULL, type = ”two.sample”, alternative

= c(”two.sided”, ”one.sided”), strict = FALSE)

only for n

1

= n

2

= n . Type ?power.t.test for the documentation.

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Motivation

The Mann-Whitney-Wilcoxon rank-sum test (or rank-sum test for short), which will be described, can be used with both small and large sample sizes.

If the two populations are continuous, the null distribution of the TS is known even with very small sample sizes.

For discrete populations, the null distribution of the TS can be well approximated with much smaller sample sizes than those required by contrast-based procedure.

The rank-sum test has high power, especially if the two population distributions are heavy tailed, or skewed.

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

The Null Hypothesis and the TS

The rank sum procedure tests H

F

0

: F

1

= F

2

.

Let R ij denote the (mid-)rank of observation X ij combined set of N = n

1

+ n

2 in the observations, and set

W

1

= n

1

X

R

1 j

, R

1

= j = 1

W

1

, W

2 n

1

= n

2

X

R

2 j

, R

2

= j = 1

W

2

.

n

2

Then, the Mann-Whitney-Wilcoxon TS is

R

1

− R

2

=

N n

1 n

2

W

1

− n

1

N + 1

2

, or simply W

1

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

The Standardized Rank-Sum TS and RR

If there are no ties,

Z

H

0

=

W

1

− n

1

( N + 1 ) / 2 p n

1 n

2

( N + 1 ) / 12

If H F

0 holds, Z

H

0

·

∼ N ( 0 , 1 ) , for n

1

, n

2

> 8. The RR are:

µ

1

H a

µ

2

> 0

µ

1

− µ

2

< 0

µ

1

− µ

2

= 0

Rejection region at level α

Z

H

0

≥ z

α

Z

H

0

| Z

H

0

≤ − z

α

| ≥ z

α/ 2

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Example

Data on sputum histamine levels from 9 allergic and 13 non-allergic individuals are given in http://sites.stat.

psu.edu/˜mga/401/Data/HistaminData.txt

. Is there a difference between the two populations? Test at α = .

01.

Solution.

R

15

= 17,

Here

R

16

R

=

11

=

21, R

18,

17

R

=

12

7,

=

R

11,

18

=

R

13

20,

= 22, R

14

R

19

= 19,

= 16. Thus

W =

X

R

1 j

= 151 and Z

H

0

= j

151 − 9 ( 23 ) / 2 p

9 ( 13 )( 23 ) / 12

= 3 .

17 .

Since n

1

, n

2

> 8, p -value=2 difference is significant.

[ 1 − Φ( 3 .

17 )] = .

0016. Thus the

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Effect of Outliers

In the above example, the t test does not reject at level

0.01.

With data in data frame hi , t.test(hi$Level ∼ hi$Sample) gives p-value of 0.13, and t.test(hi$Level ∼ hi$Sample, var.equal=TRUE) gives p-value of 0.06.

In general, using a procedure when the underlying assumptions are violated will give misleading results.

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

R Command for the Rank Sum Test

With data in data frame hi , wilcox.test(hi$Level ∼ hi$Sample) is short for wilcox.test(hi$Level ∼ hi$Sample, alternative=”two.sided”,mu = 0, paired = FALSE)

Can also get a CI, whose description is not in the book, by wilcox.test(hi$Level ∼ hi$Sample, conf.int = TRUE), which is short for wilcox.test(hi$Level ∼ hi$Sample, alternative=”two.sided”,conf.int = TRUE, conf.level = 0.95)

More advanced application: boxplot(Ozone ∼ Month, data = airquality) wilcox.test(Ozone ∼ Month, data = airquality, subset =

Month %in% c(5, 8))

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Levene’s Test

It is based on the idea that if the variances are equal, then the two samples

V

1 j

= | X

1 j

− e 1

| , j = 1 , . . . , n

1

, and V

2 j

= | X

2 j

− e 2

| , j = 1 , . . . , n

2

, where e i

, i = 1 , 2 is the median from i th sample, correspond to populations with equal means and variances.

Thus, equality of variances can be tested by testing the hypothesis

H

0

: µ

V

1

= µ

V

2 vs µ

V

1

= µ

V

2 using the two-sample t -test with pooled variance.

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Example

The following data represent the plasma ascorbic acid (vitamin

C) concentration measurements ( µ mol/l) of five randomly selected smokers and nonsmokers:

Nonsmokers 41 .

48 41 .

71 41 .

98 41 .

68 41 .

18 s

1

Smokers

= 0 .

297

40 .

42 40 .

68 40 .

51 40 .

73 40 .

91 s

2

= 0 .

192

Here the two medians are e 1

= 41 .

68 , e 2

= 40 .

68. Subtracting them from their corresponding sample values we have

V

1

V

2 values for Nonsmokers 0 .

20 0 .

03 0 .

30 0 .

00 0 .

50 values for Smokers 0 .

26 0 .

00 0 .

17 0 .

05 0 .

23

The two-sample test statistic with pooled variance yields a

p

-value of 0.558. Thus, there is not enough evidence to reject

the null hypothesis of equality of the two population variances.

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

The

F

Test Under Normality

When the two samples have been drawn from normal populations, the exact distribution of S 2

1

/ S 2

2 an F distribution.

is a multiple of

Theorem

Let X

11 sample from a normal distribution with variance σ

2

2

, and let S and S

2

2

, . . . , X

1 n

1 be a random sample from a normal distribution with variance σ

2

1

, let X

21

, . . . , X

2 n

2 be another denote the two sample variances. Then the rv

2

1

F =

S 2

1

2

1

S 2

2

/σ 2

2 has an F distribution with ν

1 of freedom.

= n

1

− 1 and ν

2

= n

2

− 1 degrees

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

The theorem suggests that H

0 the F test statistic:

: σ

2

1

= σ

2

2 can be tested with

F

H

0

=

S

2

1

.

S

2

2

If the ratio differs sufficiently from 1, the null hypothesis is rejected. In particular the RRs for testing H

0

: σ

2

1

= σ

2

2 are

σ

σ

σ

2

1

2

1

2

1

H a

> σ

< σ

= σ

2

2

2

2

2

2

RR at level α

F

H

0

F

H

0

> F n

1

− 1 , n

2

− 1 ; α

< F n

1

− 1 , n

2

− 1 ; α either F

H

0

> F n

1

− 1 , n

2

− 1 ; α/ 2 or F

H

0

< F n

1

− 1 , n

2

− 1 ; α

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Example

Consider the data in the previous example, and assume the underlying populations are normal. The test statistic is

F

H

0

=

0 .

297

0 .

192

= 2 .

40 .

The value 2.4 corresponds to the 79th percentile of the F distribution with ν

1

= 4 and ν

2

= 4 degrees of freedom. Thus, the p -value is 2 ( 1 − 0 .

79 ) = 0 .

42.

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Introduction, Motivation

Paired data arise when each experimental unit receives each of the two treatments that being compared.

1

2

3

Compare the durability of two types of tires.

Compare two labs for the analysis of mercury content.

Two acne treatments, two cataract treatments, etc.

Paired data are of the form: ( X

11

, X

21

) , . . . , ( X

1 n

, X

2 n

) .

CIs and the TS are again based on X

1

− X

2

. But now they are not independent. Thus, previous formulas do not apply.

For example, σ

2

X

1

− X

2

= σ

2

X

1

+ σ

2

X

2

− 2Cov ( X

Similarly, the rank sum test is not valid now.

1

, X

2

) .

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

While Cov ( X

1

, X

2

) can be estimated, it is easier to use

D

1

= X

11

− X

21

, . . . , D n

= X

1 n

− X

2 n

D

σ

1

2

X

1

, . . . ,

− X

2

D

= n

σ are independent, and

2

D can be estimated by

D

σ b

=

2

D

X

1

= S

2

D

/

X n

2

. Thus,

, where

S

2

D

=

1 n − 1

" n

X

D i

2

− i = 1

1 n n

(

X i = 1

D i

)

2

#

CIs and testing are based on the fact:

D

S

D

/

µ

D n

∼ t n − 1 if normality holds, or if n ≥ 30

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Example

A total of 12 water samples are analyzed for mercury content by labs A and B . The paired data yields D = X

1

− X

2

= − and S

D

= 0 .

02645. Does lab B give, on average, higher concentration results than lab A ? Test at α = 0 .

05.

0 .

0167

Solution.

Here H

0

: µ

1

− µ

2

= 0 , H a

: µ

1

− µ

2

< 0. Because n < 30, we must assume normality. Doing so we have:

T

H

0

=

S

D

D

/

√ n

=

− 0 .

0167

.

02645 /

12

= − 2 .

1865 .

Since T

H

0

< − t

.

05 , 11

= − 1 .

796, H

0 is rejected.

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

It is important to be able to recognize paired data. Below are two examples:

1. A study was conducted to see whether two cars, A and B, having very different wheel bases and turning radii, took the same time to parallel park. 7 drivers were randomly obtained and the time required for each of them to parallel park each of the 2 cars was measured. The results are as follows:

Car 1 2 3

Driver

4 5 6 7

A 19.0

21.8

16.8

24.2

22.0

34.7

23.8

B 17.8

20.2

16.2

41.4

21.4

28.4

22.7

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

2. Two brands of motorcycle tires are to be compared for durability. Eight motorcycles are selected at random and one tire from each brand is randomly assigned (front or back) on each motorcycle. The motorcycles are then run until the tires wear out. The data in http://stat.psu.edu/˜mga/401/

Data/motorcycleTiresLifetimes.txt

are in km.

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Two Proportions (NOT COVERED)

Here each pair ( X

1 j

( 0 , 1 ) or ( 0 , 0 ) .

, X

2 j

) can be either ( 1 , 1 ) or ( 1 , 0 ) or

As an example, if n voters are asked, both before and after a presidential speech, whether or not they support a certain policy, X

1 j

= 1 or 0 if the speech, and X

2 j after the speech.

= j th voter supports or not before the

1 or 0 if the same voter supports or not

Now

X

1

= p b

1

, X

2

= p b

2

, D = p b

1

− p b

2

.

As before, S

2

D

/ n estimates the variance of p

1

− p

2

.

However: a) we have different sample size requirements, and b) typically, the pairs ( X

1 j

, X

2 j

) are not given.

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Table Format of the Data

Before

1

1 Y

1

After

0

Y

2

0 Y

3

Y

4

Y

1 is the number of ( 1 , 1 ) pairs,

Y

2 is the number of ( 1 , 0 ) pairs,

Y

3 is the number of ( 0 , 1 ) pairs,

Y

4 is the number of ( 0 , 0 ) pairs,

Y

1

+ · · · + Y

4

= n

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

The test statistic can be computed from:

Y

1

+ Y

2 n

= p b

1

,

Y

1

+ Y n

3

= p b

2

, D =

Y

2

− Y

3

, and n n − 1 n

S

2

D

=

1 n n

X

( D i

− D )

2 i = 1

= q

2

+ b

3

− ( b

2

− q

3

)

2

, where q

2

= Y

2

/ n , q

3

= Y

3

/ n .

Thus, the test statistic for H

0

: p

1

− p

2

= ∆

0 is:

T

H

0

=

( b

2

− q

3

) − ∆

0 p

( q

2

+ q

3

− ( b

2

− q

3

) 2 ) / ( n − 1 )

It is approximately normal provided n

10

+ n

01

≥ 16.

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

McNemar’s Test

It can be used only for testing H

0

: p

1

− p

2

= 0:

MN =

( q b

2

− q b

3

)

2

( q b

2

+ q b

3

) / n

=

( Y

2

− Y

3

)

2

Y

2

+ Y

3

∼ χ

2

1

Note that MN = ( MN

2

)

2

, where

MN

2

=

( q

2

− q

3

) p

( q

2

+ b

3

) / n

=

Y

2

− Y

3

Y

2

+ Y

3 is a variation of the paired t statistic:

The different denominator is a consistent estimator of S

2

D under the null hypothesis.

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

The Signed Rank Test – NOT COVERED

2

3

1 Rank the absolute differences | D

1

| , . . . , | D n

| from smallest to largest. Let R i

Assign to R i denote the rank of the sign of D i

| D i

| .

, forming thus signed ranks.

Let S

+ be the sum of the ranks R i with positive sign, i.e.

the sum of the positive signed ranks.

If

If

H

H

0

0 holds, µ

S

+ holds, and

= n n ( n + 1 )

>

4

10,

, σ

2

S

+

S

+

= n ( n + 1 )( 2 n + 1 )

·

∼ N ( µ

S

+

24

, σ

2

S

+

) .

.

The TS for testing H

0

: µ

D

= 0 is

Z

H

0

= S

+

− n ( n + 1 )

4

/ r n ( n + 1 )( 2 n + 1 )

24

,

The RRs are the usual RRs of a Z -test.

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Example (Mercury concentrations from Labs A and B )

The 12 differences, D i and the ranks of their absolute values are given in the table below. Test

H

0

: µ

1

− µ

2

= 0 , H a

: µ

1

− µ

2

< 0 at α = 0 .

05.

D i

R i

-0.0206

5

-0.0350

10

-0.0161

4

-0.0017

1

0.0064

2

-0.0219

6

D i

R i

-0.0250

8

-0.0279

9

-0.0232

7

-0.0655

Solution: Here S

+

= 2 + 11 = 13. Thus

12

0.0461

11

-0.0159

3

Z

H

0

=

13 − 39

162 .

5

= − 2 .

04 .

The p -value = Φ( − 2 .

04 ) = 0 .

02. The exact p -value, as obtained from Minitab, is 0.0193.

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

R Commands for Paired Data

Rank sum test:

Only for testing: wilcox.test(x, y, alternative = c(”two.sided”,

”less”, ”greater”), mu = 0)

For testing and CI: wilcox.test(x, y, alternative = c(”two.sided”, ”less”, ”greater”), mu = 0, conf.int = TRUE, conf.level = 0.95) x,y above can be replaced by y ∼ Sample

Paired data t test for means: t.test(x, y, alternative = c(”two.sided”, ”less”, ”greater”), mu

= 0, paired = TRUE, conf.level = 0.95) x,y above can be replaced by y ∼ Sample

McNemar’s test for proportions: mcnemar.test(table)

See next page for example.

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Outline

Introduction

Comparing Two Means

Comparing Two Proportions

Power and Sample Size Calculation – NOT COVERED

The Rank-Sum Test Procedure

Comparing Two Variances – NOT COVERED

Paired Data

Example (Example of McNemar’s test)

Data on approval of the President’s performance in office in two surveys, one month apart, for a random sample of 1600 voting-age Americans.

table=matrix(c(794, 86, 150, 570), nrow = 2, dimnames = list(c(”Approve”, ”Disapprove”), c(”Approve”, ”Disapprove”))) table mcnemar.test(table)

Michael Akritas

Lesson 10 Chapter 9: Comparing Two Populations

Download