Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We...

23
Comparing Means from Two-Sample Kwonsang Lee University of Pennsylvania [email protected] April 3, 2015 Kwonsang Lee STAT111 April 3, 2015 1 / 22

Transcript of Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We...

Page 1: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Comparing Means from Two-Sample

Kwonsang Lee

University of Pennsylvania

kwonleewhartonupennedu

April 3 2015

Kwonsang Lee STAT111 April 3 2015 1 22

Inference from One-Sample

We have two options to make an inference about population mean micro fromone sample of size n1) 100(1-C) Confidence interval and2) Hypothesis test with a level α

1) 100(1-C) Confidence IntervalWe need to consider the case when σ is known or unknown

a Known σ(X minus Zlowast σradic

n X + Zlowast σradic

n)

b Unknown σ(X minus tlowastnminus1

sradicn X + tlowastnminus1

sradicn

)

Kwonsang Lee STAT111 April 3 2015 2 22

Inference from One-Sample

2) Hypothesis test with a level α

a State the null and alternative hypotheses (Here two-sided example)

H0 micro = micro0 and Ha micro 6= micro0

b Calculate a test statistic Z0 (known σ) or a test statistic T0 (unknownσ)

Z0 =X minus micro0

σradicn

or T0 =X minus micro0

sradicn

c Calculate the P-value

P-value =

2times P(Z ge |Z0|) σ is known

2times P(T ge |T0|) σ is unknown

d Compare the P-value to the significance level α

Kwonsang Lee STAT111 April 3 2015 3 22

Supplement of t-test (Two-sided test)

Because t-table doesnrsquot give the P-value we can modify our t-testInstead of computing P-value we can find the value tlowastnminus1 such that

P(T gt tlowastnminus1) =α

2

Then

Conclusion =

We reject the null if |T0| ge tlowastnminus1We donrsquot reject the null if |T0| lt tlowastnminus1

Note If one-sided alternative hypothesis is Ha micro gt 0 we need to find thevalue tlowastnminus1 such that P(T gt tlowastnminus1) = α We reject the null if T0 gt tlowastnminus1Also if Ha micro lt 0 we need to use tlowastnminus1 such that P(T lt tlowastnminus1) = α Wereject the null if T0 lt tlowastnminus1 Draw the t-distribution and think about it

Kwonsang Lee STAT111 April 3 2015 4 22

New Terminology Standard Error

X is from the population with mean micro and SD σ We take a sample ofsize n from the population and say X1 Xn

What we learned

A sample (X1 Xn) has the sample mean X and the sample SD s

The sample mean X has the distribution with mean micro and SD σradicn

New terminology

Standard error of X is sradicn

ie SE(X ) = sradicn

Kwonsang Lee STAT111 April 3 2015 5 22

Two-Sample Example

Letrsquos assume that we want to study about household incomes inPhiladelphia and New York

Philadelphia income dist rArr mean microp and SD σp

New York income dist rArr mean micron and SD σn

Then we take a Philadelphia sample of size np and a New York sample ofsize nn

Phila sample rArr sample mean xp and sample SD sp

NY sample rArr sample mean xn and sample SD sn

What to do We want to compare microp with micron

1) Hypothesis test of microp = micron

2) Confidence interval of microp minus micron

Kwonsang Lee STAT111 April 3 2015 6 22

Inference from Two-Sample Intro

We donrsquot know the values of micro1 and micro2 We want to make inferences fromSample 1 and Sample 2

We can conduct a hypothesis test or construct a confidence interval for microAlso we need to consider the case when σ1 and σ2 are known or unknown

1) Hypothesis test of micro1 = micro2 or micro1 minus micro2 = 0

2) Confidence interval of micro1 minus micro2

Kwonsang Lee STAT111 April 3 2015 7 22

Two-Sample Hypothesis Test Known σ1 and σ2

Since σ1 and σ2 are known we can take the Z test

a H0 micro1 minus micro2 = 0 and Ha micro1 minus micro2 6= 0

b Test statistic Z0 is

Z0 =(X1 minus X2)minus (micro1 minus micro2)radic

σ21

n1+

σ22

n2

c P-value is

P(Z le minus|Z0|) + P(Z ge |Z0|) = 2times P(Z ge |Z0|)

d Compare P-value with a level α

Kwonsang Lee STAT111 April 3 2015 8 22

Two-Sample Hypothesis Test Unknown σ1 and σ2

Since σ1 and σ2 are unknown we use s1 and s2 instead and use the t-testwith a level α

a H0 micro1 minus micro2 = 0 and Ha micro1 minus micro2 6= 0

b Test statistic T0 is

T0 =(X1 minus X2)minus (micro1 minus micro2)radic

s21n1

+s22n2

c (Modified Version) We can find the critical value tlowastk such that

P(T gt tlowastk ) =α

2

where k = min(n1 minus 1 n2 minus 1)

d Compare |T0| with the value tlowastk (|T0| gt tlowastk rArr Reject the null)

Kwonsang Lee STAT111 April 3 2015 9 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

Two-Sample t-test with a level α = 005

a H0 microtreated minus microcontrol = 0 and Ha microt minus microc 6= 0

b Test statistic T0 is given by

T0 =(Xt minus Xc)minus (microt minus microc)radic

s2tnt

+ s2cnc

=(515minus 415)minus 0radic

112

21 + 172

23

= 2336

c Conservatively degree of freedom k is min(nt minus 1 nc minus 1) = 20 Thecritical value tlowastk is 2086

P(T gt tlowast20) =α

2= 0025

d Since |T0| = 2336 gt 2086 = tlowast20 we reject the null hypothesis

t-table rArr http

bcswhfreemancomips6econtentcat_050ips6e_table-dpdf

Kwonsang Lee STAT111 April 3 2015 11 22

Two-Sample t-test in JMP

Here are the references for t-test

One-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_one_sample_t-testpdf

Two-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_two_sample_t-testpdf

Steps for two-sample t-test

1 Open the data file

2 Go to Analyze rarr Fit Y by X For example Y is a score variable andX is an indicator of either lsquotreatedrsquo or lsquocontrolrsquo

3 Click the red triangle next to lsquoOneway Analysis of rsquo and chooset-test

Kwonsang Lee STAT111 April 3 2015 12 22

Using JMP

We can find the descriptions of each sample We also find a confidenceinterval of micro1 minus micro2 and the results of Two-sample t-test

Using JMP we can compute the p-value of our test statistic T0 in theprevious Example 1 The P-value is 00264 which is less than 005 so wereject the null hypothesis

Here is another reference relate with Example 1httpwebutkedu~cwiek201TutorialsTwoSampleTtest

Kwonsang Lee STAT111 April 3 2015 13 22

Confidence Interval from Two-Sample

We can consider two cases 1) Known σ1 and σ2 case and 2) Unknown σ1and σ2 case

Confidence interval of lsquomicro1 minus micro2rsquo with known σ1 and σ2

(X1 minus X2)plusmn Z lowast

radicσ21n1

+σ22n2

Confidence interval of lsquomicro1 minus micro2rsquo with unknown σ1 and σ2

(X1 minus X2)plusmn tlowastk

radics21n1

+s22n2

where k = min(n1 minus 1 n2 minus 1)

Kwonsang Lee STAT111 April 3 2015 14 22

Special Case Matched Pairs

Sometimes the two samples that are being compared are matched pairs

For example if there is a drug A and it can lower blood pressure Eachsubjectrsquos blood pressure is measured before taking the drug and ismeasured after intake One subject has two values of the outcome Thenwe want to test if there is any difference between blood pressure beforeintake and blood pressure after intake

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

We want to test if blood pressure before = blood pressure after

Kwonsang Lee STAT111 April 3 2015 15 22

Matched Pairs

In this case we can compute the difference D = X1 minus X2 HereDiff=BeforeminusAfter

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

Diff 14 18 18

Then we can use a test like H0 Diff = 0 This is lsquoOne-Sample t-testrsquo

Kwonsang Lee STAT111 April 3 2015 16 22

Matched Pairs Test

From Matched pairs design we have X1 and X2 for n subjects Then wecompute the new variable D = X1 minus X2 and compute the sample meanand the sample SD of D Xd and sd

Then we can state the null hypothesis H0 microd = 0 and the alternativeHa microd 6= 0 We calculate the test statistic T0

T0 =Xd minus microdsdradicn

Then we can calculate the critical value tlowastnminus1 and compare it with the teststatistic T0

Kwonsang Lee STAT111 April 3 2015 17 22

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 2: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Inference from One-Sample

We have two options to make an inference about population mean micro fromone sample of size n1) 100(1-C) Confidence interval and2) Hypothesis test with a level α

1) 100(1-C) Confidence IntervalWe need to consider the case when σ is known or unknown

a Known σ(X minus Zlowast σradic

n X + Zlowast σradic

n)

b Unknown σ(X minus tlowastnminus1

sradicn X + tlowastnminus1

sradicn

)

Kwonsang Lee STAT111 April 3 2015 2 22

Inference from One-Sample

2) Hypothesis test with a level α

a State the null and alternative hypotheses (Here two-sided example)

H0 micro = micro0 and Ha micro 6= micro0

b Calculate a test statistic Z0 (known σ) or a test statistic T0 (unknownσ)

Z0 =X minus micro0

σradicn

or T0 =X minus micro0

sradicn

c Calculate the P-value

P-value =

2times P(Z ge |Z0|) σ is known

2times P(T ge |T0|) σ is unknown

d Compare the P-value to the significance level α

Kwonsang Lee STAT111 April 3 2015 3 22

Supplement of t-test (Two-sided test)

Because t-table doesnrsquot give the P-value we can modify our t-testInstead of computing P-value we can find the value tlowastnminus1 such that

P(T gt tlowastnminus1) =α

2

Then

Conclusion =

We reject the null if |T0| ge tlowastnminus1We donrsquot reject the null if |T0| lt tlowastnminus1

