ANCOVA (GLM2)
Prof. Andy Field
Slide 1
Aims
When and Why do we use
ANCOVA?
Partitioning Variance
Carrying outANCOVA using R
Interpretation
Main Effects
Covariates
Slide 2
Slide 3
Advantages of ANCOVA
Reduces Error Variance
By explaining some of the
unexplained variance (SSR) the error
variance in the model can be
reduced.
Variance
SST
Total Variance In The Data
SSM
Improvement Due to the Model
SSR
Error in Model
Covariate
Slide 5
SSR
An Example
We will use Fields (2012) Viagra
example (from the ANOVA lecture).
There are several possible confounding
variables e.g. Partners libido, medication.
Homogeneity of Regression
Slopes
Slide 9
Slide 10
Boxplotsof theViagradata
Slide 11
Contrasts
Contrast 1: Compare the placebo group to all doses of Viagra.
Contrast 2: Compared the high and low doses:
contrasts(viagraData$dose)<-cbind(c(-2,1,1), c(0,-1,1))
The first line sets the contrasts for dose, the second line
creates the ANCOVA model, and the third line prints the
model summary with Type III sums of squares.
Slide 16
Planned Contrasts in
ANCOVA
The overall ANCOVA does not tell
us which means differ, so to break
down the overall effect of dose we
need to look at the contrasts that
we specified before we created the
ANCOVA model:
summary.lm(viagraModel)
Planned Contrasts in
ANCOVA
The Covariate
Slide 19
Plots in ANCOVA
Residuals vs Fitted
Residuals vs Fitted
18
18
29
2
-2
Residuals
0
-2
19
-4
19
-4
Residuals
29
Fitted values
aov(libido ~ partnerLibido + dose)
Fitted values
aov(libido ~ partnerLibido + dose)
Robust ANCOVA
Looking at the effect that wearing a cloak of
invisibility has on peoples tendency for mischief:
Recorded how many mischievous acts everyone
conducted in the first 3 weeks (mischief1).
After three weeks we told about half of the sample (N =
34) that we were switching the cameras off so that noone would be able to see what they were getting up to
The remainder (N = 46) were given a cloak of invisibility.
We recorded the number of mischievous acts over the
next 3 weeks (mischief2).
Boxplots
Boxplotsof theinvisibilitydata
Group 1
Group 2
1
2
3
4
5
6
27
28
29
30
31
32
33
34
35
36
37
38
39
75
76
77
78
79
80
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Covariate
Outcome
dvGrp1
Cloak
4
9
Cloak
4
9
Cloak
4
11
Cloak
1
9
Cloak
3
8
Cloak
3
6
Cloak
5
12
Cloak
4
10
Cloak
1
10
Cloak
7
10
Cloak
7
9
Cloak
6
12
Cloak
9
11
Cloak
4
13
Cloak
7
9
Cloak
2
10
Cloak
3
8
Cloak
6
10
Cloak
0
10
covGrp2
dvGrp2
Conducting Robust
ANCOVA
ancova(covGrp1, dvGrp1, covGrp2,
dvGrp2)
ancboot(covGrp1, dvGrp1, covGrp2,
dvGrp2, nboot = 2000)
Output
12
10
8
6
+
+
+
+
+
+
10