#Info experiments Exp1: experiment 1 (WS with click detection), adults Exp2A: experiment 2 (WS without click detection), adults Exp2B: experiment 2 (WS without click detection), children Exp3: experiment 3 (WS foils TP=0), adults

1 Prepare working environment

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

2 Load data all experiments

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

WS <- read.delim("./Data/WS_Offline_Exp123.txt", sep="\t", dec=".")
WS$Subject <- as.factor(WS$Subject)
WS$Exp <- as.factor(WS$Exp)

4 Statistical analysis

4.1 Setting sum-to-zero contrasts for the variables Version and TargetOrder

contrast <- cbind(c(-0.5, +0.5)) # Version A, Version B 
colnames (contrast) <-  c("-VersionA+VersionB")
contrasts (WS$Version) <- contrast
contrasts(WS$Version)
##   -VersionA+VersionB
## A               -0.5
## B                0.5
WS$TargetOrder <- factor(WS$TargetOrder)

contrast <- cbind(c(+0.5, -0.5)) # TargetFirst, FoilFirst
colnames (contrast) <-  c("-FoilFirst+TargetFirst")
contrasts (WS$TargetOrder) <- contrast
contrasts(WS$TargetOrder)
##   -FoilFirst+TargetFirst
## 0                    0.5
## 1                   -0.5
#'TargetOrder' reflects whether participants heard the target first or the foil first 

4.2 Exp 1

4.2.1 GLMER full model Exp 1

model1 <- glmer(Accuracy~Version*TargetOrder+(TargetOrder|Subject)+(Version|Item), data=subset(WS, WS$Exp=="1"), control=glmerControl(optCtrl = list(maxfun=2e5)), family=binomial)
## boundary (singular) fit: see ?isSingular
options(width=200)
summary(model1)
## Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
##  Family: binomial  ( logit )
## Formula: Accuracy ~ Version * TargetOrder + (TargetOrder | Subject) +      (Version | Item)
##    Data: subset(WS, WS$Exp == "1")
## Control: glmerControl(optCtrl = list(maxfun = 2e+05))
## 
##      AIC      BIC   logLik deviance df.resid 
##    692.7    735.1   -336.3    672.7      502 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.7272 -0.7805 -0.5821  0.9381  1.9296 
## 
## Random effects:
##  Groups  Name                              Variance Std.Dev. Corr 
##  Subject (Intercept)                       0.2257   0.4751        
##          TargetOrder-FoilFirst+TargetFirst 0.1509   0.3884   -1.00
##  Item    (Intercept)                       0.1721   0.4149        
##          Version-VersionA+VersionB         0.2117   0.4601   1.00 
## Number of obs: 512, groups:  Subject, 32; Item, 16
## 
## Fixed effects:
##                                                             Estimate Std. Error z value Pr(>|z|)  
## (Intercept)                                                  -0.3329     0.1651  -2.016   0.0438 *
## Version-VersionA+VersionB                                     0.5443     0.2806   1.940   0.0524 .
## TargetOrder-FoilFirst+TargetFirst                             0.3253     0.2917   1.115   0.2649  
## Version-VersionA+VersionB:TargetOrder-FoilFirst+TargetFirst   0.3253     0.4684   0.695   0.4873  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) Vr-VA+VB TO-FF+
## Vrsn-VrA+VB  0.171                
## TrgtO-FF+TF -0.142  0.025         
## V-VA+VB:TO-  0.026 -0.201    0.278
## convergence code: 0
## boundary (singular) fit: see ?isSingular
isSingular(model1) # Not singular
## [1] FALSE

4.2.2 Compute confidence intervals Exp 1

4.2.2.1 CIs intercept

### Compute profile confidence intervals for the intercept (i.e. comparison with chance level)
ci <- confint (model1, parm = "(Intercept)")
lower.bound.logodds.model1 <- ci ["(Intercept)", 1]
upper.bound.logodds.model1 <- ci ["(Intercept)", 2]