Note If one-sided alternative hypothesis is Ha micro gt 0 we need to find thevalue tlowastnminus1 such that P(T gt tlowastnminus1) = α We reject the null if T0 gt tlowastnminus1Also if Ha micro lt 0 we need to use tlowastnminus1 such that P(T lt tlowastnminus1) = α Wereject the null if T0 lt tlowastnminus1 Draw the t-distribution and think about it

Kwonsang Lee STAT111 April 3 2015 4 22

New Terminology Standard Error

X is from the population with mean micro and SD σ We take a sample ofsize n from the population and say X1 Xn

What we learned

A sample (X1 Xn) has the sample mean X and the sample SD s

The sample mean X has the distribution with mean micro and SD σradicn

New terminology

Standard error of X is sradicn

ie SE(X ) = sradicn

Kwonsang Lee STAT111 April 3 2015 5 22

Two-Sample Example

Letrsquos assume that we want to study about household incomes inPhiladelphia and New York

Philadelphia income dist rArr mean microp and SD σp

New York income dist rArr mean micron and SD σn

Then we take a Philadelphia sample of size np and a New York sample ofsize nn

Phila sample rArr sample mean xp and sample SD sp

NY sample rArr sample mean xn and sample SD sn

What to do We want to compare microp with micron

1) Hypothesis test of microp = micron

2) Confidence interval of microp minus micron

Kwonsang Lee STAT111 April 3 2015 6 22

Inference from Two-Sample Intro

We donrsquot know the values of micro1 and micro2 We want to make inferences fromSample 1 and Sample 2

We can conduct a hypothesis test or construct a confidence interval for microAlso we need to consider the case when σ1 and σ2 are known or unknown

1) Hypothesis test of micro1 = micro2 or micro1 minus micro2 = 0

2) Confidence interval of micro1 minus micro2

Kwonsang Lee STAT111 April 3 2015 7 22

Two-Sample Hypothesis Test Known σ1 and σ2

Since σ1 and σ2 are known we can take the Z test

a H0 micro1 minus micro2 = 0 and Ha micro1 minus micro2 6= 0

b Test statistic Z0 is

Z0 =(X1 minus X2)minus (micro1 minus micro2)radic

σ21

n1+

σ22

n2

c P-value is

P(Z le minus|Z0|) + P(Z ge |Z0|) = 2times P(Z ge |Z0|)

d Compare P-value with a level α

Kwonsang Lee STAT111 April 3 2015 8 22

Two-Sample Hypothesis Test Unknown σ1 and σ2

Since σ1 and σ2 are unknown we use s1 and s2 instead and use the t-testwith a level α

a H0 micro1 minus micro2 = 0 and Ha micro1 minus micro2 6= 0

b Test statistic T0 is

T0 =(X1 minus X2)minus (micro1 minus micro2)radic

s21n1

+s22n2

c (Modified Version) We can find the critical value tlowastk such that

P(T gt tlowastk ) =α

2

where k = min(n1 minus 1 n2 minus 1)

d Compare |T0| with the value tlowastk (|T0| gt tlowastk rArr Reject the null)

Kwonsang Lee STAT111 April 3 2015 9 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

Two-Sample t-test with a level α = 005

a H0 microtreated minus microcontrol = 0 and Ha microt minus microc 6= 0

b Test statistic T0 is given by

T0 =(Xt minus Xc)minus (microt minus microc)radic

s2tnt

+ s2cnc

=(515minus 415)minus 0radic

112

21 + 172

23

= 2336

c Conservatively degree of freedom k is min(nt minus 1 nc minus 1) = 20 Thecritical value tlowastk is 2086

P(T gt tlowast20) =α

2= 0025

d Since |T0| = 2336 gt 2086 = tlowast20 we reject the null hypothesis

t-table rArr http

bcswhfreemancomips6econtentcat_050ips6e_table-dpdf

Kwonsang Lee STAT111 April 3 2015 11 22

Two-Sample t-test in JMP

Here are the references for t-test

One-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_one_sample_t-testpdf

Two-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_two_sample_t-testpdf

Steps for two-sample t-test

1 Open the data file

2 Go to Analyze rarr Fit Y by X For example Y is a score variable andX is an indicator of either lsquotreatedrsquo or lsquocontrolrsquo

3 Click the red triangle next to lsquoOneway Analysis of rsquo and chooset-test

Kwonsang Lee STAT111 April 3 2015 12 22

Using JMP

We can find the descriptions of each sample We also find a confidenceinterval of micro1 minus micro2 and the results of Two-sample t-test

Using JMP we can compute the p-value of our test statistic T0 in theprevious Example 1 The P-value is 00264 which is less than 005 so wereject the null hypothesis

Here is another reference relate with Example 1httpwebutkedu~cwiek201TutorialsTwoSampleTtest

Kwonsang Lee STAT111 April 3 2015 13 22

Confidence Interval from Two-Sample

We can consider two cases 1) Known σ1 and σ2 case and 2) Unknown σ1and σ2 case

Confidence interval of lsquomicro1 minus micro2rsquo with known σ1 and σ2

(X1 minus X2)plusmn Z lowast

radicσ21n1

+σ22n2

Confidence interval of lsquomicro1 minus micro2rsquo with unknown σ1 and σ2

(X1 minus X2)plusmn tlowastk

radics21n1

+s22n2

where k = min(n1 minus 1 n2 minus 1)

Kwonsang Lee STAT111 April 3 2015 14 22

Special Case Matched Pairs

Sometimes the two samples that are being compared are matched pairs

For example if there is a drug A and it can lower blood pressure Eachsubjectrsquos blood pressure is measured before taking the drug and ismeasured after intake One subject has two values of the outcome Thenwe want to test if there is any difference between blood pressure beforeintake and blood pressure after intake

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

We want to test if blood pressure before = blood pressure after

Kwonsang Lee STAT111 April 3 2015 15 22

Matched Pairs

In this case we can compute the difference D = X1 minus X2 HereDiff=BeforeminusAfter

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

Diff 14 18 18

Then we can use a test like H0 Diff = 0 This is lsquoOne-Sample t-testrsquo

Kwonsang Lee STAT111 April 3 2015 16 22

Matched Pairs Test

From Matched pairs design we have X1 and X2 for n subjects Then wecompute the new variable D = X1 minus X2 and compute the sample meanand the sample SD of D Xd and sd

Then we can state the null hypothesis H0 microd = 0 and the alternativeHa microd 6= 0 We calculate the test statistic T0

T0 =Xd minus microdsdradicn

Then we can calculate the critical value tlowastnminus1 and compare it with the teststatistic T0

Kwonsang Lee STAT111 April 3 2015 17 22

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 3: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Inference from One-Sample

2) Hypothesis test with a level α

a State the null and alternative hypotheses (Here two-sided example)

H0 micro = micro0 and Ha micro 6= micro0

b Calculate a test statistic Z0 (known σ) or a test statistic T0 (unknownσ)

Z0 =X minus micro0

σradicn

or T0 =X minus micro0

sradicn

c Calculate the P-value

P-value =

2times P(Z ge |Z0|) σ is known

2times P(T ge |T0|) σ is unknown

d Compare the P-value to the significance level α

Kwonsang Lee STAT111 April 3 2015 3 22

Supplement of t-test (Two-sided test)

Because t-table doesnrsquot give the P-value we can modify our t-testInstead of computing P-value we can find the value tlowastnminus1 such that

P(T gt tlowastnminus1) =α

2

Then

Conclusion =

We reject the null if |T0| ge tlowastnminus1We donrsquot reject the null if |T0| lt tlowastnminus1

Note If one-sided alternative hypothesis is Ha micro gt 0 we need to find thevalue tlowastnminus1 such that P(T gt tlowastnminus1) = α We reject the null if T0 gt tlowastnminus1Also if Ha micro lt 0 we need to use tlowastnminus1 such that P(T lt tlowastnminus1) = α Wereject the null if T0 lt tlowastnminus1 Draw the t-distribution and think about it

Kwonsang Lee STAT111 April 3 2015 4 22

New Terminology Standard Error

X is from the population with mean micro and SD σ We take a sample ofsize n from the population and say X1 Xn

What we learned

A sample (X1 Xn) has the sample mean X and the sample SD s

The sample mean X has the distribution with mean micro and SD σradicn

New terminology

Standard error of X is sradicn

ie SE(X ) = sradicn

Kwonsang Lee STAT111 April 3 2015 5 22

Two-Sample Example

Letrsquos assume that we want to study about household incomes inPhiladelphia and New York

Philadelphia income dist rArr mean microp and SD σp

New York income dist rArr mean micron and SD σn

Then we take a Philadelphia sample of size np and a New York sample ofsize nn

Phila sample rArr sample mean xp and sample SD sp

NY sample rArr sample mean xn and sample SD sn

What to do We want to compare microp with micron

1) Hypothesis test of microp = micron

2) Confidence interval of microp minus micron

Kwonsang Lee STAT111 April 3 2015 6 22

Inference from Two-Sample Intro

We donrsquot know the values of micro1 and micro2 We want to make inferences fromSample 1 and Sample 2

We can conduct a hypothesis test or construct a confidence interval for microAlso we need to consider the case when σ1 and σ2 are known or unknown

1) Hypothesis test of micro1 = micro2 or micro1 minus micro2 = 0

2) Confidence interval of micro1 minus micro2

Kwonsang Lee STAT111 April 3 2015 7 22

Two-Sample Hypothesis Test Known σ1 and σ2

Since σ1 and σ2 are known we can take the Z test

a H0 micro1 minus micro2 = 0 and Ha micro1 minus micro2 6= 0

b Test statistic Z0 is

Z0 =(X1 minus X2)minus (micro1 minus micro2)radic

σ21

n1+

σ22

n2

c P-value is

P(Z le minus|Z0|) + P(Z ge |Z0|) = 2times P(Z ge |Z0|)

d Compare P-value with a level α

Kwonsang Lee STAT111 April 3 2015 8 22

Two-Sample Hypothesis Test Unknown σ1 and σ2

Since σ1 and σ2 are unknown we use s1 and s2 instead and use the t-testwith a level α

a H0 micro1 minus micro2 = 0 and Ha micro1 minus micro2 6= 0

b Test statistic T0 is

