References

  1. https://stats.stackexchange.com/questions/111010/interpreting-qqplot-is-there-any-rule-of-thumb-to-decide-for-non-normality/111013#111013 determining normality from qqplots
  2. https://stats.stackexchange.com/questions/101274/how-to-interpret-a-qq-plot
  3. https://stats.stackexchange.com/questions/61055/r-how-to-interpret-the-qqplots-outlier-numbers
  4. https://ase.tufts.edu/gsc/gradresources/guidetomixedmodelsinr/mixed%20model%20guide.html
  5. https://stats.stackexchange.com/questions/226946/r-lmer-vs-glmer
  6. https://www.r-bloggers.com/linear-mixed-models-in-r/
  7. https://stats.stackexchange.com/questions/283375/violated-normality-of-residuals-assumption-in-linear-mixed-model
  8. https://stats.stackexchange.com/questions/48671/what-is-restricted-maximum-likelihood-and-when-should-it-be-used
  9. https://stats.stackexchange.com/questions/77313/why-cant-i-match-glmer-family-binomial-output-with-manual-implementation-of-g
  10. https://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_glimmix_a0000001433.htm For line about why crossed random effects can be handled with the Laplace approximation (nAHQ=1) but not with quadrature (nAHQ > 1); see code for glmer further below
  11. http://andrewgelman.com/2006/04/10/log_transformat/
  12. https://stats.stackexchange.com/questions/47840/linear-model-with-log-transformed-response-vs-generalized-linear-model-with-log to transform or not to transform, and choosing GLMM over LMM
  13. https://www.frontiersin.org/articles/10.3389/fpsyg.2015.01171/full#h8 see also supplementary material
  14. https://stats.stackexchange.com/questions/110004/how-scared-should-we-be-about-convergence-warnings-in-lme4 glmer model convergence error
  15. https://stats.stackexchange.com/questions/254361/modeling-reaction-time-with-glmer
  16. https://datascienceplus.com/r-for-publication-by-page-piccinini-lesson-6-part-1-linear-mixed-effects-models-lmem/ modeling accuracy
  17. https://stats.stackexchange.com/questions/31569/questions-about-how-random-effects-are-specified-in-lmer syntax for mixed effect models
  18. https://stats.stackexchange.com/questions/13166/rs-lmer-cheat-sheet

Dataset

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.**


Syntax explanation:

  1. corr = response variable

  2. groupID+timeID+groupID*timeID = fixed effects

  3. (1|subID) = random intercept for subject

  4. (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


More here: https://stats.stackexchange.com/questions/31569/questions-about-how-random-effects-are-specified-in-lmer