1 data input

dta <- read.csv("visual_search.csv")
head(dta)
##   Participant      Dx Set.Size      RT
## 1        9129 Control        1  786.50
## 2        9051 Control        1  935.83
## 3        9126 Control        1  750.83
## 4       9171* Control        1 1129.50
## 5        9176 Control        1 1211.33
## 6        9167 Control        1 1178.83
str(dta)
## 'data.frame':    132 obs. of  4 variables:
##  $ Participant: chr  "9129" "9051" "9126" "9171*" ...
##  $ Dx         : chr  "Control" "Control" "Control" "Control" ...
##  $ Set.Size   : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ RT         : num  786 936 751 1130 1211 ...

2 data management

dta$Participant <- factor(dta$Participant)
dta$Dx <- factor(dta$Dx)
str(dta)
## 'data.frame':    132 obs. of  4 variables:
##  $ Participant: Factor w/ 33 levels "0042","0044",..: 19 16 18 25 28 22 24 23 26 27 ...
##  $ Dx         : Factor w/ 2 levels "Aphasic","Control": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Set.Size   : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ RT         : num  786 936 751 1130 1211 ...

3 plot1

library(ggplot2)
p <- ggplot(dta, 
            aes(Set.Size, RT)) +
 geom_line(aes(group=Participant), alpha=0.5) +
 stat_smooth(aes(group=Dx), 
             method="lm", 
             formula= y ~ x) +
 geom_point(alpha=0.5) +
 facet_wrap( ~ Dx) +
 labs(x="Set size", 
      y="Reaction time (ms)") +
 theme_minimal()
suppressWarnings(suppressMessages(ggplot2:::print.ggplot(p)))

4 model

library(lme4)
## Loading required package: Matrix
model <- lmer(RT ~ Set.Size + Dx + Set.Size*Dx + (Set.Size|Participant), dta)
## boundary (singular) fit: see ?isSingular
summary(model)
## Linear mixed model fit by REML ['lmerMod']
## Formula: RT ~ Set.Size + Dx + Set.Size * Dx + (Set.Size | Participant)
##    Data: dta
## 
## REML criterion at convergence: 2186.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.7577 -0.3130 -0.0750  0.3117  6.1372 
## 
## Random effects:
##  Groups      Name        Variance Std.Dev. Corr
##  Participant (Intercept) 657489.0 810.86       
##              Set.Size       407.4  20.18   1.00
##  Residual                772445.8 878.89       
## Number of obs: 132, groups:  Participant, 33
## 
## Fixed effects:
##                    Estimate Std. Error t value
## (Intercept)         2078.75     270.97   7.672
## Set.Size              73.49      11.40   6.446
## DxControl          -1106.05     366.89  -3.015
## Set.Size:DxControl   -21.74      15.44  -1.408
## 
## Correlation of Fixed Effects:
##             (Intr) Set.Sz DxCntr
## Set.Size    -0.071              
## DxControl   -0.739  0.053       
## St.Sz:DxCnt  0.053 -0.739 -0.071
## convergence code: 0
## boundary (singular) fit: see ?isSingular
sjPlot::tab_model(model, show.obs=F, show.ngroups=F, show.r2=FALSE, show.re.var=F,show.icc=F, show.se=T)
  RT
Predictors Estimates std. Error CI p
(Intercept) 2078.75 270.97 1547.66 – 2609.84 <0.001
Set.Size 73.49 11.40 51.15 – 95.84 <0.001
Dx [Control] -1106.05 366.89 -1825.15 – -386.95 0.003
Set.Size * Dx [Control] -21.74 15.44 -52.00 – 8.52 0.159

5 Means and error bars

pd <- position_dodge(width=.2)
p1 <- ggplot(dta, 
       aes(Set.Size, RT, 
           shape=Dx, linetype=Dx)) +
  geom_smooth(method='lm', formula= y~x, se=FALSE)+
 stat_summary(fun="mean", geom="line", position=pd) +
 stat_summary(fun="mean", geom="point", position=pd) +
 stat_summary(fun.data=mean_se, 
              geom="errorbar", 
              position=pd, linetype="solid", width=0.5) +
 scale_shape_manual(values = c(1, 2, 16)) +labs(x="Set.Size", 
      y="Reaction time (ms)", 
      linetype="Group", shape="Group") +
 scale_x_continuous(breaks=seq(0,30,by=10))+
 theme_minimal()+
 theme(legend.justification=c(0.1, 1), 
       legend.position=c(0.1, 1),
       legend.background=element_rect(fill="white", 
                                      color="black"))
suppressWarnings(suppressMessages(ggplot2:::print.ggplot(p1)))

6 Residuals plots

plot(model, resid(., scaled=TRUE) ~ fitted(.) | Dx, 
     xlab="Fitted values", ylab= "Pearson residuals",
     abline=0, lty=3)