T0 =(X1 minus X2)minus (micro1 minus micro2)radic

s21n1

+s22n2

c (Modified Version) We can find the critical value tlowastk such that

P(T gt tlowastk ) =α

2

where k = min(n1 minus 1 n2 minus 1)

d Compare |T0| with the value tlowastk (|T0| gt tlowastk rArr Reject the null)

Kwonsang Lee STAT111 April 3 2015 9 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

Two-Sample t-test with a level α = 005

a H0 microtreated minus microcontrol = 0 and Ha microt minus microc 6= 0

b Test statistic T0 is given by

T0 =(Xt minus Xc)minus (microt minus microc)radic

s2tnt

+ s2cnc

=(515minus 415)minus 0radic

112

21 + 172

23

= 2336

c Conservatively degree of freedom k is min(nt minus 1 nc minus 1) = 20 Thecritical value tlowastk is 2086

P(T gt tlowast20) =α

2= 0025

d Since |T0| = 2336 gt 2086 = tlowast20 we reject the null hypothesis

t-table rArr http

bcswhfreemancomips6econtentcat_050ips6e_table-dpdf

Kwonsang Lee STAT111 April 3 2015 11 22

Two-Sample t-test in JMP

Here are the references for t-test

One-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_one_sample_t-testpdf

Two-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_two_sample_t-testpdf

Steps for two-sample t-test

1 Open the data file

2 Go to Analyze rarr Fit Y by X For example Y is a score variable andX is an indicator of either lsquotreatedrsquo or lsquocontrolrsquo

3 Click the red triangle next to lsquoOneway Analysis of rsquo and chooset-test

Kwonsang Lee STAT111 April 3 2015 12 22

Using JMP

We can find the descriptions of each sample We also find a confidenceinterval of micro1 minus micro2 and the results of Two-sample t-test

Using JMP we can compute the p-value of our test statistic T0 in theprevious Example 1 The P-value is 00264 which is less than 005 so wereject the null hypothesis

Here is another reference relate with Example 1httpwebutkedu~cwiek201TutorialsTwoSampleTtest

Kwonsang Lee STAT111 April 3 2015 13 22

Confidence Interval from Two-Sample

We can consider two cases 1) Known σ1 and σ2 case and 2) Unknown σ1and σ2 case

Confidence interval of lsquomicro1 minus micro2rsquo with known σ1 and σ2

(X1 minus X2)plusmn Z lowast

radicσ21n1

+σ22n2

Confidence interval of lsquomicro1 minus micro2rsquo with unknown σ1 and σ2

(X1 minus X2)plusmn tlowastk

radics21n1

+s22n2

where k = min(n1 minus 1 n2 minus 1)

Kwonsang Lee STAT111 April 3 2015 14 22

Special Case Matched Pairs

Sometimes the two samples that are being compared are matched pairs

For example if there is a drug A and it can lower blood pressure Eachsubjectrsquos blood pressure is measured before taking the drug and ismeasured after intake One subject has two values of the outcome Thenwe want to test if there is any difference between blood pressure beforeintake and blood pressure after intake

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

We want to test if blood pressure before = blood pressure after

Kwonsang Lee STAT111 April 3 2015 15 22

Matched Pairs

In this case we can compute the difference D = X1 minus X2 HereDiff=BeforeminusAfter

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

Diff 14 18 18

Then we can use a test like H0 Diff = 0 This is lsquoOne-Sample t-testrsquo

Kwonsang Lee STAT111 April 3 2015 16 22

Matched Pairs Test

From Matched pairs design we have X1 and X2 for n subjects Then wecompute the new variable D = X1 minus X2 and compute the sample meanand the sample SD of D Xd and sd

Then we can state the null hypothesis H0 microd = 0 and the alternativeHa microd 6= 0 We calculate the test statistic T0

T0 =Xd minus microdsdradicn

Then we can calculate the critical value tlowastnminus1 and compare it with the teststatistic T0

Kwonsang Lee STAT111 April 3 2015 17 22

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 4: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Supplement of t-test (Two-sided test)

Because t-table doesnrsquot give the P-value we can modify our t-testInstead of computing P-value we can find the value tlowastnminus1 such that

P(T gt tlowastnminus1) =α

2

Then

Conclusion =

We reject the null if |T0| ge tlowastnminus1We donrsquot reject the null if |T0| lt tlowastnminus1

Note If one-sided alternative hypothesis is Ha micro gt 0 we need to find thevalue tlowastnminus1 such that P(T gt tlowastnminus1) = α We reject the null if T0 gt tlowastnminus1Also if Ha micro lt 0 we need to use tlowastnminus1 such that P(T lt tlowastnminus1) = α Wereject the null if T0 lt tlowastnminus1 Draw the t-distribution and think about it

Kwonsang Lee STAT111 April 3 2015 4 22

New Terminology Standard Error

X is from the population with mean micro and SD σ We take a sample ofsize n from the population and say X1 Xn

What we learned

A sample (X1 Xn) has the sample mean X and the sample SD s

The sample mean X has the distribution with mean micro and SD σradicn

New terminology

Standard error of X is sradicn

ie SE(X ) = sradicn

Kwonsang Lee STAT111 April 3 2015 5 22

Two-Sample Example

Letrsquos assume that we want to study about household incomes inPhiladelphia and New York

Philadelphia income dist rArr mean microp and SD σp

New York income dist rArr mean micron and SD σn

Then we take a Philadelphia sample of size np and a New York sample ofsize nn

Phila sample rArr sample mean xp and sample SD sp

NY sample rArr sample mean xn and sample SD sn

What to do We want to compare microp with micron

1) Hypothesis test of microp = micron

2) Confidence interval of microp minus micron

Kwonsang Lee STAT111 April 3 2015 6 22

Inference from Two-Sample Intro

We donrsquot know the values of micro1 and micro2 We want to make inferences fromSample 1 and Sample 2

We can conduct a hypothesis test or construct a confidence interval for microAlso we need to consider the case when σ1 and σ2 are known or unknown

1) Hypothesis test of micro1 = micro2 or micro1 minus micro2 = 0

2) Confidence interval of micro1 minus micro2

Kwonsang Lee STAT111 April 3 2015 7 22

Two-Sample Hypothesis Test Known σ1 and σ2

Since σ1 and σ2 are known we can take the Z test

a H0 micro1 minus micro2 = 0 and Ha micro1 minus micro2 6= 0

b Test statistic Z0 is

Z0 =(X1 minus X2)minus (micro1 minus micro2)radic

σ21

n1+

σ22

n2

c P-value is

P(Z le minus|Z0|) + P(Z ge |Z0|) = 2times P(Z ge |Z0|)

d Compare P-value with a level α

Kwonsang Lee STAT111 April 3 2015 8 22

Two-Sample Hypothesis Test Unknown σ1 and σ2

Since σ1 and σ2 are unknown we use s1 and s2 instead and use the t-testwith a level α

a H0 micro1 minus micro2 = 0 and Ha micro1 minus micro2 6= 0

b Test statistic T0 is

T0 =(X1 minus X2)minus (micro1 minus micro2)radic

s21n1

+s22n2

c (Modified Version) We can find the critical value tlowastk such that

P(T gt tlowastk ) =α

2

where k = min(n1 minus 1 n2 minus 1)

d Compare |T0| with the value tlowastk (|T0| gt tlowastk rArr Reject the null)

Kwonsang Lee STAT111 April 3 2015 9 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

Two-Sample t-test with a level α = 005

a H0 microtreated minus microcontrol = 0 and Ha microt minus microc 6= 0

b Test statistic T0 is given by

T0 =(Xt minus Xc)minus (microt minus microc)radic

s2tnt

+ s2cnc

=(515minus 415)minus 0radic

112

21 + 172

23

= 2336

c Conservatively degree of freedom k is min(nt minus 1 nc minus 1) = 20 Thecritical value tlowastk is 2086

P(T gt tlowast20) =α

2= 0025

d Since |T0| = 2336 gt 2086 = tlowast20 we reject the null hypothesis

t-table rArr http

bcswhfreemancomips6econtentcat_050ips6e_table-dpdf

Kwonsang Lee STAT111 April 3 2015 11 22

Two-Sample t-test in JMP

Here are the references for t-test

One-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_one_sample_t-testpdf

Two-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_two_sample_t-testpdf

Steps for two-sample t-test

1 Open the data file

2 Go to Analyze rarr Fit Y by X For example Y is a score variable andX is an indicator of either lsquotreatedrsquo or lsquocontrolrsquo

3 Click the red triangle next to lsquoOneway Analysis of rsquo and chooset-test

Kwonsang Lee STAT111 April 3 2015 12 22

Using JMP

We can find the descriptions of each sample We also find a confidenceinterval of micro1 minus micro2 and the results of Two-sample t-test

Using JMP we can compute the p-value of our test statistic T0 in theprevious Example 1 The P-value is 00264 which is less than 005 so wereject the null hypothesis

Here is another reference relate with Example 1httpwebutkedu~cwiek201TutorialsTwoSampleTtest

Kwonsang Lee STAT111 April 3 2015 13 22

Confidence Interval from Two-Sample

We can consider two cases 1) Known σ1 and σ2 case and 2) Unknown σ1and σ2 case

Confidence interval of lsquomicro1 minus micro2rsquo with known σ1 and σ2

(X1 minus X2)plusmn Z lowast

radicσ21n1

+σ22n2

Confidence interval of lsquomicro1 minus micro2rsquo with unknown σ1 and σ2

(X1 minus X2)plusmn tlowastk

radics21n1

+s22n2

where k = min(n1 minus 1 n2 minus 1)

Kwonsang Lee STAT111 April 3 2015 14 22

Special Case Matched Pairs

Sometimes the two samples that are being compared are matched pairs

For example if there is a drug A and it can lower blood pressure Eachsubjectrsquos blood pressure is measured before taking the drug and ismeasured after intake One subject has two values of the outcome Thenwe want to test if there is any difference between blood pressure beforeintake and blood pressure after intake

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

We want to test if blood pressure before = blood pressure after

Kwonsang Lee STAT111 April 3 2015 15 22

