comparing several means: anova

LAST UPDATED: November 15, 2012
COMPARING SEVERAL MEANS:
ANOVA
J. Elder
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
Objectives
Comparing Several Means – ANOVA (GLM 1)
2
Basic principles of ANOVA
¨  Equations underlying one-way ANOVA
¨  Doing a one-way ANOVA in R
¨ 
¨ 
Following up an ANOVA:
¤ Planned
contrasts/comparisons
n Choosing
contrasts
n Coding contrasts
¤ Post
¨ 
hoc tests
ANOVA as regression
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Objectives
Comparing Several Means – ANOVA (GLM 1)
3
Basic principles of ANOVA
¨  Equations underlying one-way ANOVA
¨  Doing a one-way ANOVA in R
¨ 
¨ 
Following up an ANOVA:
¤ Planned
contrasts/comparisons
n Choosing
contrasts
n Coding contrasts
¤ Post
¨ 
hoc tests
ANOVA as regression
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
When and Why
Comparing Several Means – ANOVA (GLM 1)
4
¨ 
When we want to compare means we can use a t-test.
This test has limitations:
¤  You
can compare only 2 means: often we would like to
compare means from 3 or more groups.
¤  It can be used only with one predictor/independent
variable.
¨ 
ANOVA
¤  Compares
several means.
¤  Can be used when you have manipulated more than one
independent variable.
¤  It is an extension of regression (the general linear model).
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Generalizing t-Tests
Comparing Several Means – ANOVA (GLM 1)
5
t-Tests allow us to test hypotheses about differences
between two groups or conditions (e.g., treatment
and control).
¨  What do we do if we wish to compare multiple
groups or conditions simultaneously?
¨  Examples:
¨ 
¤  Effects
of 3 different therapies for autism
¤  Effects of 4 different SSRIs on seratonin re-uptake
¤  Effects of 5 different body orientations on judgement
of induced self-motion.
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Why Not Use Lots of t-Tests?
Comparing Several Means – ANOVA (GLM 1)
6
¨ 
If we want to compare several means why don’t we compare
pairs of means with t-tests?
¤ 
Inflates the Type I error rate.
1
1
2
2
2
3
3
1
3
familywise error = 1 − 0.95n
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Advantages of ANOVA
Comparing Several Means – ANOVA (GLM 1)
7
Avoid inflation in error rate due to multiple
comparisons
¨  Can detect an effect of the treatment even when no
2 groups are significantly different.
¨ 
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
What Does ANOVA Tell Us?
Comparing Several Means – ANOVA (GLM 1)
8
¨ 
Null hypothesis:
¤  Like
a t-test, ANOVA tests the null hypothesis that the means
are the same.
¨ 
Experimental hypothesis:
¤  The
¨ 
means differ.
ANOVA is an omnibus test
¤  It
test for an overall difference between groups.
¤  It tells us that the group means are different.
¤  It doesn’t tell us exactly which means differ.
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
6-Step Process for ANOVA
Comparing Several Means – ANOVA (GLM 1)
9
H0 : µ1 = µ2 = ... = µn
1. 
State the hypotheses
2. 
Select the statistical test and significance level
3. 
Select the samples and collect the data
4. 
Find the region of rejection
5. 
Calculate the test statistic
6. 
Make the statistical decision
H A : ∃i , j ∈ [1,..., n] : µi ≠ µ j
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Theory of ANOVA
Comparing Several Means – ANOVA (GLM 1)
10
¨ 
We calculate how much variability there is between
scores
¤  Total
¨ 
sum of squares (SST).
We then calculate how much of this variability can be
explained by the model we fit to the data
¤  How
much variability is due to the experimental
manipulation, model sum of squares (SSM)...
¨ 
… and how much cannot be explained
¤  How
much variability is due to individual differences in
performance, residual sum of squares (SSR).
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Theory of ANOVA
Comparing Several Means – ANOVA (GLM 1)
11
¨ 
We compare the amount of variability explained by
the model (experiment), to the error in the model
(individual differences)
¤  This
¨ 
ratio is called the F-ratio.
If the model explains a lot more variability than it
can’t explain, then the experimental manipulation has
had a significant effect on the outcome (DV).
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Theory of ANOVA
Comparing Several Means – ANOVA (GLM 1)
12
¨ 
If the experiment is successful, then the model will
explain more variance than it can’t
¤  MSM
will be greater than MSR
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
End of Lecture
November 8, 2012
Objectives
Comparing Several Means – ANOVA (GLM 1)
14
Basic principles of ANOVA
¨  Equations underlying one-way ANOVA
¨  Doing a one-way ANOVA in R
¨ 
¨ 
Following up an ANOVA:
¤ Planned
contrasts/comparisons
n Choosing
contrasts
n Coding contrasts
¤ Post
¨ 
hoc tests
ANOVA as regression
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Example (Two Means)
Comparing Several Means – ANOVA (GLM 1)
15
X1
X2
-10.2 4.8
-1.8 6.7
15.2 -0.8
-0.4 8.9
12.3 23.1
-7.0 5.2
0.1 -0.1
-7.8 9.1
5.9 0.6
-2.5 -11.1
X1
s1
Mean
Std Dev
0.4
8.4
4.6 2.5
8.8
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
X2
XG
s2
J. Elder
Reinterpreting the 2-Sample t-Statistic
Comparing Several Means – ANOVA (GLM 1)
16
t2 =
X
(
n
1
− X2
)
2
2
s p2
The denominator sp2 is an estimate of the variance σ 2 of the population,
derived by averaging the variances within the two samples:
1
sp2 = (s12 + s22 )
2
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Reinterpreting the 2-Sample t-Statistic
Comparing Several Means – ANOVA (GLM 1)
17
t2 =
(X
n
1 − X2
)
2
The numerator is also an estimate of the variance σ 2 of the population,
derived from the variance between the sample means.
2
s
2
p
To see this, recall that s X =
s
n
→ s 2 = ns X2
(
)
For 2 groups, s X2 = (X 1 − X G )2 + (X 2 − X G )2 , where X G =
2
⎛
⎞ ⎛
⎞
1
1
Thus, s = ⎜ X 1 − (X 1 + X 2 )⎟ + ⎜ X 2 − (X 1 + X 2 )⎟
2
2
⎝
⎠ ⎝
⎠
1
(X + X 2 )
2 1
NB : Only 1 df in calculation of s X .
2
2
X
2
⎛1
⎞ ⎛1
⎞
= ⎜ (X 1 − X 2 )⎟ + ⎜ (X 2 − X 1)⎟
⎝2
⎠ ⎝2
⎠
=
2
1
(X 1 − X 2 )2
2
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
The F Distribution
Comparing Several Means – ANOVA (GLM 1)
18
F = t2 =
n
(
X1 − X 2
)
2
2
sp2
Thus, under the null hypothesis, the numerator and denominator are
independent estimates of the same population variance σ 2 .
The ratio of 2 independent, unbiased estimates of the same variance
follows an F distribution.
0.5
F distribution for 2 groups
of size n=13
0.4
p(F )
0.3
0.2
0.1
0
0
2
4
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
6
F
8
10
J. Elder
Within and Between Variances
Comparing Several Means – ANOVA (GLM 1)
19
¨ 
¨ 
¨ 
¨ 
¨ 
Recall that the variance is, by definition, the mean squared deviation of
scores from their mean.
Since the numerator of the F statistic estimates the variance from the
deviations of group means, it is sometimes called the mean-square-between
estimate.
Since this estimate will include the effect of the independent variable (if
any), it is also called the model mean-square MSM.
Since the denominator of the F statistic estimates the variance from the
deviations within groups, it is sometimes called the mean-square-within
estimate.
Since this deviation should only reflect the unmodeled noise (residual) it is also
called the residual mean-square MSR.
MSM
Thus F =
MSR
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Generalizing to > 2 Groups
Comparing Several Means – ANOVA (GLM 1)
20
MSM
F=
MSR
MSM
n (X
∑
=
MSR
∑ (n − 1)s
=
i
i
− X G )2
dfM
i
, where X G =
1
NT
∑
all scores
Xi =
1
NT
∑n X
i
i
2
i
dfR
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Sums of Squares Approach
Comparing Several Means – ANOVA (GLM 1)
21
F=
MSM
MSR
MSM =
SSM
, where SSM = ∑ ni (X i − X G )2
dfM
SSR
MSR =
, where SSR = ∑ (ni − 1)si2
dfR
NB :
SST = SSM + SSR
MST ≠ MSM + MSR
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Degrees of Freedom
Comparing Several Means – ANOVA (GLM 1)
22
The sample variance follows a scaled chi-square
distribution, parameterized by the degrees of
freedom.
¨  Thus the F distribution is a ratio of two chi-square
distributions, each with different degrees of freedom.
¨ 
dfM = k − 1, where k = number of groups.
dfR = NT − k, where NT = total number of subjects over all groups.
(
)
= ∑ ni − 1
i
dfT = dfM + dfR = NT − 1
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Properties of the F Distribution
Comparing Several Means – ANOVA (GLM 1)
23
Domain strictly non-negative
1
0.8
Positively skewed
n=2
n=5
n=10
n=100
k =3
0.6
0.4
dfR
µ=
dfR − 2
0.2
0
0
5
10
1
n=2
n=5
n=10
n=100
k = 10
Tail becomes lighter as dfR → ∞
0.8
0.6
0.4
Distribution → Normal as dfR ,dfM → ∞
0.2
0
0
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
2
4
6
8
10
J. Elder
The F Statistic
Comparing Several Means – ANOVA (GLM 1)
24
When H0 is true (X 1 = X 2 =  = X k ) we expect F  1.
What do we expect when H0 is false?
MSM
F=
MSR
MSM
n (X
∑
=
MSR
(n − 1)s
∑
=
i
i
− X G )2
dfM
i
, where X G =
1
NT
∑
all scores
Xi =
1
NT
∑n X
i
i
2
i
dfR
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Testing Hypotheses
Comparing Several Means – ANOVA (GLM 1)
25
MSM
F=
MSR
Large values of F suggest that differences between the groups
are inflating the MSM estimate of σ 2 → reject H0 .
1
F distribution for 3 groups of size n=13
p(F)
0.8
0.6
0.4
0.2
0
0
2
4
6
8
10
Fcrit  3.32 for α = .05
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Interpreting the F Ratio
Comparing Several Means – ANOVA (GLM 1)
26
F=
estimate of treatment effect + between-group estimate of error variance
within-group estimate of error variance
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Example
Comparing Several Means – ANOVA (GLM 1)
27
¨ 
Testing the effects of Viagra on libido using three
groups:
¤  Placebo
(sugar pill)
¤  Low dose viagra
¤  High dose viagra
¨ 
The outcome/dependent variable (DV) was an
objective measure of libido.
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
The Data
28
Comparing Several Means – ANOVA (GLM 1)
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Summary Table
Comparing Several Means – ANOVA (GLM 1)
29
Source SS df MS F Model 20.14 2 10.067 5.12* Residual 23.60 12 1.967 Total 43.74 14 PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Objectives
Comparing Several Means – ANOVA (GLM 1)
30
Basic principles of ANOVA
¨  Equations underlying one-way ANOVA
¨  Doing a one-way ANOVA in R
¨ 
¨ 
Following up an ANOVA:
¤ Planned
contrasts/comparisons
n Choosing
contrasts
n Coding contrasts
¤ Post
¨ 
hoc tests
ANOVA as regression
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
One-Way ANOVA using R
Comparing Several Means – ANOVA (GLM 1)
31
¨ 
When the Test Assumptions Are Met:
¤  Using
lm():
viagraModel<-lm(libido~dose, data = viagraData)
¤  Using
aov():
viagraModel<-aov(libido ~ dose, data = viagraData)
summary(viagraModel)
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Using lm() for ANOVAs
Comparing Several Means – ANOVA (GLM 1)
32
viagraModel<-lm(libido~dose, data = viagraData)
¨  Be careful that the independent variable is coded
as a factor!
¤ 
¨ 
¨ 
If it is interpreted as a number, lm() will do a linear
regression.
By default we get contrasts of the second to last
levels against the first level.
For this experiment, this contrasts the low and high
doses against the placebo.
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
ANOVA Assumptions
Comparing Several Means – ANOVA (GLM 1)
33
Independent random sampling
¨  Normal distributions
¨  Homogeneity of variance
¨ 
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Levene’s Test for Homogeneity of Variance
Comparing Several Means – ANOVA (GLM 1)
34
1. Replace each score X1i , X 2i ,... with its absolute deviation from the sample mean:
d1i =| X 1i − X 1 |
d 2i =| X 2i − X 2 |

