1 Prepare working environment

rm(list = ls()) # Empty environment
library("ggplot2")
library("lme4")
## Loading required package: Matrix

2 Load data

You need a folder named “Data” in which the data file is placed

ClickData <- read.delim("./Data/Exp1_ClickDetection.txt", sep="\t", dec=",")

4 Data analysis

4.1 Setting sum-to-zero contrasts for the variables ClickContext and Version + centering the variable Block

contrast <- cbind(c(-0.5, +0.5)) # ClickBetween, ClickWithin 
colnames (contrast) <-  c("-ClickBetween+ClickWithin")
contrasts (ClickData$ClickContext) <- contrast

contrast <- cbind(c(-0.5, +0.5)) # Version A, version B 
colnames (contrast) <-  c("-versionA+versionB")
contrasts (ClickData$Version) <- contrast

contrasts(ClickData$ClickContext)
##              -ClickBetween+ClickWithin
## ClickBetween                      -0.5
## ClickWithin                        0.5
contrasts(ClickData$Version)
##   -versionA+versionB
## A               -0.5
## B                0.5
ClickData$Block <- ClickData$Block -2.5

4.2 GLMER full model

model <- lmer(RTNorm~ClickContext*Block*Version + (ClickContext*Block|Subject) + (Version|Syl), data=ClickData, control=lmerControl(optCtrl = list(maxfun=2e5)))
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : Model failed to converge with max|grad| = 0.00739338 (tol = 0.002, component 1)
options(width=400)
summary(model)
## Linear mixed model fit by REML ['lmerMod']
## Formula: RTNorm ~ ClickContext * Block * Version + (ClickContext * Block |      Subject) + (Version | Syl)
##    Data: ClickData
## Control: lmerControl(optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 5209.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9076 -0.6670 -0.0200  0.6191  4.0942 
## 
## Random effects:
##  Groups   Name                                        Variance Std.Dev. Corr             
##  Subject  (Intercept)                                 0.343911 0.58644                   
##           ClickContext-ClickBetween+ClickWithin       0.012249 0.11067   0.27            
##           Block                                       0.012862 0.11341  -0.04 -0.30      
##           ClickContext-ClickBetween+ClickWithin:Block 0.013113 0.11451  -0.72  0.30 -0.57
##  Syl      (Intercept)                                 0.001783 0.04223                   
##           Version-versionA+versionB                   0.002513 0.05013  1.00             
##  Residual                                             0.612702 0.78275                   
## Number of obs: 2142, groups:  Subject, 30; Syl, 8
## 
## Fixed effects:
##                                                                        Estimate Std. Error t value
## (Intercept)                                                            0.012923   0.109662   0.118
## ClickContext-ClickBetween+ClickWithin                                 -0.001344   0.043381  -0.031
## Block                                                                  0.023584   0.025736   0.916
## Version-versionA+versionB                                             -0.399033   0.218005  -1.830
## ClickContext-ClickBetween+ClickWithin:Block                           -0.040443   0.037084  -1.091
## ClickContext-ClickBetween+ClickWithin:Version-versionA+versionB       -0.133803   0.099167  -1.349
## Block:Version-versionA+versionB                                       -0.079608   0.051467  -1.547
## ClickContext-ClickBetween+ClickWithin:Block:Version-versionA+versionB -0.160441   0.074186  -2.163
## 
## Correlation of Fixed Effects:
##             (Intr) ClC-CB+CW Block  Vr-A+B ClC-CB+CW:B CC-CB+CW:V B:V-A+
## ClckC-CB+CW  0.122                                                      
## Block       -0.030 -0.113                                               
## Vrsn-vrsA+B -0.055 -0.008     0.002                                     
## ClC-CB+CW:B -0.399  0.079    -0.270  0.029                              
## CC-CB+CW:V- -0.007  0.198     0.015  0.107 -0.002                       
## Blck:Vr-A+B  0.002  0.017    -0.066 -0.030  0.027      -0.099           
## CC-CB+CW:B:  0.029 -0.002     0.026 -0.402 -0.064       0.069     -0.270
## convergence code: 0
## Model failed to converge with max|grad| = 0.00739338 (tol = 0.002, component 1)
isSingular(model) # Model is not singular
## [1] FALSE