### Calculate the CIs of the odds and probabilities based on the logodds
lower.bound.odds.model1 <- exp (lower.bound.logodds.model1)
upper.bound.odds.model1 <- exp (upper.bound.logodds.model1)
lower.bound.prob.model1 <- lower.bound.odds.model1 / (lower.bound.odds.model1 + 1)
upper.bound.prob.model1 <- upper.bound.odds.model1 / (upper.bound.odds.model1 + 1)

lower.bound.prob.model1 # 0.3363355
upper.bound.prob.model1 # 0.5000725

#Estimate Intercept:
exp(-0.3329)
0.7168419/(0.7168419+1) # 0.4175352

4.2.2.2 CIs Version effect

### Compute profile confidence intervals for the Version effect
ci <- confint (model1, parm = "Version-VersionA+VersionB")
lower.bound.logodds.model1 <- ci ["Version-VersionA+VersionB", 1]
upper.bound.logodds.model1 <- ci ["Version-VersionA+VersionB", 2]

### Calculate the CIs of the odds and probabilities based on the logodds
lower.bound.odds.model1 <- exp (lower.bound.logodds.model1)
upper.bound.odds.model1 <- exp (upper.bound.logodds.model1)

lower.bound.odds.model1 # 0.9714877
upper.bound.odds.model1 # 3.069883

#Estimate Version effect (in odds):
exp(0.5443) # 1.723402

4.2.2.3 CIs TargetOrder effect

### Compute profile confidence intervals for the TargetOrder effect
ci <- confint (model1, parm = "TargetOrder-FoilFirst+TargetFirst")
lower.bound.logodds.model1 <- ci ["TargetOrder-FoilFirst+TargetFirst", 1]
upper.bound.logodds.model1 <- ci ["TargetOrder-FoilFirst+TargetFirst", 2]

### Calculate the CIs of the odds and probabilities based on the logodds
lower.bound.odds.model1 <- exp (lower.bound.logodds.model1)
upper.bound.odds.model1 <- exp (upper.bound.logodds.model1)

lower.bound.odds.model1 # 0.7583393
upper.bound.odds.model1 # 2.565197

#Estimate TargetOrder effect (in odds):
exp(0.3253) #  1.384446

4.3 Exp 2A: Adults

4.3.1 Full GLMER model Exp 2A

model2 <- glmer(Accuracy~Version*TargetOrder+(TargetOrder|Subject)+(Version|Item), data=subset(WS, WS$Exp=="2A"), control=glmerControl(optCtrl = list(maxfun=2e5)), family=binomial)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : Model failed to converge with max|grad| =
## 0.00147191 (tol = 0.001, component 1)
options(width=120)
summary(model2)
## Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
##  Family: binomial  ( logit )
## Formula: Accuracy ~ Version * TargetOrder + (TargetOrder | Subject) +      (Version | Item)
##    Data: subset(WS, WS$Exp == "2A")
## Control: glmerControl(optCtrl = list(maxfun = 2e+05))
## 
##      AIC      BIC   logLik deviance df.resid 
##    603.4    644.7   -291.7    583.4      447 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.2071 -0.7888 -0.3616  0.7981  2.1360 
## 
## Random effects:
##  Groups  Name                              Variance Std.Dev. Corr 
##  Subject (Intercept)                       0.694801 0.83355       
##          TargetOrder-FoilFirst+TargetFirst 0.005462 0.07391  -1.00
##  Item    (Intercept)                       0.025764 0.16051       
##          Version-VersionA+VersionB         1.971390 1.40406  0.13 
## Number of obs: 457, groups:  Subject, 27; Item, 16
## 
## Fixed effects:
##                                                             Estimate Std. Error z value Pr(>|z|)  
## (Intercept)                                                 -0.02444    0.19804  -0.123   0.9018  
## Version-VersionA+VersionB                                    0.42418    0.52357   0.810   0.4178  
## TargetOrder-FoilFirst+TargetFirst                            0.50792    0.22980   2.210   0.0271 *
## Version-VersionA+VersionB:TargetOrder-FoilFirst+TargetFirst  0.10403    0.82544   0.126   0.8997  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) Vr-VA+VB TO-FF+
## Vrsn-VrA+VB  0.102                
## TrgtO-FF+TF -0.081 -0.002         
## V-VA+VB:TO- -0.001 -0.032    0.098
## convergence code: 0
## Model failed to converge with max|grad| = 0.00147191 (tol = 0.001, component 1)