2. Now run an analysis of variance on d1i , d2i ,... :
F=
MSM
MSR
MSM =
SSM
, where SSM = ∑ ni (d i − dG )2
dfM
SSR
MSR =
, where SSR = ∑ (ni − 1)sdi2
dfR
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
When variances are not equal across groups
Comparing Several Means – ANOVA (GLM 1)
35
If Levene’s test is significant then it is unlikely that
variances are homogeneous.
¨  Recall that when doing t-tests on a pair of means
we applied the Welch-Sattertwhaite approximation
to account for unequal variances.
¨  We can apply a comparable approximation for
ANOVA by executing:
¨ 
oneway.test(libido ~ dose, data = viagraData)
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Objectives
Comparing Several Means – ANOVA (GLM 1)
36
Basic principles of ANOVA
¨  Equations underlying one-way ANOVA
¨  Doing a one-way ANOVA in R
¨ 
¨ 
Following up an ANOVA:
¤ Planned
contrasts/comparisons
n Choosing
contrasts
n Coding contrasts
¤ Post
¨ 
hoc tests
ANOVA as regression
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Why Use Follow-Up Tests?
Comparing Several Means – ANOVA (GLM 1)
37
¨ 
The F-ratio tells us only that there is some effect of
the IV.
¤  i.e.
group means were different
It does not tell us specifically which group means
differ from which.
¨  We need additional tests to find out where the
group differences lie.
¨ 
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
How?
Comparing Several Means – ANOVA (GLM 1)
38
¨ 
Orthogonal contrasts/comparisons
¤  Hypothesis
driven
¤  Planned a priori
¨ 
Post hoc tests
¤  Not
planned (no hypothesis)
¤  Compare all pairs of means
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Planned Contrasts
Comparing Several Means – ANOVA (GLM 1)
39
¨ 
Basic idea:
¤  The
variability explained by the model
(experimental manipulation, SSM) is due to
participants being assigned to different groups.
¤  This variability can be broken down further to test
specific hypotheses about which groups might
differ.
¤  We break down the variance according to
hypotheses made a priori (before the experiment).
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Rules When Choosing Contrasts
Comparing Several Means – ANOVA (GLM 1)
40
¨ 
Independent
¤  Contrasts
must not interfere with each other (they must test
unique hypotheses).
¨ 
Only two chunks
¤  Each
¨ 
contrast should compare only two chunks of variation.
K–1
¤  You
should always end up with one less contrast than the
number of groups.
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Generating Hypotheses
Comparing Several Means – ANOVA (GLM 1)
41
¨ 
Example: Testing the effects of Viagra on libido using
three groups:
¤  Placebo
¤  Low
dose viagra
¤  High
¨ 
¨ 
(sugar pill)
dose viagra
Dependent variable (DV) was an objective measure
of libido.
Intuitively, what might we expect to happen?
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Mean
Placebo
Low Dose
High Dose
3
5
7
2
2
4
1
4
5
1
2
3
4
3
6
2.20
3.20
5.00
How do I Choose Contrasts?
Comparing Several Means – ANOVA (GLM 1)
43
¨ 
Big hint:
¤  In
most experiments we usually have one or more control
groups.
¤  The
logic of control groups dictates that we expect them to
be different from groups that we’ve manipulated.
¤  The
first contrast will typically be to compare any control
groups (chunk 1) with any experimental conditions (chunk 2).
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Hypotheses
Comparing Several Means – ANOVA (GLM 1)
44
¨ 
Hypothesis 1:
¤  People
who take Viagra will have a higher libido than those
who don’t.
¤  Placebo < (Low, High)
¨ 
Hypothesis 2:
¤  People
taking a high dose of Viagra will have a greater
libido than those taking a low dose.
¤  Low < High
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Planned Comparisons
45
Comparing Several Means – ANOVA (GLM 1)
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Another Example
46
Comparing Several Means – ANOVA (GLM 1)
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Coding Planned Contrasts: Rules
Comparing Several Means – ANOVA (GLM 1)
47
¨ 
Rule 1
¤  Groups
coded with positive weights compared to groups
coded with negative weights.
¨ 
Rule 2
¤  The
sum of the positive weights should equal the sum of the
negative weights.
¨ 
Rule 3
¤  If
a group is not involved in a comparison, assign it a weight
of zero.
¨ 
Rule 4
¤  If
a group is singled out in a comparison, then that group
should not be used in any subsequent contrasts.
Note: Ignore rules in textbook.
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Orthogonal Contrasts
Comparing Several Means – ANOVA (GLM 1)
50
¨ 
Two contrasts are said to be orthogonal when the
sum of the products of the weights for the two
contrasts is 0.
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Orthogonality and Type I Errors
Comparing Several Means – ANOVA (GLM 1)
52
¨ 
¨ 
¨ 
¨ 
If two contrasts are not orthogonal, whether you commit
a Type I error on the first may be correlated with
whether you commit a Type I error on the second.
If the two contrasts are orthogonal, these two events
should be uncorrelated.
In either case, one still has inflation of experiment-wise
Type I error.
Despite this, many publications allow reporting of
planned orthogonal contrasts without correction for
multiple comparisons.
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Planned Contrasts using R
Comparing Several Means – ANOVA (GLM 1)
53
¨ 
To do planned comparisons in R we have to set the
contrast attribute of our grouping variable using the
contrast() function and then recreate our ANOVA
model using
¤  viagraModel
<- aov(libido~dose, data=viagraData)
¤  summary.lm(viagraModel)
or
¤  viagraModel
<- lm(libido~dose, data=viagraData)
¤  summary(viagraModel)
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Objectives
Comparing Several Means – ANOVA (GLM 1)
54
Basic principles of ANOVA
¨  Equations underlying one-way ANOVA
¨  Doing a one-way ANOVA in R
¨ 
¨ 
Following up an ANOVA:
¤ Planned
contrasts/comparisons
n Choosing
contrasts
n Coding contrasts
¤ Post
¨ 
hoc tests
ANOVA as regression
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Post Hoc Tests
Comparing Several Means – ANOVA (GLM 1)
55
¨ 
¨ 
¨ 
¨ 
¨ 
Post-hoc tests are tests you decide to do after the data are
collected and examined.
Since you have already seen the data, regardless of how
many tests you are interested in you must correct as though you
are interested in all possible pairwise tests.
How you conduct post hoc tests in R depends on which test
you’d like to do.
Bonferroni can be done using the pairwise.t.test() function,
which is part of the R base system.
Tukey can be done using the glht() function in the multcomp()
package.
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Bonferroni-Dunn Test
Comparing Several Means – ANOVA (GLM 1)
For a given number of
comparisons j the
experiment-wise alpha
will never be more than j
times the per-comparison
alpha.
α EW ≤ jα PC
j=5
6
j × α PC
5
4
3
α EW = 1 − (1 − α ) j
2
1
3
5
7
9
0.
0.
0.
0.
→ set α PC
α EW
=
j
1
0
0.
56
¨ 
Experimentwise alpha
56
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
alpha (per comparison)
J. Elder
Tukey’s Honestly Significant Difference
Comparing Several Means – ANOVA (GLM 1)
57
¨ 
Key Idea:
¤  Given
k groups, consider the
smallest and largest means.
¤  Ensure protection against Type I
error when comparing these two
means.
¤  This is guaranteed to protect
against Type I error for all pairs.
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
Treatment
Group
n
Mean
A
10
45.5
B
11
46.8
C
9
53.2
D
10
54.5
J. Elder
Tukey
Comparing Several Means – ANOVA (GLM 1)
58
¨ 
For the Viagra data, we can obtain Tukey post hoc
tests by executing:
postHocs<-glht(viagraModel, linfct = mcp(dose =
"Tukey"))
summary(postHocs)
confint(postHocs)
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Output
59
Comparing Several Means – ANOVA (GLM 1)
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Which Posthoc Test To Use
Comparing Several Means – ANOVA (GLM 1)
60
When doing a full set of post-hoc tests, Tukey is
usually more powerful than Bonferroni.
¨  However, when doing a small number of planned
comparisons, Bonferroni can be more powerful.
¨  Also, Tukey’s assumptions can fail if the sample sizes
are very different – use Bonferroni in this case.
¨ 
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Objectives
Comparing Several Means – ANOVA (GLM 1)
61
Basic principles of ANOVA
¨  Equations underlying one-way ANOVA
¨  Doing a one-way ANOVA in R
¨ 
¨ 
Following up an ANOVA:
¤ Planned
contrasts/comparisons
n Choosing
contrasts
n Coding contrasts
¤ Post
¨ 
hoc tests
ANOVA as regression
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
ANOVA as Regression
62
Comparing Several Means – ANOVA (GLM 1)
outcomei = ( model ) + errori
libidoi = b0 + b2 high i + b1low i + ε i
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
The Data
63
Comparing Several Means – ANOVA (GLM 1)
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Placebo Group
64
Comparing Several Means – ANOVA (GLM 1)
libidoi = b0 + b2 high i + b1low i + ε i
libidoi = b0 + ( b2 × 0 ) + ( b1 × 0 )
libidoi = b0
X placebo = b0
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
High Dose Group
65
Comparing Several Means – ANOVA (GLM 1)
libidoi = b0 + b2 high i + b1low i + ε i
libidoi = b0 + ( b2 ×1) + (b1 × 0 )
libidoi = b0 + b2
libidoi = b0 + b2
X high = X placebo + b2
b2 = X high − X placebo
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Low Dose Group
66
Comparing Several Means – ANOVA (GLM 1)
libidoi = b0 + b2 high i + b1low i + ε i
libidoi = b0 + ( b2 × 0 ) + ( b1 ×1)
libidoi = b0 + b1
libidoi = b0 + b1
X Low = X placebo + b1
b1 = X low − X placebo
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Output from Regression
67
Comparing Several Means – ANOVA (GLM 1)
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder
Experiments vs. Correlation
Comparing Several Means – ANOVA (GLM 1)
68
¨ 
ANOVA in linear regression (continuous IV):
¤  Used
to assess whether the linear regression model
is good at predicting an outcome.
¤  Remember that the model assumes that the DV is a
linear function of the IV.
¨ 
ANOVA in testing means (discrete IV):
¤  Used
to see whether different levels of the IV lead
to differences in an outcome variable (DV).
¤  There is no assumption with regard to linearity of
the DV as a function of the IV.
PSYC 3031 INTERMEDIATE STATISTICS LABORATORY
J. Elder