4.3 Computing confindence intervals for effects

4.3.1 Compute CIs for effect of ClickContext (estimate = 0.001346)

ci <- confint (model, parm = "ClickContext-ClickBetween+ClickWithin")
lower.bound.logodds.model <- ci ["ClickContext-ClickBetween+ClickWithin", 1]
upper.bound.logodds.model <- ci ["ClickContext-ClickBetween+ClickWithin", 2]

lower.bound.logodds.model # -0.0866034
upper.bound.logodds.model # 0.08368011

4.3.2 Compute CIs for effect of Block (estimate = 0.023583)

ci <- confint (model, parm = "Block")
lower.bound.logodds.model <- ci ["Block", 1]
upper.bound.logodds.model <- ci ["Block", 2]

lower.bound.logodds.model # -0.02544915
upper.bound.logodds.model # 0.07217663

4.3.3 Compute CIs for interaction between ClickContext x Block (estimate = -0.040443)

ci <- confint (model, parm = "ClickContext-ClickBetween+ClickWithin:Block")
lower.bound.logodds.model <- ci ["ClickContext-ClickBetween+ClickWithin:Block", 1]
upper.bound.logodds.model <- ci ["ClickContext-ClickBetween+ClickWithin:Block", 2]

lower.bound.logodds.model # -0.1121578
upper.bound.logodds.model # 0.03078924

4.3.4 Compute CIs for interaction between ClickContext x Block x Version (estimate = -0.160448)

ci <- confint (model, parm = "ClickContext-ClickBetween+ClickWithin:Block:Version-versionA+versionB")
## Computing profile confidence intervals ...
lower.bound.logodds.model <- ci ["ClickContext-ClickBetween+ClickWithin:Block:Version-versionA+versionB", 1]
upper.bound.logodds.model <- ci ["ClickContext-ClickBetween+ClickWithin:Block:Version-versionA+versionB", 2]

lower.bound.logodds.model # -0.3038538
## [1] -0.3038538
upper.bound.logodds.model # 0.01789951
## [1] -0.01789946

4.4 Computing p values for effects

4.4.1 Get p value function

get.p.value <- function (profile) {
  pmin <- 0.0
  pmax <- 1.0
  for (i in 1:50) {
    pmid <- 0.5 * (pmin + pmax)
    ci <- confint (profile, level = 1.0 - pmid)
    if (ci [1, 1] < 0.0 && ci [1, 2] > 0.0) {
      pmin <- pmid
    } else {
      pmax <- pmid
    }
  }
  pmid
}

4.4.2 Compute p value for effect of ClickContext

profile <- profile(model, which = "ClickContext-ClickBetween+ClickWithin")
confint <- confint(profile, level = 0.975)
get.p.value(profile) # p = 0.9759977
## [1] 0.9759977

4.4.3 Compute p value for effect of Block

profile <- profile(model, which = "Block")
confint <- confint(profile, level = 0.975)
get.p.value(profile) # p = 0.3466513
## [1] 0.3466513

4.4.4 Compute p value for interaction between ClickContext x Block

profile <- profile(model, which = "ClickContext-ClickBetween+ClickWithin:Block")
confint <- confint(profile, level = 0.975)
get.p.value(profile) # p = 0.2649057
## [1] 0.2649057

4.4.5 Compute p value for interaction between ClickContext x Block x Version

profile <- profile(model, which = "ClickContext-ClickBetween+ClickWithin:Block:Version-versionA+versionB")
confint <- confint(profile, level = 0.975)
get.p.value(profile) # p = 0.02746652 *
## [1] 0.02746652