Matched Pairs

In this case we can compute the difference D = X1 minus X2 HereDiff=BeforeminusAfter

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

Diff 14 18 18

Then we can use a test like H0 Diff = 0 This is lsquoOne-Sample t-testrsquo

Kwonsang Lee STAT111 April 3 2015 16 22

Matched Pairs Test

From Matched pairs design we have X1 and X2 for n subjects Then wecompute the new variable D = X1 minus X2 and compute the sample meanand the sample SD of D Xd and sd

Then we can state the null hypothesis H0 microd = 0 and the alternativeHa microd 6= 0 We calculate the test statistic T0

T0 =Xd minus microdsdradicn

Then we can calculate the critical value tlowastnminus1 and compare it with the teststatistic T0

Kwonsang Lee STAT111 April 3 2015 17 22

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 5: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

New Terminology Standard Error

X is from the population with mean micro and SD σ We take a sample ofsize n from the population and say X1 Xn

What we learned

A sample (X1 Xn) has the sample mean X and the sample SD s

The sample mean X has the distribution with mean micro and SD σradicn

New terminology

Standard error of X is sradicn

ie SE(X ) = sradicn

Kwonsang Lee STAT111 April 3 2015 5 22

Two-Sample Example

Letrsquos assume that we want to study about household incomes inPhiladelphia and New York

Philadelphia income dist rArr mean microp and SD σp

New York income dist rArr mean micron and SD σn

Then we take a Philadelphia sample of size np and a New York sample ofsize nn

Phila sample rArr sample mean xp and sample SD sp

NY sample rArr sample mean xn and sample SD sn

What to do We want to compare microp with micron

1) Hypothesis test of microp = micron

2) Confidence interval of microp minus micron

Kwonsang Lee STAT111 April 3 2015 6 22

Inference from Two-Sample Intro

We donrsquot know the values of micro1 and micro2 We want to make inferences fromSample 1 and Sample 2

We can conduct a hypothesis test or construct a confidence interval for microAlso we need to consider the case when σ1 and σ2 are known or unknown

1) Hypothesis test of micro1 = micro2 or micro1 minus micro2 = 0

2) Confidence interval of micro1 minus micro2

Kwonsang Lee STAT111 April 3 2015 7 22

Two-Sample Hypothesis Test Known σ1 and σ2

Since σ1 and σ2 are known we can take the Z test

a H0 micro1 minus micro2 = 0 and Ha micro1 minus micro2 6= 0

b Test statistic Z0 is

Z0 =(X1 minus X2)minus (micro1 minus micro2)radic

σ21

n1+

σ22

n2

c P-value is

P(Z le minus|Z0|) + P(Z ge |Z0|) = 2times P(Z ge |Z0|)

d Compare P-value with a level α

Kwonsang Lee STAT111 April 3 2015 8 22

Two-Sample Hypothesis Test Unknown σ1 and σ2

Since σ1 and σ2 are unknown we use s1 and s2 instead and use the t-testwith a level α

a H0 micro1 minus micro2 = 0 and Ha micro1 minus micro2 6= 0

b Test statistic T0 is

T0 =(X1 minus X2)minus (micro1 minus micro2)radic

s21n1

+s22n2

c (Modified Version) We can find the critical value tlowastk such that

P(T gt tlowastk ) =α

2

where k = min(n1 minus 1 n2 minus 1)

d Compare |T0| with the value tlowastk (|T0| gt tlowastk rArr Reject the null)

Kwonsang Lee STAT111 April 3 2015 9 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

Two-Sample t-test with a level α = 005

a H0 microtreated minus microcontrol = 0 and Ha microt minus microc 6= 0

b Test statistic T0 is given by

T0 =(Xt minus Xc)minus (microt minus microc)radic

s2tnt

+ s2cnc

=(515minus 415)minus 0radic

112

21 + 172

23

= 2336

c Conservatively degree of freedom k is min(nt minus 1 nc minus 1) = 20 Thecritical value tlowastk is 2086

P(T gt tlowast20) =α

2= 0025

d Since |T0| = 2336 gt 2086 = tlowast20 we reject the null hypothesis

t-table rArr http

bcswhfreemancomips6econtentcat_050ips6e_table-dpdf

Kwonsang Lee STAT111 April 3 2015 11 22

Two-Sample t-test in JMP

Here are the references for t-test

One-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_one_sample_t-testpdf

Two-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_two_sample_t-testpdf

Steps for two-sample t-test

1 Open the data file

2 Go to Analyze rarr Fit Y by X For example Y is a score variable andX is an indicator of either lsquotreatedrsquo or lsquocontrolrsquo

3 Click the red triangle next to lsquoOneway Analysis of rsquo and chooset-test

Kwonsang Lee STAT111 April 3 2015 12 22

Using JMP

We can find the descriptions of each sample We also find a confidenceinterval of micro1 minus micro2 and the results of Two-sample t-test

Using JMP we can compute the p-value of our test statistic T0 in theprevious Example 1 The P-value is 00264 which is less than 005 so wereject the null hypothesis

Here is another reference relate with Example 1httpwebutkedu~cwiek201TutorialsTwoSampleTtest

Kwonsang Lee STAT111 April 3 2015 13 22

Confidence Interval from Two-Sample

We can consider two cases 1) Known σ1 and σ2 case and 2) Unknown σ1and σ2 case

Confidence interval of lsquomicro1 minus micro2rsquo with known σ1 and σ2

(X1 minus X2)plusmn Z lowast

radicσ21n1

+σ22n2

Confidence interval of lsquomicro1 minus micro2rsquo with unknown σ1 and σ2

(X1 minus X2)plusmn tlowastk

radics21n1

+s22n2

where k = min(n1 minus 1 n2 minus 1)

Kwonsang Lee STAT111 April 3 2015 14 22

Special Case Matched Pairs

Sometimes the two samples that are being compared are matched pairs

For example if there is a drug A and it can lower blood pressure Eachsubjectrsquos blood pressure is measured before taking the drug and ismeasured after intake One subject has two values of the outcome Thenwe want to test if there is any difference between blood pressure beforeintake and blood pressure after intake

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

We want to test if blood pressure before = blood pressure after

Kwonsang Lee STAT111 April 3 2015 15 22

Matched Pairs

In this case we can compute the difference D = X1 minus X2 HereDiff=BeforeminusAfter

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

Diff 14 18 18

Then we can use a test like H0 Diff = 0 This is lsquoOne-Sample t-testrsquo

Kwonsang Lee STAT111 April 3 2015 16 22

Matched Pairs Test

From Matched pairs design we have X1 and X2 for n subjects Then wecompute the new variable D = X1 minus X2 and compute the sample meanand the sample SD of D Xd and sd

Then we can state the null hypothesis H0 microd = 0 and the alternativeHa microd 6= 0 We calculate the test statistic T0

T0 =Xd minus microdsdradicn

Then we can calculate the critical value tlowastnminus1 and compare it with the teststatistic T0

Kwonsang Lee STAT111 April 3 2015 17 22

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 6: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Two-Sample Example

Letrsquos assume that we want to study about household incomes inPhiladelphia and New York

Philadelphia income dist rArr mean microp and SD σp

New York income dist rArr mean micron and SD σn

Then we take a Philadelphia sample of size np and a New York sample ofsize nn

Phila sample rArr sample mean xp and sample SD sp

NY sample rArr sample mean xn and sample SD sn

What to do We want to compare microp with micron

1) Hypothesis test of microp = micron

2) Confidence interval of microp minus micron

Kwonsang Lee STAT111 April 3 2015 6 22

Inference from Two-Sample Intro

We donrsquot know the values of micro1 and micro2 We want to make inferences fromSample 1 and Sample 2

We can conduct a hypothesis test or construct a confidence interval for microAlso we need to consider the case when σ1 and σ2 are known or unknown

1) Hypothesis test of micro1 = micro2 or micro1 minus micro2 = 0

2) Confidence interval of micro1 minus micro2

Kwonsang Lee STAT111 April 3 2015 7 22

Two-Sample Hypothesis Test Known σ1 and σ2

Since σ1 and σ2 are known we can take the Z test

a H0 micro1 minus micro2 = 0 and Ha micro1 minus micro2 6= 0

b Test statistic Z0 is

Z0 =(X1 minus X2)minus (micro1 minus micro2)radic

σ21

n1+

σ22

n2

c P-value is

P(Z le minus|Z0|) + P(Z ge |Z0|) = 2times P(Z ge |Z0|)

d Compare P-value with a level α

Kwonsang Lee STAT111 April 3 2015 8 22

Two-Sample Hypothesis Test Unknown σ1 and σ2

Since σ1 and σ2 are unknown we use s1 and s2 instead and use the t-testwith a level α

a H0 micro1 minus micro2 = 0 and Ha micro1 minus micro2 6= 0

b Test statistic T0 is

T0 =(X1 minus X2)minus (micro1 minus micro2)radic

s21n1

+s22n2

c (Modified Version) We can find the critical value tlowastk such that

P(T gt tlowastk ) =α

2

where k = min(n1 minus 1 n2 minus 1)

d Compare |T0| with the value tlowastk (|T0| gt tlowastk rArr Reject the null)

Kwonsang Lee STAT111 April 3 2015 9 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

Two-Sample t-test with a level α = 005

a H0 microtreated minus microcontrol = 0 and Ha microt minus microc 6= 0

b Test statistic T0 is given by

T0 =(Xt minus Xc)minus (microt minus microc)radic

s2tnt

+ s2cnc

=(515minus 415)minus 0radic

112

21 + 172

23

= 2336

c Conservatively degree of freedom k is min(nt minus 1 nc minus 1) = 20 Thecritical value tlowastk is 2086

P(T gt tlowast20) =α

2= 0025

d Since |T0| = 2336 gt 2086 = tlowast20 we reject the null hypothesis

t-table rArr http

bcswhfreemancomips6econtentcat_050ips6e_table-dpdf

Kwonsang Lee STAT111 April 3 2015 11 22

Two-Sample t-test in JMP

Here are the references for t-test

