-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathANCOVA.R
67 lines (44 loc) · 2.02 KB
/
ANCOVA.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
library(afex)
afex_options(es_aov = 'pes',
correction_aov = 'GG',
emmeans_model = 'univariate')
# Load Data ---------------------------------------------------------------
# Load data (is RDS file - these are R files the contain objects, in our
# case, a tidy data-frame)
Alcohol_data <- readRDS("Alcohol_data.rds")
head(Alcohol_data)
# Fit ANOVA model ---------------------------------------------------------
ersp_anova <- aov_ez('Subject','ersp',Alcohol_data,
within = c('Frequency','Correctness'),
between = c('Alcohol'))
ersp_anova
# But mothers education level is related to the outcome..
# We probably would want to control for it - reduce the MSE..
# Fit ANCOVA model --------------------------------------------------------
# Keep in mind that some have argued that the use (or misuse) of ANCOVA
# should be avoided. See: http://doi.org/10.1037//0021-843X.110.1.40
ersp_ancova <- aov_ez('Subject','ersp',Alcohol_data,
within = c('Frequency','Correctness'),
between = c('Alcohol'),
# The new bits:
covariate = 'mograde',
factorize = FALSE) # MUST set `factorize = FALSE`!
# Note the warning!
ersp_anova
ersp_ancova
# Center the covariate and re-fit the model -------------------------------
# Why center the covariate? See Centering Variables for ANOVA.docx for an
# extremely detailed explanation.
Alcohol_data$mograde_c <- scale(Alcohol_data$mograde,
center = TRUE, scale = FALSE)
# Re-Fit model
ersp_ancova2 <- aov_ez('Subject','ersp',Alcohol_data,
within = c('Frequency','Correctness'),
between = c('Alcohol'),
# The new bits
covariate = 'mograde_c', factorize = FALSE)
ersp_anova
ersp_ancova
ersp_ancova2 # Huge difference!
# Follow up analysis ------------------------------------------------------
# use emmeans as usual (: