lecture 7: hypothesis testing and anova

33
Lecture 7: Hypothesis Testing and ANOVA

Upload: trinhduong

Post on 03-Jan-2017

234 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 7: Hypothesis Testing and ANOVA

Lecture 7: HypothesisTesting and ANOVA

Page 2: Lecture 7: Hypothesis Testing and ANOVA

Goals

• Introduction to ANOVA

• Review of common one and two sample tests

• Overview of key elements of hypothesis testing

Page 3: Lecture 7: Hypothesis Testing and ANOVA

Hypothesis Testing

• The intent of hypothesis testing is formally examine twoopposing conjectures (hypotheses), H0 and HA

• These two hypotheses are mutually exclusive andexhaustive so that one is true to the exclusion of theother

• We accumulate evidence - collect and analyze sampleinformation - for the purpose of determining which ofthe two hypotheses is true and which of the twohypotheses is false

Page 4: Lecture 7: Hypothesis Testing and ANOVA

The Null and Alternative Hypothesis

• States the assumption (numerical) to be tested

• Begin with the assumption that the null hypothesis is TRUE

• Always contains the ‘=’ sign

The null hypothesis, H0:

The alternative hypothesis, Ha:

• Is the opposite of the null hypothesis

• Challenges the status quo• Never contains just the ‘=’ sign

• Is generally the hypothesis that is believed to be true bythe researcher

Page 5: Lecture 7: Hypothesis Testing and ANOVA

One and Two Sided Tests

• Hypothesis tests can be one or two sided (tailed)

• One tailed tests are directional:

H0: µ1 - µ2 ≤ 0

HA: µ1 - µ2 > 0

• Two tailed tests are not directional:

H0: µ1 - µ2 = 0

HA: µ1 - µ2 ≠ 0

Page 6: Lecture 7: Hypothesis Testing and ANOVA

P-values

• After calculating a test statistic we convert this to a P-value by comparing its value to distribution of teststatistic’s under the null hypothesis

• Measure of how likely the test statistic value is underthe null hypothesis

P-value ≤ α ⇒ Reject H0 at level α

P-value > α ⇒ Do not reject H0 at level α

• Calculate a test statistic in the sample data that isrelevant to the hypothesis being tested

Page 7: Lecture 7: Hypothesis Testing and ANOVA

When To Reject H0

One Sidedα = 0.05

Rejection region: set of all test statistic values for which H0 will berejected

Critical Value = -1.64 Critical Values = -1.96 and +1.96

Level of significance, α: Specified before an experiment to definerejection region

Two Sidedα = 0.05

Page 8: Lecture 7: Hypothesis Testing and ANOVA

Some Notation• In general, critical values for an α level test denoted as:

!

One sided test : X"

Two sided test : X"/2

where X depends on the distribution of the test statistic

• For example, if X ~ N(0,1):

!

One sided test : z" (i.e., z0.05 = 1.64)

Two sided test : z"/2 (i.e., z0.05 / 2 = z0.025 = ± 1.96)

Page 9: Lecture 7: Hypothesis Testing and ANOVA

Errors in Hypothesis Testing

H0 True H0 False

Do NotReject H0

Rejct H0

Actual Situation “Truth”

Decision

Page 10: Lecture 7: Hypothesis Testing and ANOVA

Errors in Hypothesis Testing

Correct Decision1 - α

Correct Decision1 - β

Incorrect Decisionβ

Incorrect Decisionα

H0 True H0 False

Do NotReject H0

Rejct H0

Actual Situation “Truth”

Decision

Page 11: Lecture 7: Hypothesis Testing and ANOVA

Type I and II Errors

Correct Decision1 - α

Correct Decision1 - β

Incorrect Decision

β

Incorrect Decision

α

H0 True H0 False

Do NotReject H0

Rejct H0

Actual Situation “Truth”

Decision

Type II Error

