str(BX_corr)
## 'data.frame': 3735 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 2 12 29 31 48 58 65 72 87 99 ...
## $ condnID: Factor w/ 1 level "BX": 1 1 1 1 1 1 1 1 1 1 ...
## $ corr : int 1 1 0 1 0 1 1 1 1 1 ...
#Interactions are not significant.
summary(GHQ <- glmer(corr ~ groupID * timeID + (timeID|subID), data = BX_corr,family = "binomial"))
## Generalized linear mixed model fit by maximum likelihood (Laplace
## Approximation) [glmerMod]
## Family: binomial ( logit )
## Formula: corr ~ groupID * timeID + (timeID | subID)
## Data: BX_corr
##
## AIC BIC logLik deviance df.resid
## 2428.3 2471.9 -1207.2 2414.3 3728
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -4.2759 0.1293 0.1883 0.3150 2.5791
##
## Random effects:
## Groups Name Variance Std.Dev. Corr
## subID (Intercept) 2.484 1.576
## timeIDpre 3.521 1.876 -0.21
## Number of obs: 3735, groups: subID, 164
##
## Fixed effects:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 2.62790 0.23439 11.212 <2e-16 ***
## groupIDUAA 0.13283 0.32321 0.411 0.681
## timeIDpre -0.01466 0.31994 -0.046 0.963
## groupIDUAA:timeIDpre 0.14212 0.42402 0.335 0.737
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) grIDUAA tmIDpr
## groupIDUAA -0.623
## timeIDpre -0.427 0.233
## grpIDUAA:ID 0.241 -0.411 -0.603
GHQ <- glmer(corr ~ groupID * timeID + (timeID|subID), data = BX_corr,family = "binomial")
BX_corr$fit <- predict(GHQ)
time_order <- c('pre', 'post')
ggplot(BX_corr, aes(x=factor(timeID, level = time_order), y=corr, 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()
**Note: Adding an interaction term for groupID*timeID as a random effect on subID does not help converge the model.**
corr = response variable
groupID+timeID+groupID*timeID = fixed effects
(1|subID) = random intercept for subject
(timeID-1|subID) = random slope for subject that is “due to time” (performance post would likely be different from pre). The random slope is considered independent of the random intercept since we can’t be sure that subjects who start out higher than average will show the greatest change. No theoeretical rationale to suppose that. The specific syntax, “timeID-1” allows one to suppress the intercept term for time. Also, as a sidenote/follow-up, adding (groupID-1) did not allow the model to converge. timeID-1