Data Files
#Data are in two files, one for the category-learning group, and one for the paired-associate-learning group
#Category learning
data1<-read.table("FixRep_StimPresentationB_CAT.txt", header=T)
colnames(data1)[2]<-"group"
#Paired-Associate Learning
data2<-read.table("FixRep_StimPresentationB_PA.txt", header=T)
colnames(data2)[2]<-"group"
data<-rbind(data1,data2)
#Combine data into one data frame
data<-rbind(data1,data2)
library(dplyr)
#Convert all chr columns to factor
data <- mutate_if(data, is.character, as.factor)
#Rename group levels
levels(data$group)<-c("CAT", "PA")
#Following Hendreson et al. (1991) we exclude fixations with duration <90 or >1000
#We are only interested in critical (encoded as "mixed") trials, presenting one label and one ideogram shape
#Finally, we are interested in fixations falling within an interest area (i.e., within a shape)
data<-droplevels(data[data$CURRENT_FIX_DURATION>90 & data$CURRENT_FIX_DURATION<1000 & data$cnd=='mixed' & data$CURRENT_FIX_INTEREST_AREA_LABEL!='.',])
Dwell Time by Learning Group and Shape
#Calculate Dwell Time (i.e., sum of duration of fixations during one trial)
data_dw<-aggregate(CURRENT_FIX_DURATION~sbj+trial+group+cnd+CURRENT_FIX_INTEREST_AREA_LABEL+Response,data,sum,na.rm=T)
data_dw<-data_dw[order(data_dw$sbj, data_dw$trial,data_dw$CURRENT_FIX_INTEREST_AREA_LABEL),]
colnames(data_dw)[5]<-'IA_LABEL'
colnames(data_dw)[7]<-'DWELL_TIME'
data_dw$IA_LABEL<-as.factor(data_dw$IA_LABEL)
#Calculate Dwell Time by Learning Group and Shape (coded as IA_Label: "label" vs. "ideog")
data_mean<-aggregate(DWELL_TIME~sbj+group+IA_LABEL,data_dw, mean,na.rm=T)
#Category Learning
#Dwell Time on label shapes
mean(data_mean[data_mean$group=='CAT'&data_mean$IA_LABEL=='label',]$DWELL_TIME)
## [1] 668.2807
sd(data_mean[data_mean$group=='CAT'&data_mean$IA_LABEL=='label',]$DWELL_TIME)
## [1] 213.0915
#Dwell Time on ideogram shapes
mean(data_mean[data_mean$group=='CAT'&data_mean$IA_LABEL=='ideog',]$DWELL_TIME)
## [1] 683.8226
sd(data_mean[data_mean$group=='CAT'&data_mean$IA_LABEL=='ideog',]$DWELL_TIME)
## [1] 220.485
#Paired-Associate Learning
#Dwell Time on label shapes
mean(data_mean[data_mean$group=='PA'&data_mean$IA_LABEL=='label',]$DWELL_TIME)
## [1] 726.596
sd(data_mean[data_mean$group=='PA'&data_mean$IA_LABEL=='label',]$DWELL_TIME)
## [1] 225.2125
#Dwell Time on ideogram shapes
mean(data_mean[data_mean$group=='PA'&data_mean$IA_LABEL=='ideog',]$DWELL_TIME)
## [1] 727.5203
sd(data_mean[data_mean$group=='PA'&data_mean$IA_LABEL=='ideog',]$DWELL_TIME)
## [1] 205.9584
Dwell Time by Learning Group, Shape and Block
library(sciplot)
library(gplots)
#Create "block" variable
data$block<-ifelse(data$trial<25,1,ifelse(data$trial<49,2,ifelse(data$trial<73,3,4)))
#Calculate dwell time
data_dw<-aggregate(CURRENT_FIX_DURATION ~ sbj+trial+group+cnd+block+CURRENT_FIX_INTEREST_AREA_LABEL+Response,data,sum,na.rm=T)
data_dw<-data_dw[order(data_dw$sbj, data_dw$trial,data_dw$CURRENT_FIX_INTEREST_AREA_LABEL),]
colnames(data_dw)[6]<-'IA_LABEL'
colnames(data_dw)[8]<-'DWELL_TIME'
data_dw$IA_LABEL<-as.factor(data_dw$IA_LABEL)
#Calculate dwell time by block, shape, and learning group
data_bl<-aggregate(DWELL_TIME~ sbj+block+IA_LABEL+group,data_dw,mean,na.rm=T)
data_bl<-data_bl[order(data_bl$sbj, data_bl$block),]
3-way ANOVA
library(ez)
data_bl$block<-as.factor(data_bl$block)
ezANOVA(data=data_bl, dv=.(DWELL_TIME), wid=.(sbj), within=.(IA_LABEL,block), between = .(group), detailed=TRUE, type=3)
## $ANOVA
## Effect DFn DFd SSn SSd F p
## 1 (Intercept) 1 46 1.885028e+08 15705006 552.12507948 2.897620e-27
## 2 group 1 46 2.812385e+05 15705006 0.82374810 3.688169e-01
## 3 IA_LABEL 1 46 5.007966e+03 1581865 0.14562966 7.045044e-01
## 5 block 3 138 4.575167e+04 3978573 0.52897775 6.631204e-01
## 4 group:IA_LABEL 1 46 2.387688e+03 1581865 0.06943303 7.933409e-01
## 6 group:block 3 138 2.422953e+05 3978573 2.80140208 4.229036e-02
## 7 IA_LABEL:block 3 138 1.809948e+05 2567114 3.24323847 2.402422e-02
## 8 group:IA_LABEL:block 3 138 2.015125e+05 2567114 3.61089400 1.499358e-02
## p<.05 ges
## 1 * 0.8877598126
## 2 0.0116629689
## 3 0.0002100871
## 5 0.0019160346
## 4 0.0001001760
## 6 * 0.0100642479
## 7 * 0.0075371945
## 8 * 0.0083844517
##
## $`Mauchly's Test for Sphericity`
## Effect W p p<.05
## 5 block 0.8275720 0.1325377
## 6 group:block 0.8275720 0.1325377
## 7 IA_LABEL:block 0.8860819 0.3681421
## 8 group:IA_LABEL:block 0.8860819 0.3681421
##
## $`Sphericity Corrections`
## Effect GGe p[GG] p[GG]<.05 HFe p[HF]
## 5 block 0.8972648 0.64375505 0.9583583 0.65551753
## 6 group:block 0.8972648 0.04847193 * 0.9583583 0.04469171
## 7 IA_LABEL:block 0.9280550 0.02729440 * 0.9938931 0.02428543
## 8 group:IA_LABEL:block 0.9280550 0.01751123 * 0.9938931 0.01519208
## p[HF]<.05
## 5
## 6 *
## 7 *
## 8 *
#There is a triple interaction. We analyze each group separately
2 -way ANOVA on data from the Category-Learning Group
data_cat<-droplevels(data_bl[data_bl$group=="CAT",])
ezANOVA(data=data_cat, dv=.(DWELL_TIME), wid=.(sbj), within=.(IA_LABEL,block), detailed=TRUE, type=3)
## $ANOVA
## Effect DFn DFd SSn SSd F p p<.05
## 1 (Intercept) 1 23 87110922.429 8154167.3 245.708868 9.063632e-14 *
## 2 IA_LABEL 1 23 7155.784 529664.0 0.310731 5.826170e-01
## 3 block 3 69 105401.140 2298417.9 1.054737 3.740832e-01
## 4 IA_LABEL:block 3 69 290220.873 918227.4 7.269528 2.626766e-04 *
## ges
## 1 0.8798070050
## 2 0.0006009409
## 3 0.0087791282
## 4 0.0238067489
##
## $`Mauchly's Test for Sphericity`
## Effect W p p<.05
## 3 block 0.5661863 0.03039813 *
## 4 IA_LABEL:block 0.8200044 0.50602696
##
## $`Sphericity Corrections`
## Effect GGe p[GG] p[GG]<.05 HFe p[HF]
## 3 block 0.7299433 0.360908924 0.8097951 0.3655852161
## 4 IA_LABEL:block 0.8727392 0.000546225 * 0.9949608 0.0002703815
## p[HF]<.05
## 3
## 4 *
# Interaction of block by shape
# Post-hoc multiple comparisons
# See https://cran.r-project.org/web/packages/multcomp/vignettes/multcomp-examples.pdf
library(nlme)
library(lmerTest)
library(multcomp)
# Same analysis as with ezANOVA, but using lme this time
mod<-lme(DWELL_TIME ~ IA_LABEL* block, random=list(sbj=pdBlocked(list(~1, pdIdent(~IA_LABEL-1), pdIdent(~block-1)))), data=data_cat)
tmp <- expand.grid(IA_LABEL = unique(data_cat$IA_LABEL), block = unique(data_cat$block))
X <- model.matrix(~ block * IA_LABEL, data =tmp)
Tukey <- contrMat(table(data_cat$IA_LABEL), "Tukey")
mat<-matrix(0, nrow = nrow(Tukey), ncol = ncol(Tukey))
K1 <- cbind(Tukey, mat, mat, mat)
rownames(K1) <- paste(levels(data_cat$block)[1], rownames(K1), sep = ":")
K2 <- cbind(mat, Tukey, mat, mat)
rownames(K2) <- paste(levels(data_cat$block)[2], rownames(K2), sep = ":")
K3 <- cbind(mat,mat, Tukey,mat)
rownames(K3) <- paste(levels(data_cat$block)[3], rownames(K3), sep = ":")
K4 <- cbind(mat, mat, mat, Tukey)
rownames(K4) <- paste(levels(data_cat$block)[4], rownames(K4), sep = ":")
K <- rbind(K1, K2, K3, K4)
colnames(K) <- c(colnames(Tukey), colnames(Tukey), colnames(Tukey), colnames(Tukey))
summary(glht(mod, linfct = K %*% X))
##
## Simultaneous Tests for General Linear Hypotheses
##
## Fit: lme.formula(fixed = DWELL_TIME ~ IA_LABEL * block, data = data_cat,
## random = list(sbj = pdBlocked(list(~1, pdIdent(~IA_LABEL -
## 1), pdIdent(~block - 1)))))
##
## Linear Hypotheses:
## Estimate Std. Error z value Pr(>|z|)
## 1:label - ideog == 0 118.27 44.07 2.684 0.0249 *
## 2:label - ideog == 0 -45.58 55.24 -0.825 0.8074
## 3:label - ideog == 0 -83.12 55.24 -1.505 0.3481
## 4:label - ideog == 0 -44.26 44.07 -1.004 0.6856
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## (Adjusted p values reported -- single-step method)
2 -way ANOVA on data from the Paired-Associate-Learning Group
data_pa<-droplevels(data_bl[data_bl$group=="PA",])
ezANOVA(data=data_pa, dv=.(DWELL_TIME), wid=.(sbj), within=.(IA_LABEL,block), detailed=TRUE, type=3)
## $ANOVA
## Effect DFn DFd SSn SSd F p p<.05
## 1 (Intercept) 1 23 1.016731e+08 7550839 3.096982e+02 7.707641e-15 *
## 2 IA_LABEL 1 23 2.398709e+02 1052201 5.243323e-03 9.429010e-01
## 3 block 3 69 1.826458e+05 1680155 2.500277e+00 6.663352e-02
## 4 IA_LABEL:block 3 69 9.228645e+04 1648886 1.287286e+00 2.856826e-01
## ges
## 1 8.949689e-01
## 2 2.010261e-05
## 3 1.507635e-02
## 4 7.674952e-03
##
## $`Mauchly's Test for Sphericity`
## Effect W p p<.05
## 3 block 0.8316550 0.5492052
## 4 IA_LABEL:block 0.6885652 0.1509226
##
## $`Sphericity Corrections`
## Effect GGe p[GG] p[GG]<.05 HFe p[HF] p[HF]<.05
## 3 block 0.8843313 0.0748483 1.0103346 0.06663352
## 4 IA_LABEL:block 0.7926132 0.2867039 0.8901128 0.28652113
# No effect, no interaction
Graph
#Data for graph
data_gr<-aggregate(DWELL_TIME~ block+IA_LABEL+group,data_bl,mean,na.rm=T)
temp<-aggregate(DWELL_TIME~ block+IA_LABEL+group,data_bl,se)
data_gr$se<-temp$DWELL_TIME
data_gr<-data_gr[order(data_gr$block),]
data_gr$block<-as.numeric(data_gr$block)
par(mfrow=c(1,2))
col<-c("red" ,"blue")
lintyp<-c("solid", "dashed")
linwid=c(2,2)
pchar=c(15,17)
leg<-c("Label Shapes", "Ideogram Shapes")
main="Category-Learning Group"
offset=0.02
ylim=c(0,1000)
#Category-Learning Group
#Label Shapes
plotCI(data_gr[data_gr$IA_LABEL=='label'& data_gr$group=='CAT',]$block, data_gr[data_gr$IA_LABEL=='label' & data_gr$group=='CAT',]$DWELL_TIME, uiw=data_gr[data_gr$IA_LABEL=='label'& data_gr$group=='CAT',]$se, gap=0, col=col[1], pch=pchar[1], xlab="Block", ylab="Dwell Time (msec)", main = main, las=2, bty="n", cex.main=1, cex.axis=0.9, ylim=ylim, xaxt="n")
lines(data_gr[data_gr$IA_LABEL=='label'& data_gr$group=='CAT',]$ block,data_gr[data_gr$IA_LABEL=='label'& data_gr$group=='CAT',]$DWELL_TIME, col=col[1], lty=lintyp[1], lwd=linwid[1])
#Ideogram Shapes
plotCI(data_gr[data_gr$IA_LABEL=='ideog'& data_gr$group=='CAT',]$block+offset, data_gr[data_gr$IA_LABEL=='ideog' & data_gr$group=='CAT',]$DWELL_TIME, uiw=data_gr[data_gr$IA_LABEL=='ideog' & data_gr$group=='CAT',]$se, gap=0, col=col[2], pch=pchar[2], xaxt="n", yaxt="n", las=2, add=T)
lines(data_gr[data_gr$IA_LABEL=='ideog' & data_gr$group=='CAT',]$block+offset,data_gr[data_gr$IA_LABEL=='ideog' & data_gr$group=='CAT',]$DWELL_TIME, col=col[2], lty=lintyp[2], lwd=linwid[2])
axis(side = 1, at = 1:4, labels = 1:4, cex.axis = 0.8)
legend(x=2.2, y=450, legend=leg, pch=pchar, lty=lintyp, bty="n", col=col, lwd=linwid, seg.len=4.0)
#Paired-Associate Group
col<-c("red","blue")
lintyp<-c("solid", "dashed")
linwid=c(2,2)
pchar=c(15,17)
leg<-c("Label Shapes", "Ideogram Shapes")
main="Paired-Associate Group"
#Label Shapes
plotCI(data_gr[data_gr$IA_LABEL=='label'& data_gr$group=='PA',]$block+2*offset, data_gr[data_gr$IA_LABEL=='label' & data_gr$group=='PA',]$DWELL_TIME, uiw=data_gr[data_gr$IA_LABEL=='label'& data_gr$group=='CAT',]$se, gap=0, col=col[1], pch=pchar[1], xlab="Block", ylab="Dwell Time (msec)", main = main, las=2, bty="n", cex.main=1, cex.axis=0.9, ylim=ylim, xaxt="n")
lines(data_gr[data_gr$IA_LABEL=='label'& data_gr$group=='PA',]$block+2*offset,data_gr[data_gr$IA_LABEL=='label'& data_gr$group=='PA',]$DWELL_TIME, col=col[1], lty=lintyp[1], lwd=linwid[1])
#Ideogram Shapes
plotCI(data_gr[data_gr$IA_LABEL=='ideog'& data_gr$group=='PA',]$block+3*offset, data_gr[data_gr$IA_LABEL=='ideog' & data_gr$group=='PA',]$DWELL_TIME, uiw=data_gr[data_gr$IA_LABEL=='ideog' & data_gr$group=='CAT',]$se, gap=0, col=col[2], pch=pchar[2], xaxt="n", yaxt="n", las=2, add=T)
lines(data_gr[data_gr$IA_LABEL=='ideog' & data_gr$group=='PA',]$block+3*offset,data_gr[data_gr$IA_LABEL=='ideog' & data_gr$group=='PA',]$DWELL_TIME, col=col[2], lty=lintyp[2], lwd=linwid[2])
axis(side = 1, at = 1:4, labels = 1:4, cex.axis = 0.8)
legend(x=2.2, y=450, legend=leg, pch=pchar, lty=lintyp, bty="n", col=col, lwd=linwid, seg.len=4.0)
mtext('Discrimination Session, Average Dwell Time', outer = TRUE, cex = 1, font =2)

par(mfrow=c(1,1), oma = c(0, 0, 0, 0))