4.3.2 Compute confidence intervals Exp 2A

4.3.2.1 CIs intercept

### Compute profile confidence intervals for the intercept (i.e. comparison with chance level)
ci <- confint (model2, parm = "(Intercept)")
lower.bound.logodds.model2 <- ci ["(Intercept)", 1]
upper.bound.logodds.model2 <- ci ["(Intercept)", 2]

### Calculate the CIs of the odds and probabilities based on the logodds
lower.bound.odds.model2 <- exp (lower.bound.logodds.model2)
upper.bound.odds.model2 <- exp (upper.bound.logodds.model2)
lower.bound.prob.model2 <- lower.bound.odds.model2 / (lower.bound.odds.model2 + 1)
upper.bound.prob.model2 <- upper.bound.odds.model2 / (upper.bound.odds.model2 + 1)

lower.bound.prob.model2 # 0.3363355
upper.bound.prob.model2 # 0.5000725

#Estimate Intercept:
exp(-0.3329)
0.7168419/(0.7168419+1) # 0.4175352

4.3.2.2 CIs Version effect

### Compute profile confidence intervals for the Version effect
ci <- confint (model2, parm = "Version-VersionA+VersionB")
lower.bound.logodds.model2 <- ci ["Version-VersionA+VersionB", 1]
upper.bound.logodds.model2 <- ci ["Version-VersionA+VersionB", 2]

### Calculate the CIs of the odds and probabilities based on the logodds
lower.bound.odds.model2 <- exp (lower.bound.logodds.model2)
upper.bound.odds.model2 <- exp (upper.bound.logodds.model2)

lower.bound.odds.model2 # 0.5248686
upper.bound.odds.model2 # 4.515306

#Estimate Version effect (in odds):
exp(0.42418) # 1.528337

4.3.2.3 CIs TargetOrder effect

### Compute profile confidence intervals for the TargetOrder effect
ci <- confint (model2, parm = "TargetOrder-FoilFirst+TargetFirst")
lower.bound.logodds.model2 <- ci ["TargetOrder-FoilFirst+TargetFirst", 1]
upper.bound.logodds.model2 <- ci ["TargetOrder-FoilFirst+TargetFirst", 2]

### Calculate the CIs of the odds and probabilities based on the logodds
lower.bound.odds.model2 <- exp (lower.bound.logodds.model2)
upper.bound.odds.model2 <- exp (upper.bound.logodds.model2)

lower.bound.odds.model2 # 0.5248686
upper.bound.odds.model2 # 4.515306

#Estimate TargetOrder effect (in odds):
exp( 0.50792) # 1.661831

4.4 Exp 2B: Children

4.4.1 Full GLMER model Exp 2B

model3 <- glmer(Accuracy~Version*TargetOrder+(TargetOrder|Subject)+(Version|Item), data=subset(WS, WS$Exp=="2B"), control=glmerControl(optCtrl = list(maxfun=100e5)), family=binomial)
## boundary (singular) fit: see ?isSingular
options(width=120)
summary(model3)
## Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
##  Family: binomial  ( logit )
## Formula: Accuracy ~ Version * TargetOrder + (TargetOrder | Subject) +      (Version | Item)
##    Data: subset(WS, WS$Exp == "2B")
## Control: glmerControl(optCtrl = list(maxfun = 1e+07))
## 
##      AIC      BIC   logLik deviance df.resid 
##    602.5    643.2   -291.3    582.5      422 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.5715 -0.9266  0.5602  0.8734  1.5846 
## 
## Random effects:
##  Groups  Name                              Variance Std.Dev. Corr
##  Subject (Intercept)                       0.02908  0.1705       
##          TargetOrder-FoilFirst+TargetFirst 0.26136  0.5112   0.20
##  Item    (Intercept)                       0.02419  0.1555       
##          Version-VersionA+VersionB         1.24908  1.1176   1.00
## Number of obs: 432, groups:  Subject, 27; Item, 16
## 
## Fixed effects:
##                                                             Estimate Std. Error z value Pr(>|z|)
## (Intercept)                                                  0.02718    0.11347   0.240    0.811
## Version-VersionA+VersionB                                   -0.09606    0.35156  -0.273    0.785
## TargetOrder-FoilFirst+TargetFirst                            0.20025    0.23859   0.839    0.401
## Version-VersionA+VersionB:TargetOrder-FoilFirst+TargetFirst  0.54763    0.71839   0.762    0.446
## 
## Correlation of Fixed Effects:
##             (Intr) Vr-VA+VB TO-FF+
## Vrsn-VrA+VB  0.315                
## TrgtO-FF+TF  0.019 -0.003         
## V-VA+VB:TO- -0.003  0.007    0.296
## convergence code: 0
## boundary (singular) fit: see ?isSingular
isSingular(model3)
## [1] FALSE