Type I Error

)()( ErrorIITypePErrorITypeP == !"

!

Power = 1 - "

Page 12: Lecture 7: Hypothesis Testing and ANOVA

Parametric and Non-Parametric Tests

• Parametric Tests: Relies on theoretical distributions ofthe test statistic under the null hypothesis and assumptionsabout the distribution of the sample data (i.e., normality)

• Non-Parametric Tests: Referred to as “DistributionFree” as they do not assume that data are drawn from anyparticular distribution

Page 13: Lecture 7: Hypothesis Testing and ANOVA

Whirlwind Tour of One and Two Sample Tests

Type of DataBinomialNon-GaussianGaussianGoal

Chi-Square orFisher’s Exact Test

Wilcoxon-Mann-Whitney Test

Two samplet-test

Compare twounpairedgroups

McNemar’s TestWilcoxon TestPaired t-testCompare twopaired groups

Binomial TestWilcoxon TestOne sample

t-test

Compare onegroup to a

hypotheticalvalue

Page 14: Lecture 7: Hypothesis Testing and ANOVA

General Form of a t-test

!

T =x "µ

s n

!

t" ,n#1

!

T =x " y " (µ

1"µ

2)

sp

1

m+1

n

!

t" ,m+n#2

One Sample Two Sample

Statistic

df

Page 15: Lecture 7: Hypothesis Testing and ANOVA

Non-Parametric Alternatives

• Wilcoxon Test: non-parametric analog of one sample t-test

• Wilcoxon-Mann-Whitney test: non-parametric analogof two sample t-test

Page 16: Lecture 7: Hypothesis Testing and ANOVA

Hypothesis Tests of a Proportion

• Large sample test (prop.test)

!

z =ˆ p " p

0

p0(1" p

0) /n

• Small sample test (binom.test)

- Calculated directly from binomial distribution

Page 17: Lecture 7: Hypothesis Testing and ANOVA

Confidence Intervals

• Confidence interval: an interval of plausible values forthe parameter being estimated, where degree of plausibilityspecifided by a “confidence level”

• General form:

!

ˆ x ± critical value" • se

!

x - y ± t",m +n#2 • sp

1

m+

1

n

Page 18: Lecture 7: Hypothesis Testing and ANOVA

Interpreting a 95% CI

• We calculate a 95% CI for a hypothetical sample mean to bebetween 20.6 and 35.4. Does this mean there is a 95%probability the true population mean is between 20.6 and 35.4?

• NO! Correct interpretation relies on the long-rang frequencyinterpretation of probability

µ

• Why is this so?

Page 19: Lecture 7: Hypothesis Testing and ANOVA

Hypothesis Tests of 3 or More Means

• Suppose we measure a quantitative trait in a group of Nindividuals and also genotype a SNP in our favoritecandidate gene. We then divide these N individuals intothe three genotype categories to test whether theaverage trait value differs among genotypes.

• What statistical framework is appropriate here?

• Why not perform all pair-wise t-tests?

Page 20: Lecture 7: Hypothesis Testing and ANOVA

Basic Framework of ANOVA

• Want to study the effect of one or morequalitative variables on a quantitativeoutcome variable

• Qualitative variables are referred to as factors(i.e., SNP)

• Characteristics that differentiates factors arereferred to as levels (i.e., three genotypes of aSNP

Page 21: Lecture 7: Hypothesis Testing and ANOVA

One-Way ANOVA

• Simplest case is for One-Way (Single Factor) ANOVA

The outcome variable is the variable you’re comparing

The factor variable is the categorical variable being used todefine the groups- We will assume k samples (groups)

The one-way is because each value is classified in exactly oneway

• ANOVA easily generalizes to more factors

Page 22: Lecture 7: Hypothesis Testing and ANOVA

Assumptions of ANOVA

• Independence

• Normality

• Homogeneity of variances (aka,Homoscedasticity)

Page 23: Lecture 7: Hypothesis Testing and ANOVA

• The null hypothesis is that the means are all equal

• The alternative hypothesis is that at least one ofthe means is different– Think about the Sesame Street® game where three of

these things are kind of the same, but one of thesethings is not like the other. They don’t all have to bedifferent, just one of them.

One-Way ANOVA: Null Hypothesis

0 1 2 3:

kH µ µ µ µ= = = =L

!

H0 : µ

1= µ

2= ...= µ

k

Page 24: Lecture 7: Hypothesis Testing and ANOVA

Motivating ANOVA

• A random sample of some quantitative traitwas measured in individuals randomly sampledfrom population

• Genotyping of a single SNP– AA: 82, 83, 97

– AG: 83, 78, 68

– GG: 38, 59, 55

Page 25: Lecture 7: Hypothesis Testing and ANOVA

Rational of ANOVA

• Basic idea is to partition total variation of thedata into two sources

1. Variation within levels (groups)

2. Variation between levels (groups)

• If H0 is true the standardized variances are equalto one another

Page 26: Lecture 7: Hypothesis Testing and ANOVA

The Details

• Let Xij denote the data from the ith level and jth observation

AA: 82, 83, 97 AG: 83, 78, 68

GG: 38, 59, 55

Our Data:

• Overall, or grand mean, is:

!

x ..

=xij

Nj=1

J

"i=1

K

"

!

x ..

=82 + 83+ 97 + 83+ 78 + 68 + 38 + 59 + 55

9= 71.4

!

x 1.

= (82 + 83+ 97) /3 = 87.3

!

x 2. = (83+ 78 + 68) /3 = 76.3

!

x 3. = (38 + 59 + 55) /3 = 50.6

Page 27: Lecture 7: Hypothesis Testing and ANOVA

Partitioning Total Variation

• Recall, variation is simply average squared deviations from the mean

SST SSTG SSTE= +

!

(xij " x ..

j=1

J

#i=1

K

# )2

!

ni• (x

i." x

..)2

i=1

K

#

!

(xij " x i.j=1

J

#i=1

K

# )2

Sum of squareddeviations about thegrand mean across all

N observations

Sum of squareddeviations for eachgroup mean about

the grand mean

Sum of squareddeviations for all

observations withineach group from thatgroup mean, summed

across all groups

Page 28: Lecture 7: Hypothesis Testing and ANOVA

In Our Example

SST SSTG SSTE= +

!

(xij " x ..

j=1

J

#i=1

K

# )2

!

(xij " x i.j=1

J

#i=1

K

# )2

!

(82 " 71.4)2

+ (83" 71.4)2

+ (97 " 71.4)2

+

(83" 71.4)2

+ (78 " 71.4)2

+ (68 " 71.4)2

+

(38 " 71.4)2

+ (59 " 71.4)2

+ (55 " 71.4)2

=

!

3• (87.3" 71.4)2

+

3• (76.3" 71.4)2

+

3• (50.6 " 71.4)2

=

!

(82 " 87.3)2

+ (83" 87.3)2

+ (97 " 87.3)2

+

(83" 76.3)2

+ (78 " 76.3)2

+ (68 " 76.3)2

+

(38 " 50.6)2

+ (59 " 50.6)2

+ (55 " 50.6)2

=

2630.2 2124.2 506

!

ni• (x

i." x

..)2

i=1

K

#

Page 29: Lecture 7: Hypothesis Testing and ANOVA

In Our Example

SST SSTG SSTE= +

!

(xij " x ..

j=1

J

#i=1

K

# )2

!

(xij " x i.j=1

J

#i=1

K

# )2

!

x ..!

x 1.

!

x 2.

!

x 3.

!

ni• (x

i." x

..)2

i=1

K

#

Page 30: Lecture 7: Hypothesis Testing and ANOVA

Calculating Mean Squares

• To make the sum of squares comparable, we divide each one bytheir associated degrees of freedom

• SSTG = k - 1 (3 - 1 = 2)

• SSTE = N - k (9 - 3 = 6)

• SSTT = N - 1 (9 - 1 = 8)

• MSTG = 2124.2 / 2 = 1062.1

• MSTE = 506 / 6 = 84.3

Page 31: Lecture 7: Hypothesis Testing and ANOVA

Almost There… Calculating F Statistic

!

F =MST

G

MSTE

=1062.2

84.3=12.59

• The test statistic is the ratio of group and error mean squares

• If H0 is true MSTG and MSTE are equal

• Critical value for rejection region is Fα, k-1, N-k

• If we define α = 0.05, then F0.05, 2, 6 = 5.14

Page 32: Lecture 7: Hypothesis Testing and ANOVA

ANOVA Table

SSTN-1Total

SSTEN-kError

SSTGk-1Group

FMSSum ofSquares

dfSource ofVariation

!

SSTG

k "1

!

SSTE

N " k!

SSTG

k "1SST

E

N " k

Page 33: Lecture 7: Hypothesis Testing and ANOVA

Non-Parametric Alternative

• Kruskal-Wallis Rank Sum Test: non-parametric analog to ANOVA

• In R, kruskal.test()