--- title: "Experiment 1, 2 and 3: Offline task" author: "Iris Broedelet" date: "14/11/2019" output: html_document: code_folding: show number_sections: yes theme: paper toc: yes toc_float: yes --- #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 # Prepare working environment ```{r} rm(list = ls()) # Empty environment library("ggplot2") library("lme4") ``` # Load data all experiments You need a folder named "Data" in which the data file is placed ```{r} WS <- read.delim("./Data/WS_Offline_Exp123.txt", sep="\t", dec=".") WS$Subject <- as.factor(WS$Subject) WS$Exp <- as.factor(WS$Exp) ``` # Print some descriptives ```{r} mean(WS$Accuracy[WS$Exp == "1"]) # Mean acc Exp 1 = 0.4335938 sd(WS$MeanAccPP[WS$Exp == "1"]) # SD = 0.1753253 mean(WS$Accuracy[WS$Exp == "2A"]) # Mean acc Exp 2A = 0.4901532 sd(WS$MeanAccPP[WS$Exp == "2A"]) # SD = 0.2024202 mean(WS$Accuracy[WS$Exp == "2B"]) # Mean acc Exp 2B = 0.5069444 sd(WS$MeanAccPP[WS$Exp == "2B"]) # SD = 0.1266805 mean(WS$Accuracy[WS$Exp == "3"]) # Mean acc Exp 3 = 0.5424837 sd(WS$MeanAccPP[WS$Exp == "3"]) # SD = 0.1622186 ``` # Statistical analysis ## Setting sum-to-zero contrasts for the variables Version and TargetOrder ```{r} contrast <- cbind(c(-0.5, +0.5)) # Version A, Version B colnames (contrast) <- c("-VersionA+VersionB") contrasts (WS$Version) <- contrast contrasts(WS$Version) 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) #'TargetOrder' reflects whether participants heard the target first or the foil first ``` ## Exp 1 ### GLMER full model Exp 1 ```{r} model1 <- glmer(Accuracy~Version*TargetOrder+(TargetOrder|Subject)+(Version|Item), data=subset(WS, WS$Exp=="1"), control=glmerControl(optCtrl = list(maxfun=2e5)), family=binomial) options(width=200) summary(model1) isSingular(model1) # Not singular ``` ### Compute confidence intervals Exp 1 #### CIs intercept ```{r, eval=F, echo=T} ### 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 ``` #### CIs Version effect ```{r, eval=F, echo=T} ### 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 ``` #### CIs TargetOrder effect ```{r, eval=F, echo=T} ### 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 ``` ## Exp 2A: Adults ### Full GLMER model Exp 2A ```{r} model2 <- glmer(Accuracy~Version*TargetOrder+(TargetOrder|Subject)+(Version|Item), data=subset(WS, WS$Exp=="2A"), control=glmerControl(optCtrl = list(maxfun=2e5)), family=binomial) options(width=120) summary(model2) ``` ### Compute confidence intervals Exp 2A #### CIs intercept ```{r, eval=F, echo=T} ### 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 ``` #### CIs Version effect ```{r, eval=F, echo=T} ### 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 ``` #### CIs TargetOrder effect ```{r, eval=F, echo=T} ### 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 ``` ## Exp 2B: Children ### Full GLMER model Exp 2B ```{r} model3 <- glmer(Accuracy~Version*TargetOrder+(TargetOrder|Subject)+(Version|Item), data=subset(WS, WS$Exp=="2B"), control=glmerControl(optCtrl = list(maxfun=100e5)), family=binomial) options(width=120) summary(model3) isSingular(model3) ``` ### Compute confidence intervals Exp 2B #### CIs intercept ```{r, eval=F, echo=T} ### 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 ``` #### CIs Version effect ```{r, eval=F, echo=T} ### 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 ```{r, eval=F, echo=T} ### 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 ``` ## Exp 3 ### Full GLMER model Exp 3 ```{r} model4 <- glmer(Accuracy~Version*TargetOrder+(TargetOrder|Subject)+(Version|Item), data=subset(WS, WS$Exp=="3"), control=glmerControl(optCtrl = list(maxfun=2e5)), family=binomial) options(width=120) summary(model4) isSingular(model4) ``` ### Compute confidence intervals Exp 3 #### CIs intercept ```{r, eval=F, echo=T} ### 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 ``` #### CIs Version effect ```{r, eval=F, echo=T} ### 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 ``` #### CIs TargetOrder effect ```{r, eval=F, echo=T} ### 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 ```