4.4.2 Compute confidence intervals Exp 2B

4.4.2.1 CIs intercept

### Compute profile confidence intervals for the intercept (i.e. comparison with chance level)
ci <- confint (model3, parm = "(Intercept)")
lower.bound.logodds.model3 <- ci ["(Intercept)", 1]
upper.bound.logodds.model3 <- ci ["(Intercept)", 2]

### Calculate the CIs of the odds and probabilities based on the logodds
lower.bound.odds.model3 <- exp (lower.bound.logodds.model3)
upper.bound.odds.model3 <- exp (upper.bound.logodds.model3)
lower.bound.prob.model3 <- lower.bound.odds.model3 / (lower.bound.odds.model3 + 1)
upper.bound.prob.model3 <- upper.bound.odds.model3 / (upper.bound.odds.model3 + 1)

lower.bound.prob.model3 # 0.4483769
upper.bound.prob.model3 # 0.5651782

#Estimate Intercept:
exp(0.02718)
1.027553/(1.027553+1) # 0.5067946

4.4.2.2 CIs Version effect

### Compute profile confidence intervals for the Version effect
ci <- confint (model3, parm = "Version-VersionA+VersionB")
lower.bound.logodds.model3 <- ci ["Version-VersionA+VersionB", 1]
upper.bound.logodds.model3 <- ci ["Version-VersionA+VersionB", 2]

### Calculate the CIs of the odds and probabilities based on the logodds
lower.bound.odds.model3 <- exp (lower.bound.logodds.model3)
upper.bound.odds.model3 <- exp (upper.bound.logodds.model3)


lower.bound.odds.model3 # 0.4330773
upper.bound.odds.model3 # 1.90173

#Estimate Version effect (in odds):
exp(-0.09606) # 0.9084095

CIs TargetOrder effect

### Compute profile confidence intervals for the TargetOrder effect
ci <- confint (model3, parm = "TargetOrder-FoilFirst+TargetFirst")
lower.bound.logodds.model3 <- ci ["TargetOrder-FoilFirst+TargetFirst", 1]
upper.bound.logodds.model3 <- ci ["TargetOrder-FoilFirst+TargetFirst", 2]

### Calculate the CIs of the odds and probabilities based on the logodds
lower.bound.odds.model3 <- exp (lower.bound.logodds.model3)
upper.bound.odds.model3 <- exp (upper.bound.logodds.model3)

lower.bound.odds.model3 # 0.7497391
upper.bound.odds.model3 # 2.01281

#Estimate TargetOrder effect (in odds):
exp(0.20025) # 1.221708

4.5 Exp 3

4.5.1 Full GLMER model Exp 3

