A set of subjects from two groups are requested to perform a test after a sleep session of type A
and then after a sleep session of type B
.
My data frame pdf
has then an independent variable Acc
(accuracy) which contains the accuracy score (percentage of correct responses) of each subject after each session type. I am interested in the effect of Group
and SessionType
in the accuracy score. Since the same subjects are tested on each of the session types, a repeated measures two- way ANOVA is needed, or alternatively a linear mixed-effects model. For flexibility, I chose the latter.
I have fitted a linear mixed-effects model using the lmer
package:
model <- lmer(Acc ~ Group * SessionType + (1 | Subject), pdf, REML = FALSE)
After fitting the model, I was curious to see what the ANOVA test would tell me. So I used the anova
function from the stats
package over the linear model:
anov <- anova(model)
I expected the linear mixed-effects and the ANOVA to tell me more or less the same thing. Although one speaks of differences in mean and the other of linear coefficients, they should be (to my understanding) essentially the same. However, as you can see in the image below, they show quite different results.
tab_model(anov, model, dv.labels=c("Accuracy ANOVA", "Accuracy LME"))
In particular, the linear model concludes that there's no reason to believe the coefficient associated to the Group
variable is different from zero, while the ANOVA model finds a significant difference between the means of both groups.
Am I misunderstanding something? How should these results be interpreted?
Edit: I include a summary of the model and of the data frame.
> str(pdf)
tibble [88 × 8] (S3: tbl_df/tbl/data.frame)
$ Subject : Factor w/ 48 levels "17","18","19",..: 1 1 2 2 3 3 4 4 5 5 ...
$ SessionType: Factor w/ 2 levels "BL","SWD": 1 2 1 2 1 2 1 2 1 2 ...
$ Group : Factor w/ 2 levels "HC","MDD": 1 1 2 2 2 2 2 2 2 2 ...
$ ErrsOfCom : int [1:88] 0 0 0 0 2 4 0 0 3 0 ...
$ ErrsOfOm : int [1:88] 7 12 13 12 9 7 13 8 12 10 ...
$ TotalErrors: int [1:88] 7 12 13 12 11 11 13 8 15 10 ...
$ Acc : num [1:88] 0.912 0.85 0.838 0.85 0.863 ...
$ AvgRT : num [1:88] 70.7 49.5 45.6 49.1 60.7 ...
> summary(model)
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: Acc ~ Group * SessionType + (1 | Subject)
Data: pdf
REML criterion at convergence: -291.1
Scaled residuals:
Min 1Q Median 3Q Max
-2.09564 -0.50489 -0.05255 0.48803 1.77343
Random effects:
Groups Name Variance Std.Dev.
Subject (Intercept) 0.0006677 0.02584
Residual 0.0008636 0.02939
Number of obs: 85, groups: Subject, 45
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 0.865222 0.010335 73.483602 83.722 <2e-16 ***
GroupMDD -0.007741 0.012758 72.880478 -0.607 0.5459
SessionTypeSWD 0.026002 0.011174 42.944520 2.327 0.0247 *
GroupMDD:SessionTypeSWD -0.021414 0.013696 42.113553 -1.563 0.1254
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) GrpMDD SsTSWD
GroupMDD -0.810
SessnTypSWD -0.566 0.459
GrMDD:STSWD 0.462 -0.563 -0.816