One-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_one_sample_t-testpdf

Two-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_two_sample_t-testpdf

Steps for two-sample t-test

1 Open the data file

2 Go to Analyze rarr Fit Y by X For example Y is a score variable andX is an indicator of either lsquotreatedrsquo or lsquocontrolrsquo

3 Click the red triangle next to lsquoOneway Analysis of rsquo and chooset-test

Kwonsang Lee STAT111 April 3 2015 12 22

Using JMP

We can find the descriptions of each sample We also find a confidenceinterval of micro1 minus micro2 and the results of Two-sample t-test

Using JMP we can compute the p-value of our test statistic T0 in theprevious Example 1 The P-value is 00264 which is less than 005 so wereject the null hypothesis

Here is another reference relate with Example 1httpwebutkedu~cwiek201TutorialsTwoSampleTtest

Kwonsang Lee STAT111 April 3 2015 13 22

Confidence Interval from Two-Sample

We can consider two cases 1) Known σ1 and σ2 case and 2) Unknown σ1and σ2 case

Confidence interval of lsquomicro1 minus micro2rsquo with known σ1 and σ2

(X1 minus X2)plusmn Z lowast

radicσ21n1

+σ22n2

Confidence interval of lsquomicro1 minus micro2rsquo with unknown σ1 and σ2

(X1 minus X2)plusmn tlowastk

radics21n1

+s22n2

where k = min(n1 minus 1 n2 minus 1)

Kwonsang Lee STAT111 April 3 2015 14 22

Special Case Matched Pairs

Sometimes the two samples that are being compared are matched pairs

For example if there is a drug A and it can lower blood pressure Eachsubjectrsquos blood pressure is measured before taking the drug and ismeasured after intake One subject has two values of the outcome Thenwe want to test if there is any difference between blood pressure beforeintake and blood pressure after intake

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

We want to test if blood pressure before = blood pressure after

Kwonsang Lee STAT111 April 3 2015 15 22

Matched Pairs

In this case we can compute the difference D = X1 minus X2 HereDiff=BeforeminusAfter

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

Diff 14 18 18

Then we can use a test like H0 Diff = 0 This is lsquoOne-Sample t-testrsquo

Kwonsang Lee STAT111 April 3 2015 16 22

Matched Pairs Test

From Matched pairs design we have X1 and X2 for n subjects Then wecompute the new variable D = X1 minus X2 and compute the sample meanand the sample SD of D Xd and sd

Then we can state the null hypothesis H0 microd = 0 and the alternativeHa microd 6= 0 We calculate the test statistic T0

T0 =Xd minus microdsdradicn

Then we can calculate the critical value tlowastnminus1 and compare it with the teststatistic T0

Kwonsang Lee STAT111 April 3 2015 17 22

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 7: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Inference from Two-Sample Intro

We donrsquot know the values of micro1 and micro2 We want to make inferences fromSample 1 and Sample 2

We can conduct a hypothesis test or construct a confidence interval for microAlso we need to consider the case when σ1 and σ2 are known or unknown

1) Hypothesis test of micro1 = micro2 or micro1 minus micro2 = 0

2) Confidence interval of micro1 minus micro2

Kwonsang Lee STAT111 April 3 2015 7 22

Two-Sample Hypothesis Test Known σ1 and σ2

Since σ1 and σ2 are known we can take the Z test

a H0 micro1 minus micro2 = 0 and Ha micro1 minus micro2 6= 0

b Test statistic Z0 is

Z0 =(X1 minus X2)minus (micro1 minus micro2)radic

σ21

n1+

σ22

n2

c P-value is

P(Z le minus|Z0|) + P(Z ge |Z0|) = 2times P(Z ge |Z0|)

d Compare P-value with a level α

Kwonsang Lee STAT111 April 3 2015 8 22

Two-Sample Hypothesis Test Unknown σ1 and σ2

Since σ1 and σ2 are unknown we use s1 and s2 instead and use the t-testwith a level α

a H0 micro1 minus micro2 = 0 and Ha micro1 minus micro2 6= 0

b Test statistic T0 is

T0 =(X1 minus X2)minus (micro1 minus micro2)radic

s21n1

+s22n2

c (Modified Version) We can find the critical value tlowastk such that

P(T gt tlowastk ) =α

2

where k = min(n1 minus 1 n2 minus 1)

d Compare |T0| with the value tlowastk (|T0| gt tlowastk rArr Reject the null)

Kwonsang Lee STAT111 April 3 2015 9 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

Two-Sample t-test with a level α = 005

a H0 microtreated minus microcontrol = 0 and Ha microt minus microc 6= 0

b Test statistic T0 is given by

T0 =(Xt minus Xc)minus (microt minus microc)radic

s2tnt

+ s2cnc

=(515minus 415)minus 0radic

112

21 + 172

23

= 2336

c Conservatively degree of freedom k is min(nt minus 1 nc minus 1) = 20 Thecritical value tlowastk is 2086

P(T gt tlowast20) =α

2= 0025

d Since |T0| = 2336 gt 2086 = tlowast20 we reject the null hypothesis

t-table rArr http

bcswhfreemancomips6econtentcat_050ips6e_table-dpdf

Kwonsang Lee STAT111 April 3 2015 11 22

Two-Sample t-test in JMP

Here are the references for t-test

One-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_one_sample_t-testpdf

Two-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_two_sample_t-testpdf

Steps for two-sample t-test

1 Open the data file

2 Go to Analyze rarr Fit Y by X For example Y is a score variable andX is an indicator of either lsquotreatedrsquo or lsquocontrolrsquo

3 Click the red triangle next to lsquoOneway Analysis of rsquo and chooset-test

Kwonsang Lee STAT111 April 3 2015 12 22

Using JMP

We can find the descriptions of each sample We also find a confidenceinterval of micro1 minus micro2 and the results of Two-sample t-test

Using JMP we can compute the p-value of our test statistic T0 in theprevious Example 1 The P-value is 00264 which is less than 005 so wereject the null hypothesis

Here is another reference relate with Example 1httpwebutkedu~cwiek201TutorialsTwoSampleTtest

Kwonsang Lee STAT111 April 3 2015 13 22

Confidence Interval from Two-Sample

We can consider two cases 1) Known σ1 and σ2 case and 2) Unknown σ1and σ2 case

Confidence interval of lsquomicro1 minus micro2rsquo with known σ1 and σ2

(X1 minus X2)plusmn Z lowast

radicσ21n1

+σ22n2

Confidence interval of lsquomicro1 minus micro2rsquo with unknown σ1 and σ2

(X1 minus X2)plusmn tlowastk

radics21n1

+s22n2

where k = min(n1 minus 1 n2 minus 1)

Kwonsang Lee STAT111 April 3 2015 14 22

Special Case Matched Pairs

Sometimes the two samples that are being compared are matched pairs

For example if there is a drug A and it can lower blood pressure Eachsubjectrsquos blood pressure is measured before taking the drug and ismeasured after intake One subject has two values of the outcome Thenwe want to test if there is any difference between blood pressure beforeintake and blood pressure after intake

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

We want to test if blood pressure before = blood pressure after

Kwonsang Lee STAT111 April 3 2015 15 22

Matched Pairs

In this case we can compute the difference D = X1 minus X2 HereDiff=BeforeminusAfter

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

Diff 14 18 18

Then we can use a test like H0 Diff = 0 This is lsquoOne-Sample t-testrsquo

Kwonsang Lee STAT111 April 3 2015 16 22

Matched Pairs Test

From Matched pairs design we have X1 and X2 for n subjects Then wecompute the new variable D = X1 minus X2 and compute the sample meanand the sample SD of D Xd and sd

Then we can state the null hypothesis H0 microd = 0 and the alternativeHa microd 6= 0 We calculate the test statistic T0

T0 =Xd minus microdsdradicn

Then we can calculate the critical value tlowastnminus1 and compare it with the teststatistic T0

Kwonsang Lee STAT111 April 3 2015 17 22

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 8: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Two-Sample Hypothesis Test Known σ1 and σ2

Since σ1 and σ2 are known we can take the Z test

a H0 micro1 minus micro2 = 0 and Ha micro1 minus micro2 6= 0

b Test statistic Z0 is

Z0 =(X1 minus X2)minus (micro1 minus micro2)radic

σ21

n1+

σ22

n2

c P-value is

P(Z le minus|Z0|) + P(Z ge |Z0|) = 2times P(Z ge |Z0|)

d Compare P-value with a level α

Kwonsang Lee STAT111 April 3 2015 8 22

Two-Sample Hypothesis Test Unknown σ1 and σ2

Since σ1 and σ2 are unknown we use s1 and s2 instead and use the t-testwith a level α

a H0 micro1 minus micro2 = 0 and Ha micro1 minus micro2 6= 0

b Test statistic T0 is

T0 =(X1 minus X2)minus (micro1 minus micro2)radic

s21n1

+s22n2

c (Modified Version) We can find the critical value tlowastk such that

P(T gt tlowastk ) =α

2

where k = min(n1 minus 1 n2 minus 1)

d Compare |T0| with the value tlowastk (|T0| gt tlowastk rArr Reject the null)

Kwonsang Lee STAT111 April 3 2015 9 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

Two-Sample t-test with a level α = 005

a H0 microtreated minus microcontrol = 0 and Ha microt minus microc 6= 0

b Test statistic T0 is given by

T0 =(Xt minus Xc)minus (microt minus microc)radic

s2tnt

+ s2cnc

=(515minus 415)minus 0radic

112

21 + 172

23

= 2336

c Conservatively degree of freedom k is min(nt minus 1 nc minus 1) = 20 Thecritical value tlowastk is 2086

P(T gt tlowast20) =α

2= 0025

d Since |T0| = 2336 gt 2086 = tlowast20 we reject the null hypothesis

t-table rArr http

bcswhfreemancomips6econtentcat_050ips6e_table-dpdf

Kwonsang Lee STAT111 April 3 2015 11 22

Two-Sample t-test in JMP

Here are the references for t-test

One-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_one_sample_t-testpdf

Two-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_two_sample_t-testpdf

Steps for two-sample t-test

1 Open the data file

2 Go to Analyze rarr Fit Y by X For example Y is a score variable andX is an indicator of either lsquotreatedrsquo or lsquocontrolrsquo

3 Click the red triangle next to lsquoOneway Analysis of rsquo and chooset-test

Kwonsang Lee STAT111 April 3 2015 12 22

Using JMP

We can find the descriptions of each sample We also find a confidenceinterval of micro1 minus micro2 and the results of Two-sample t-test

Using JMP we can compute the p-value of our test statistic T0 in theprevious Example 1 The P-value is 00264 which is less than 005 so wereject the null hypothesis

Here is another reference relate with Example 1httpwebutkedu~cwiek201TutorialsTwoSampleTtest

Kwonsang Lee STAT111 April 3 2015 13 22

Confidence Interval from Two-Sample

We can consider two cases 1) Known σ1 and σ2 case and 2) Unknown σ1and σ2 case

Confidence interval of lsquomicro1 minus micro2rsquo with known σ1 and σ2

(X1 minus X2)plusmn Z lowast

radicσ21n1

+σ22n2

Confidence interval of lsquomicro1 minus micro2rsquo with unknown σ1 and σ2

(X1 minus X2)plusmn tlowastk

radics21n1

+s22n2

where k = min(n1 minus 1 n2 minus 1)

Kwonsang Lee STAT111 April 3 2015 14 22

Special Case Matched Pairs

Sometimes the two samples that are being compared are matched pairs

For example if there is a drug A and it can lower blood pressure Eachsubjectrsquos blood pressure is measured before taking the drug and ismeasured after intake One subject has two values of the outcome Thenwe want to test if there is any difference between blood pressure beforeintake and blood pressure after intake

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

We want to test if blood pressure before = blood pressure after

Kwonsang Lee STAT111 April 3 2015 15 22

Matched Pairs

In this case we can compute the difference D = X1 minus X2 HereDiff=BeforeminusAfter

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

Diff 14 18 18

Then we can use a test like H0 Diff = 0 This is lsquoOne-Sample t-testrsquo

Kwonsang Lee STAT111 April 3 2015 16 22

Matched Pairs Test

From Matched pairs design we have X1 and X2 for n subjects Then wecompute the new variable D = X1 minus X2 and compute the sample meanand the sample SD of D Xd and sd

Then we can state the null hypothesis H0 microd = 0 and the alternativeHa microd 6= 0 We calculate the test statistic T0

T0 =Xd minus microdsdradicn

Then we can calculate the critical value tlowastnminus1 and compare it with the teststatistic T0

Kwonsang Lee STAT111 April 3 2015 17 22

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 9: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Two-Sample Hypothesis Test Unknown σ1 and σ2

Since σ1 and σ2 are unknown we use s1 and s2 instead and use the t-testwith a level α

a H0 micro1 minus micro2 = 0 and Ha micro1 minus micro2 6= 0

b Test statistic T0 is

T0 =(X1 minus X2)minus (micro1 minus micro2)radic

s21n1

+s22n2

c (Modified Version) We can find the critical value tlowastk such that

P(T gt tlowastk ) =α

2

where k = min(n1 minus 1 n2 minus 1)

d Compare |T0| with the value tlowastk (|T0| gt tlowastk rArr Reject the null)

Kwonsang Lee STAT111 April 3 2015 9 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

Two-Sample t-test with a level α = 005

a H0 microtreated minus microcontrol = 0 and Ha microt minus microc 6= 0

b Test statistic T0 is given by

T0 =(Xt minus Xc)minus (microt minus microc)radic

s2tnt

+ s2cnc

=(515minus 415)minus 0radic

112

21 + 172

23

= 2336

c Conservatively degree of freedom k is min(nt minus 1 nc minus 1) = 20 Thecritical value tlowastk is 2086

P(T gt tlowast20) =α

2= 0025

d Since |T0| = 2336 gt 2086 = tlowast20 we reject the null hypothesis

t-table rArr http

bcswhfreemancomips6econtentcat_050ips6e_table-dpdf

Kwonsang Lee STAT111 April 3 2015 11 22

Two-Sample t-test in JMP

Here are the references for t-test

One-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_one_sample_t-testpdf

Two-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_two_sample_t-testpdf

Steps for two-sample t-test

1 Open the data file

2 Go to Analyze rarr Fit Y by X For example Y is a score variable andX is an indicator of either lsquotreatedrsquo or lsquocontrolrsquo

3 Click the red triangle next to lsquoOneway Analysis of rsquo and chooset-test

Kwonsang Lee STAT111 April 3 2015 12 22

Using JMP

We can find the descriptions of each sample We also find a confidenceinterval of micro1 minus micro2 and the results of Two-sample t-test

Using JMP we can compute the p-value of our test statistic T0 in theprevious Example 1 The P-value is 00264 which is less than 005 so wereject the null hypothesis

Here is another reference relate with Example 1httpwebutkedu~cwiek201TutorialsTwoSampleTtest

Kwonsang Lee STAT111 April 3 2015 13 22

Confidence Interval from Two-Sample

We can consider two cases 1) Known σ1 and σ2 case and 2) Unknown σ1and σ2 case

Confidence interval of lsquomicro1 minus micro2rsquo with known σ1 and σ2

(X1 minus X2)plusmn Z lowast

radicσ21n1

+σ22n2

Confidence interval of lsquomicro1 minus micro2rsquo with unknown σ1 and σ2

(X1 minus X2)plusmn tlowastk

radics21n1

+s22n2

where k = min(n1 minus 1 n2 minus 1)

Kwonsang Lee STAT111 April 3 2015 14 22

Special Case Matched Pairs

Sometimes the two samples that are being compared are matched pairs

For example if there is a drug A and it can lower blood pressure Eachsubjectrsquos blood pressure is measured before taking the drug and ismeasured after intake One subject has two values of the outcome Thenwe want to test if there is any difference between blood pressure beforeintake and blood pressure after intake

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

We want to test if blood pressure before = blood pressure after

Kwonsang Lee STAT111 April 3 2015 15 22

Matched Pairs

In this case we can compute the difference D = X1 minus X2 HereDiff=BeforeminusAfter

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

Diff 14 18 18

Then we can use a test like H0 Diff = 0 This is lsquoOne-Sample t-testrsquo

Kwonsang Lee STAT111 April 3 2015 16 22

Matched Pairs Test

From Matched pairs design we have X1 and X2 for n subjects Then wecompute the new variable D = X1 minus X2 and compute the sample meanand the sample SD of D Xd and sd

Then we can state the null hypothesis H0 microd = 0 and the alternativeHa microd 6= 0 We calculate the test statistic T0

T0 =Xd minus microdsdradicn

Then we can calculate the critical value tlowastnminus1 and compare it with the teststatistic T0

Kwonsang Lee STAT111 April 3 2015 17 22

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 10: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

Two-Sample t-test with a level α = 005

a H0 microtreated minus microcontrol = 0 and Ha microt minus microc 6= 0

b Test statistic T0 is given by

T0 =(Xt minus Xc)minus (microt minus microc)radic

s2tnt

+ s2cnc

=(515minus 415)minus 0radic

112

21 + 172

23

= 2336

c Conservatively degree of freedom k is min(nt minus 1 nc minus 1) = 20 Thecritical value tlowastk is 2086

P(T gt tlowast20) =α

2= 0025

d Since |T0| = 2336 gt 2086 = tlowast20 we reject the null hypothesis

t-table rArr http

bcswhfreemancomips6econtentcat_050ips6e_table-dpdf

Kwonsang Lee STAT111 April 3 2015 11 22

Two-Sample t-test in JMP

Here are the references for t-test

One-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_one_sample_t-testpdf

Two-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_two_sample_t-testpdf

Steps for two-sample t-test

1 Open the data file

2 Go to Analyze rarr Fit Y by X For example Y is a score variable andX is an indicator of either lsquotreatedrsquo or lsquocontrolrsquo

3 Click the red triangle next to lsquoOneway Analysis of rsquo and chooset-test

Kwonsang Lee STAT111 April 3 2015 12 22

Using JMP

We can find the descriptions of each sample We also find a confidenceinterval of micro1 minus micro2 and the results of Two-sample t-test

Using JMP we can compute the p-value of our test statistic T0 in theprevious Example 1 The P-value is 00264 which is less than 005 so wereject the null hypothesis

Here is another reference relate with Example 1httpwebutkedu~cwiek201TutorialsTwoSampleTtest

Kwonsang Lee STAT111 April 3 2015 13 22

Confidence Interval from Two-Sample

We can consider two cases 1) Known σ1 and σ2 case and 2) Unknown σ1and σ2 case

Confidence interval of lsquomicro1 minus micro2rsquo with known σ1 and σ2

(X1 minus X2)plusmn Z lowast

radicσ21n1

+σ22n2

Confidence interval of lsquomicro1 minus micro2rsquo with unknown σ1 and σ2

(X1 minus X2)plusmn tlowastk

radics21n1

+s22n2

where k = min(n1 minus 1 n2 minus 1)

Kwonsang Lee STAT111 April 3 2015 14 22

Special Case Matched Pairs

Sometimes the two samples that are being compared are matched pairs

For example if there is a drug A and it can lower blood pressure Eachsubjectrsquos blood pressure is measured before taking the drug and ismeasured after intake One subject has two values of the outcome Thenwe want to test if there is any difference between blood pressure beforeintake and blood pressure after intake

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

We want to test if blood pressure before = blood pressure after

Kwonsang Lee STAT111 April 3 2015 15 22

Matched Pairs

In this case we can compute the difference D = X1 minus X2 HereDiff=BeforeminusAfter

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

Diff 14 18 18

Then we can use a test like H0 Diff = 0 This is lsquoOne-Sample t-testrsquo

Kwonsang Lee STAT111 April 3 2015 16 22

Matched Pairs Test

From Matched pairs design we have X1 and X2 for n subjects Then wecompute the new variable D = X1 minus X2 and compute the sample meanand the sample SD of D Xd and sd