model4 <- glmer(Accuracy~Version*TargetOrder+(TargetOrder|Subject)+(Version|Item), data=subset(WS, WS$Exp=="3"), control=glmerControl(optCtrl = list(maxfun=2e5)), family=binomial)
## boundary (singular) fit: see ?isSingular
options(width=120)
summary(model4)
## Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
##  Family: binomial  ( logit )
## Formula: Accuracy ~ Version * TargetOrder + (TargetOrder | Subject) +      (Version | Item)
##    Data: subset(WS, WS$Exp == "3")
## Control: glmerControl(optCtrl = list(maxfun = 2e+05))
## 
##      AIC      BIC   logLik deviance df.resid 
##   1023.6   1070.0   -501.8   1003.6      755 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.9449 -0.9089  0.5116  0.8267  1.8201 
## 
## Random effects:
##  Groups  Name                              Variance  Std.Dev. Corr 
##  Subject (Intercept)                       2.045e-01 0.452164      
##          TargetOrder-FoilFirst+TargetFirst 6.691e-02 0.258668 -1.00
##  Item    (Intercept)                       2.746e-01 0.524054      
##          Version-VersionA+VersionB         1.143e-06 0.001069 -1.00
## Number of obs: 765, groups:  Subject, 45; Item, 16
## 
## Fixed effects:
##                                                             Estimate Std. Error z value Pr(>|z|)   
## (Intercept)                                                  0.19210    0.16749   1.147  0.25139   
## Version-VersionA+VersionB                                    0.61551    0.20693   2.974  0.00294 **
## TargetOrder-FoilFirst+TargetFirst                            0.51617    0.30859   1.673  0.09439 . 
## Version-VersionA+VersionB:TargetOrder-FoilFirst+TargetFirst  0.05428    0.32311   0.168  0.86659   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) Vr-VA+VB TO-FF+
## Vrsn-VrA+VB  0.002                
## TrgtO-FF+TF -0.055  0.017         
## V-VA+VB:TO-  0.022 -0.194    0.005
## convergence code: 0
## boundary (singular) fit: see ?isSingular
isSingular(model4)
## [1] TRUE

4.5.2 Compute confidence intervals Exp 3

4.5.2.1 CIs intercept

### Compute profile confidence intervals for the intercept (i.e. comparison with chance level)
ci <- confint (model4, parm = "(Intercept)")
lower.bound.logodds.model4 <- ci ["(Intercept)", 1]
upper.bound.logodds.model4 <- ci ["(Intercept)", 2]

### Calculate the CIs of the odds and probabilities based on the logodds
lower.bound.odds.model4 <- exp (lower.bound.logodds.model4)
upper.bound.odds.model4 <- exp (upper.bound.logodds.model4)
lower.bound.prob.model4 <- lower.bound.odds.model2 / (lower.bound.odds.model4 + 1)
upper.bound.prob.model4 <- upper.bound.odds.model2 / (upper.bound.odds.model4 + 1)

lower.bound.prob.model4 # 0.3363355
upper.bound.prob.model4 # 0.5000725

#Estimate Intercept:
exp(-0.3329)
0.7168419/(0.7168419+1) # 0.4175352

4.5.2.2 CIs Version effect

### Compute profile confidence intervals for the Version effect
ci <- confint (model4, parm = "Version-VersionA+VersionB")
lower.bound.logodds.model4 <- ci ["Version-VersionA+VersionB", 1]
upper.bound.logodds.model4 <- ci ["Version-VersionA+VersionB", 2]

### Calculate the CIs of the odds and probabilities based on the logodds
lower.bound.odds.model4 <- exp (lower.bound.logodds.model4)
upper.bound.odds.model4 <- exp (upper.bound.logodds.model4)

lower.bound.odds.model4 # 1.227391
upper.bound.odds.model4 # 2.825969

#Estimate Version effect (in odds):
exp(0.61551) # 1.8506

4.5.2.3 CIs TargetOrder effect

### Compute profile confidence intervals for the TargetOrder effect
ci <- confint (model4, parm = "TargetOrder-FoilFirst+TargetFirst")
lower.bound.logodds.model4 <- ci ["TargetOrder-FoilFirst+TargetFirst", 1]
upper.bound.logodds.model4 <- ci ["TargetOrder-FoilFirst+TargetFirst", 2]

### Calculate the CIs of the odds and probabilities based on the logodds
lower.bound.odds.model4 <- exp (lower.bound.logodds.model4)
upper.bound.odds.model4 <- exp (upper.bound.logodds.model4)

lower.bound.odds.model4 # 0.8845244
upper.bound.odds.model4 # 3.217961

#Estimate TargetOrder effect (in odds):
exp(0.51617) # 1.661831