str(AY_corr)
## 'data.frame': 3737 obs. of 6 variables:
## $ subID : Factor w/ 164 levels "sub01","sub04",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ groupID: Factor w/ 2 levels "AE","UAA": 2 2 2 2 2 2 2 2 2 2 ...
## $ timeID : Factor w/ 2 levels "post","pre": 2 2 2 2 2 2 2 2 2 2 ...
## $ trialID: int 4 5 30 36 43 57 66 68 89 93 ...
## $ condnID: Factor w/ 1 level "AY": 1 1 1 1 1 1 1 1 1 1 ...
## $ corr : int 1 0 1 1 1 1 1 1 1 1 ...
summary(GHQ <- glmer(corr ~ groupID + timeID + groupID * timeID + (1+groupID*timeID | subID), data = AY_corr,family = "binomial"))
## Generalized linear mixed model fit by maximum likelihood (Laplace
## Approximation) [glmerMod]
## Family: binomial ( logit )
## Formula:
## corr ~ groupID + timeID + groupID * timeID + (1 + groupID * timeID |
## subID)
## Data: AY_corr
##
## AIC BIC logLik deviance df.resid
## 2830.9 2918.1 -1401.5 2802.9 3723
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.8922 0.1896 0.2830 0.3982 1.6384
##
## Random effects:
## Groups Name Variance Std.Dev. Corr
## subID (Intercept) 1.3594 1.1659
## groupIDUAA 0.7235 0.8506 -0.43
## timeIDpre 1.1480 1.0714 -0.46 0.27
## groupIDUAA:timeIDpre 1.5913 1.2615 -0.01 -0.35 0.04
## Number of obs: 3737, groups: subID, 164
##
## Fixed effects:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 2.4922 0.2058 12.111 <2e-16 ***
## groupIDUAA -0.2905 0.2811 -1.034 0.3014
## timeIDpre -0.5559 0.2359 -2.357 0.0184 *
## groupIDUAA:timeIDpre 0.8016 0.3783 2.119 0.0341 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) grIDUAA tmIDpr
## groupIDUAA -0.732
## timeIDpre -0.680 0.498
## grpIDUAA:ID 0.424 -0.596 -0.623
#Interactions are significant.
GHQ <- glmer(corr ~ groupID + timeID + groupID * timeID + (groupID*timeID | subID), data = AY_corr,family = "binomial")
AY_corr$fit <- predict(GHQ)
time_order <- c('pre', 'post')
ggplot(AY_corr, aes(x=factor(timeID, level = time_order), y=accuracy, group=subID, col=groupID)) +
scale_color_manual(values=wes_palette(n=3, name="GrandBudapest1")) +
facet_grid(~groupID) +
geom_line(aes(y=fit), size=0.5) +
geom_hline(yintercept=0, linetype="dashed") +
theme_bw()