--- title: "Experiment 1: ClickDetection task" author: "Iris Broedelet" date: "14/11/2019" output: html_document: code_folding: show number_sections: yes theme: paper toc: yes toc_float: yes --- # Prepare working environment ```{r} rm(list = ls()) # Empty environment library("ggplot2") library("lme4") ``` # Load data You need a folder named "Data" in which the data file is placed ```{r} ClickData <- read.delim("./Data/Exp1_ClickDetection.txt", sep="\t", dec=",") ``` # Print some descriptives ```{r} #Mean normalized RT per ClickContext and Block tapply(ClickData$RTNorm, list(ClickData$ClickContext),mean,na.rm=TRUE) #Mean normalized RT per Block tapply(ClickData$RTNorm, list(ClickData$Block),mean,na.rm=TRUE) #Mean normalized RT per ClickContext and Block tapply(ClickData$RTNorm, list(ClickData$ClickContext, ClickData$Block),mean,na.rm=TRUE) ``` # Data analysis ## Setting sum-to-zero contrasts for the variables ClickContext and Version + centering the variable Block ```{r} 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) contrasts(ClickData$Version) ClickData$Block <- ClickData$Block -2.5 ``` ## GLMER full model ```{r} model <- lmer(RTNorm~ClickContext*Block*Version + (ClickContext*Block|Subject) + (Version|Syl), data=ClickData, control=lmerControl(optCtrl = list(maxfun=2e5))) options(width=400) summary(model) isSingular(model) # Model is not singular ``` ## Computing confindence intervals for effects ### Compute CIs for effect of ClickContext (estimate = 0.001346) ```{r, eval=F, echo=T} 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 ``` ### Compute CIs for effect of Block (estimate = 0.023583) ```{r, eval=F, echo=T} 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 ``` ### Compute CIs for interaction between ClickContext x Block (estimate = -0.040443) ```{r, eval=F, echo=T} 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 ``` ### Compute CIs for interaction between ClickContext x Block x Version (estimate = -0.160448) ```{r} ci <- confint (model, parm = "ClickContext-ClickBetween+ClickWithin:Block:Version-versionA+versionB") 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 upper.bound.logodds.model # 0.01789951 ``` ## Computing *p* values for effects ### Get *p* value function ```{r} 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 } ``` ### Compute *p* value for effect of ClickContext ```{r} profile <- profile(model, which = "ClickContext-ClickBetween+ClickWithin") confint <- confint(profile, level = 0.975) get.p.value(profile) # p = 0.9759977 ``` ### Compute *p* value for effect of Block ```{r} profile <- profile(model, which = "Block") confint <- confint(profile, level = 0.975) get.p.value(profile) # p = 0.3466513 ``` ### Compute *p* value for interaction between ClickContext x Block ```{r} profile <- profile(model, which = "ClickContext-ClickBetween+ClickWithin:Block") confint <- confint(profile, level = 0.975) get.p.value(profile) # p = 0.2649057 ``` ### Compute *p* value for interaction between ClickContext x Block x Version ```{r} profile <- profile(model, which = "ClickContext-ClickBetween+ClickWithin:Block:Version-versionA+versionB") confint <- confint(profile, level = 0.975) get.p.value(profile) # p = 0.02746652 * ```