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/13166/rs-lmer-cheat-sheet

Dataset

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()