Then we can state the null hypothesis H0 microd = 0 and the alternativeHa microd 6= 0 We calculate the test statistic T0

T0 =Xd minus microdsdradicn

Then we can calculate the critical value tlowastnminus1 and compare it with the teststatistic T0

Kwonsang Lee STAT111 April 3 2015 17 22

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 11: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Example 1

There is a product A that is advertised as helping students to learnStatistics more effectively We want to test if there is any positive effect ofthe product A Among 44 participants we randomly select 21 people touse the product (21 treated and 23 control) After one month allparticipants take a statistic test and the scores are recorded Thefollowing is the summary

n x s

Treated 21 515 11Control 23 415 17

Q How can we conduct a hypothesis test

We need to do Two-Sample t-test

Kwonsang Lee STAT111 April 3 2015 10 22

Example 1

Two-Sample t-test with a level α = 005

a H0 microtreated minus microcontrol = 0 and Ha microt minus microc 6= 0

b Test statistic T0 is given by

T0 =(Xt minus Xc)minus (microt minus microc)radic

s2tnt

+ s2cnc

=(515minus 415)minus 0radic

112

21 + 172

23

= 2336

c Conservatively degree of freedom k is min(nt minus 1 nc minus 1) = 20 Thecritical value tlowastk is 2086

P(T gt tlowast20) =α

2= 0025

d Since |T0| = 2336 gt 2086 = tlowast20 we reject the null hypothesis

t-table rArr http

bcswhfreemancomips6econtentcat_050ips6e_table-dpdf

Kwonsang Lee STAT111 April 3 2015 11 22

Two-Sample t-test in JMP

Here are the references for t-test

One-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_one_sample_t-testpdf

Two-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_two_sample_t-testpdf

Steps for two-sample t-test

1 Open the data file

2 Go to Analyze rarr Fit Y by X For example Y is a score variable andX is an indicator of either lsquotreatedrsquo or lsquocontrolrsquo

3 Click the red triangle next to lsquoOneway Analysis of rsquo and chooset-test

Kwonsang Lee STAT111 April 3 2015 12 22

Using JMP

We can find the descriptions of each sample We also find a confidenceinterval of micro1 minus micro2 and the results of Two-sample t-test

Using JMP we can compute the p-value of our test statistic T0 in theprevious Example 1 The P-value is 00264 which is less than 005 so wereject the null hypothesis

Here is another reference relate with Example 1httpwebutkedu~cwiek201TutorialsTwoSampleTtest

Kwonsang Lee STAT111 April 3 2015 13 22

Confidence Interval from Two-Sample

We can consider two cases 1) Known σ1 and σ2 case and 2) Unknown σ1and σ2 case

Confidence interval of lsquomicro1 minus micro2rsquo with known σ1 and σ2

(X1 minus X2)plusmn Z lowast

radicσ21n1

+σ22n2

Confidence interval of lsquomicro1 minus micro2rsquo with unknown σ1 and σ2

(X1 minus X2)plusmn tlowastk

radics21n1

+s22n2

where k = min(n1 minus 1 n2 minus 1)

Kwonsang Lee STAT111 April 3 2015 14 22

Special Case Matched Pairs

Sometimes the two samples that are being compared are matched pairs

For example if there is a drug A and it can lower blood pressure Eachsubjectrsquos blood pressure is measured before taking the drug and ismeasured after intake One subject has two values of the outcome Thenwe want to test if there is any difference between blood pressure beforeintake and blood pressure after intake

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

We want to test if blood pressure before = blood pressure after

Kwonsang Lee STAT111 April 3 2015 15 22

Matched Pairs

In this case we can compute the difference D = X1 minus X2 HereDiff=BeforeminusAfter

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

Diff 14 18 18

Then we can use a test like H0 Diff = 0 This is lsquoOne-Sample t-testrsquo

Kwonsang Lee STAT111 April 3 2015 16 22

Matched Pairs Test

From Matched pairs design we have X1 and X2 for n subjects Then wecompute the new variable D = X1 minus X2 and compute the sample meanand the sample SD of D Xd and sd

Then we can state the null hypothesis H0 microd = 0 and the alternativeHa microd 6= 0 We calculate the test statistic T0

T0 =Xd minus microdsdradicn

Then we can calculate the critical value tlowastnminus1 and compare it with the teststatistic T0

Kwonsang Lee STAT111 April 3 2015 17 22

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 12: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Example 1

Two-Sample t-test with a level α = 005

a H0 microtreated minus microcontrol = 0 and Ha microt minus microc 6= 0

b Test statistic T0 is given by

T0 =(Xt minus Xc)minus (microt minus microc)radic

s2tnt

+ s2cnc

=(515minus 415)minus 0radic

112

21 + 172

23

= 2336

c Conservatively degree of freedom k is min(nt minus 1 nc minus 1) = 20 Thecritical value tlowastk is 2086

P(T gt tlowast20) =α

2= 0025

d Since |T0| = 2336 gt 2086 = tlowast20 we reject the null hypothesis

t-table rArr http

bcswhfreemancomips6econtentcat_050ips6e_table-dpdf

Kwonsang Lee STAT111 April 3 2015 11 22

Two-Sample t-test in JMP

Here are the references for t-test

One-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_one_sample_t-testpdf

Two-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_two_sample_t-testpdf

Steps for two-sample t-test

1 Open the data file

2 Go to Analyze rarr Fit Y by X For example Y is a score variable andX is an indicator of either lsquotreatedrsquo or lsquocontrolrsquo

3 Click the red triangle next to lsquoOneway Analysis of rsquo and chooset-test

Kwonsang Lee STAT111 April 3 2015 12 22

Using JMP

We can find the descriptions of each sample We also find a confidenceinterval of micro1 minus micro2 and the results of Two-sample t-test

Using JMP we can compute the p-value of our test statistic T0 in theprevious Example 1 The P-value is 00264 which is less than 005 so wereject the null hypothesis

Here is another reference relate with Example 1httpwebutkedu~cwiek201TutorialsTwoSampleTtest

Kwonsang Lee STAT111 April 3 2015 13 22

Confidence Interval from Two-Sample

We can consider two cases 1) Known σ1 and σ2 case and 2) Unknown σ1and σ2 case

Confidence interval of lsquomicro1 minus micro2rsquo with known σ1 and σ2

(X1 minus X2)plusmn Z lowast

radicσ21n1

+σ22n2

Confidence interval of lsquomicro1 minus micro2rsquo with unknown σ1 and σ2

(X1 minus X2)plusmn tlowastk

radics21n1

+s22n2

where k = min(n1 minus 1 n2 minus 1)

Kwonsang Lee STAT111 April 3 2015 14 22

Special Case Matched Pairs

Sometimes the two samples that are being compared are matched pairs

For example if there is a drug A and it can lower blood pressure Eachsubjectrsquos blood pressure is measured before taking the drug and ismeasured after intake One subject has two values of the outcome Thenwe want to test if there is any difference between blood pressure beforeintake and blood pressure after intake

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

We want to test if blood pressure before = blood pressure after

Kwonsang Lee STAT111 April 3 2015 15 22

Matched Pairs

In this case we can compute the difference D = X1 minus X2 HereDiff=BeforeminusAfter

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

Diff 14 18 18

Then we can use a test like H0 Diff = 0 This is lsquoOne-Sample t-testrsquo

Kwonsang Lee STAT111 April 3 2015 16 22

Matched Pairs Test

From Matched pairs design we have X1 and X2 for n subjects Then wecompute the new variable D = X1 minus X2 and compute the sample meanand the sample SD of D Xd and sd

Then we can state the null hypothesis H0 microd = 0 and the alternativeHa microd 6= 0 We calculate the test statistic T0

T0 =Xd minus microdsdradicn

Then we can calculate the critical value tlowastnminus1 and compare it with the teststatistic T0

Kwonsang Lee STAT111 April 3 2015 17 22

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 13: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Two-Sample t-test in JMP

Here are the references for t-test

One-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_one_sample_t-testpdf

Two-sample t-test httpwwwchemscedufacultymorganresourcesstatisticsJMP_two_sample_t-testpdf

Steps for two-sample t-test

1 Open the data file

2 Go to Analyze rarr Fit Y by X For example Y is a score variable andX is an indicator of either lsquotreatedrsquo or lsquocontrolrsquo

3 Click the red triangle next to lsquoOneway Analysis of rsquo and chooset-test

Kwonsang Lee STAT111 April 3 2015 12 22

Using JMP

We can find the descriptions of each sample We also find a confidenceinterval of micro1 minus micro2 and the results of Two-sample t-test

Using JMP we can compute the p-value of our test statistic T0 in theprevious Example 1 The P-value is 00264 which is less than 005 so wereject the null hypothesis

Here is another reference relate with Example 1httpwebutkedu~cwiek201TutorialsTwoSampleTtest

Kwonsang Lee STAT111 April 3 2015 13 22

Confidence Interval from Two-Sample

We can consider two cases 1) Known σ1 and σ2 case and 2) Unknown σ1and σ2 case

Confidence interval of lsquomicro1 minus micro2rsquo with known σ1 and σ2

(X1 minus X2)plusmn Z lowast

radicσ21n1

+σ22n2

Confidence interval of lsquomicro1 minus micro2rsquo with unknown σ1 and σ2

(X1 minus X2)plusmn tlowastk

radics21n1

+s22n2

where k = min(n1 minus 1 n2 minus 1)

Kwonsang Lee STAT111 April 3 2015 14 22

Special Case Matched Pairs

Sometimes the two samples that are being compared are matched pairs

For example if there is a drug A and it can lower blood pressure Eachsubjectrsquos blood pressure is measured before taking the drug and ismeasured after intake One subject has two values of the outcome Thenwe want to test if there is any difference between blood pressure beforeintake and blood pressure after intake

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

We want to test if blood pressure before = blood pressure after

Kwonsang Lee STAT111 April 3 2015 15 22

Matched Pairs

In this case we can compute the difference D = X1 minus X2 HereDiff=BeforeminusAfter

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

Diff 14 18 18

Then we can use a test like H0 Diff = 0 This is lsquoOne-Sample t-testrsquo

Kwonsang Lee STAT111 April 3 2015 16 22

Matched Pairs Test

From Matched pairs design we have X1 and X2 for n subjects Then wecompute the new variable D = X1 minus X2 and compute the sample meanand the sample SD of D Xd and sd

Then we can state the null hypothesis H0 microd = 0 and the alternativeHa microd 6= 0 We calculate the test statistic T0

T0 =Xd minus microdsdradicn

Then we can calculate the critical value tlowastnminus1 and compare it with the teststatistic T0

Kwonsang Lee STAT111 April 3 2015 17 22

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 14: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Using JMP

We can find the descriptions of each sample We also find a confidenceinterval of micro1 minus micro2 and the results of Two-sample t-test

Using JMP we can compute the p-value of our test statistic T0 in theprevious Example 1 The P-value is 00264 which is less than 005 so wereject the null hypothesis

Here is another reference relate with Example 1httpwebutkedu~cwiek201TutorialsTwoSampleTtest

Kwonsang Lee STAT111 April 3 2015 13 22

Confidence Interval from Two-Sample

We can consider two cases 1) Known σ1 and σ2 case and 2) Unknown σ1and σ2 case

Confidence interval of lsquomicro1 minus micro2rsquo with known σ1 and σ2

(X1 minus X2)plusmn Z lowast

radicσ21n1

+σ22n2

Confidence interval of lsquomicro1 minus micro2rsquo with unknown σ1 and σ2

(X1 minus X2)plusmn tlowastk

radics21n1

+s22n2

where k = min(n1 minus 1 n2 minus 1)

Kwonsang Lee STAT111 April 3 2015 14 22

Special Case Matched Pairs

Sometimes the two samples that are being compared are matched pairs

For example if there is a drug A and it can lower blood pressure Eachsubjectrsquos blood pressure is measured before taking the drug and ismeasured after intake One subject has two values of the outcome Thenwe want to test if there is any difference between blood pressure beforeintake and blood pressure after intake

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

We want to test if blood pressure before = blood pressure after

Kwonsang Lee STAT111 April 3 2015 15 22

Matched Pairs

In this case we can compute the difference D = X1 minus X2 HereDiff=BeforeminusAfter

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

Diff 14 18 18

Then we can use a test like H0 Diff = 0 This is lsquoOne-Sample t-testrsquo

Kwonsang Lee STAT111 April 3 2015 16 22

Matched Pairs Test

From Matched pairs design we have X1 and X2 for n subjects Then wecompute the new variable D = X1 minus X2 and compute the sample meanand the sample SD of D Xd and sd

Then we can state the null hypothesis H0 microd = 0 and the alternativeHa microd 6= 0 We calculate the test statistic T0

T0 =Xd minus microdsdradicn

Then we can calculate the critical value tlowastnminus1 and compare it with the teststatistic T0

Kwonsang Lee STAT111 April 3 2015 17 22

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 15: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Confidence Interval from Two-Sample

We can consider two cases 1) Known σ1 and σ2 case and 2) Unknown σ1and σ2 case

Confidence interval of lsquomicro1 minus micro2rsquo with known σ1 and σ2

(X1 minus X2)plusmn Z lowast

radicσ21n1

+σ22n2

Confidence interval of lsquomicro1 minus micro2rsquo with unknown σ1 and σ2

(X1 minus X2)plusmn tlowastk

radics21n1

+s22n2

where k = min(n1 minus 1 n2 minus 1)

Kwonsang Lee STAT111 April 3 2015 14 22

Special Case Matched Pairs

Sometimes the two samples that are being compared are matched pairs

For example if there is a drug A and it can lower blood pressure Eachsubjectrsquos blood pressure is measured before taking the drug and ismeasured after intake One subject has two values of the outcome Thenwe want to test if there is any difference between blood pressure beforeintake and blood pressure after intake

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

We want to test if blood pressure before = blood pressure after

Kwonsang Lee STAT111 April 3 2015 15 22

Matched Pairs

In this case we can compute the difference D = X1 minus X2 HereDiff=BeforeminusAfter

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

Diff 14 18 18

Then we can use a test like H0 Diff = 0 This is lsquoOne-Sample t-testrsquo

Kwonsang Lee STAT111 April 3 2015 16 22

Matched Pairs Test

From Matched pairs design we have X1 and X2 for n subjects Then wecompute the new variable D = X1 minus X2 and compute the sample meanand the sample SD of D Xd and sd

Then we can state the null hypothesis H0 microd = 0 and the alternativeHa microd 6= 0 We calculate the test statistic T0

T0 =Xd minus microdsdradicn

Then we can calculate the critical value tlowastnminus1 and compare it with the teststatistic T0

Kwonsang Lee STAT111 April 3 2015 17 22

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 16: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Special Case Matched Pairs

Sometimes the two samples that are being compared are matched pairs

For example if there is a drug A and it can lower blood pressure Eachsubjectrsquos blood pressure is measured before taking the drug and ismeasured after intake One subject has two values of the outcome Thenwe want to test if there is any difference between blood pressure beforeintake and blood pressure after intake

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

We want to test if blood pressure before = blood pressure after

Kwonsang Lee STAT111 April 3 2015 15 22

Matched Pairs

In this case we can compute the difference D = X1 minus X2 HereDiff=BeforeminusAfter

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

Diff 14 18 18

Then we can use a test like H0 Diff = 0 This is lsquoOne-Sample t-testrsquo

Kwonsang Lee STAT111 April 3 2015 16 22

Matched Pairs Test

From Matched pairs design we have X1 and X2 for n subjects Then wecompute the new variable D = X1 minus X2 and compute the sample meanand the sample SD of D Xd and sd

Then we can state the null hypothesis H0 microd = 0 and the alternativeHa microd 6= 0 We calculate the test statistic T0

T0 =Xd minus microdsdradicn

Then we can calculate the critical value tlowastnminus1 and compare it with the teststatistic T0

Kwonsang Lee STAT111 April 3 2015 17 22

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 17: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Matched Pairs

In this case we can compute the difference D = X1 minus X2 HereDiff=BeforeminusAfter

Subject 1 Subject 2 Subject n

Before 130 128 126After 116 110 108

Diff 14 18 18

Then we can use a test like H0 Diff = 0 This is lsquoOne-Sample t-testrsquo

Kwonsang Lee STAT111 April 3 2015 16 22

Matched Pairs Test

From Matched pairs design we have X1 and X2 for n subjects Then wecompute the new variable D = X1 minus X2 and compute the sample meanand the sample SD of D Xd and sd

Then we can state the null hypothesis H0 microd = 0 and the alternativeHa microd 6= 0 We calculate the test statistic T0

T0 =Xd minus microdsdradicn

Then we can calculate the critical value tlowastnminus1 and compare it with the teststatistic T0

Kwonsang Lee STAT111 April 3 2015 17 22

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 18: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Matched Pairs Test

From Matched pairs design we have X1 and X2 for n subjects Then wecompute the new variable D = X1 minus X2 and compute the sample meanand the sample SD of D Xd and sd

Then we can state the null hypothesis H0 microd = 0 and the alternativeHa microd 6= 0 We calculate the test statistic T0

T0 =Xd minus microdsdradicn

Then we can calculate the critical value tlowastnminus1 and compare it with the teststatistic T0

Kwonsang Lee STAT111 April 3 2015 17 22

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 19: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Example 2

We consider the drug of lowering blood pressure example

Subject Before After D

1 130 116 142 128 110 18

10 126 108 18

The summary is that

xbefore = 1222 sbefore = 63

xafter = 113 safter = 91

However in matched pairs designwhat we need is a new variableD = Before minus After We have

xd = 92 sd = 98

Kwonsang Lee STAT111 April 3 2015 18 22

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 20: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Example 2 Under Independent Assumption

It is clear that lsquoBeforersquo and lsquoAfterrsquo is not independent because these twoare from the same subject If we consider lsquoBeforersquo and lsquoAfterrsquo areindependent then what can we conclude

We want to do hypothesis test with a level α = 002

a H0 microbefore minus microafter = 0 and Ha microbefore minus microafter 6= 0

b The test statistic T0 is

T0 =(xbefore minus xafter )minus (microbefore minus microafter )radic

s21n1

+s22n2

=1222minus 113radic

632

10 + 912

10

= 2629

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2629 lt 2821 = tlowast9 So we donrsquot reject the null It meansthat there is not enough evidence that there is an effect of a drug onlowering blood pressure

Kwonsang Lee STAT111 April 3 2015 19 22

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 21: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Example 2 Matched Pairs

lsquoBeforersquo and lsquoAfterrsquo from the original data are dependent So doing t-testisnrsquot correct under independence Here is right Matched pairs t-test

Hypothesis test with a level α = 002

a H0 microd = 0 and Ha microd 6= 0

b The test statistic T0 is

T0 =xd minus microdsdradicn

=92

98radic

10= 2969

c k = n minus 1 = 9 and tlowast9 = 2821 such that P(T gt tlowast9 ) = α2 = 001

d |T0| = 2969 gt 2821 = tlowast9 So we reject the null It means thatthere is enough evidence that there is an effect of a drug on loweringblood pressure

Note It is important to use the right approach

Kwonsang Lee STAT111 April 3 2015 20 22

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 22: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Summary

We learned CI and Hypothesis test in so many situations I can give adirection about how to choose the right way of analysis

1 Need to understand the data ie is it one-sample or two-sampleor matched pairs design

2 Do we know the population SD σ

3 Is our goal making a CI or doing hypothesis test

4 If we need to do hypothesis test what is the null and alternativehypotheses (One-sided or Two-sided)

Kwonsang Lee STAT111 April 3 2015 21 22

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22

Page 23: Comparing Means from Two-Sample - Penn Mathkwonlee/recitation_wk11.pdfStatistics more e ectively. We want to test if there is any positive e ect of the product A. Among 44 participants,

Next Week

We have been talking about inferences of the population mean micro Nextweek wersquore going to talk about CI and hypothesis test for population p

Kwonsang Lee STAT111 April 3 2015 22 22