library(bestNormalize)
library(sjPlot)
library(lmerTest)
library(ggplot2)
Sys.setlocale("LC_ALL", "Czech")
options(encoding = "UTF-8")
aqsync<-read.csv(file="aqsync.csv",fileEncoding = "UTF-16LE")
aqsync$cleanrt<-aqsync$rt
aqsync$cleanrt[aqsync$rt>4000|aqsync$rt<100]<-NA
aqsync$normclrt<-bestNormalize(aqsync$cleanrt,allow_orderNorm=F)$x.t
aqprec<-read.csv(file="aqprec.csv",fileEncoding = "UTF-16LE")
aqprec$cleanrt<-aqprec$rt
aqprec$cleanrt[aqprec$rt>4000|aqprec$rt<100]<-NA
aqprec$normclrt<-bestNormalize(aqprec$cleanrt,allow_orderNorm=F)$x.t
The following function calculates cell means and standard errors to be used in plots.
summarySE<- function(data=NULL, measurevar, groupvars=NULL, na.rm=FALSE,
conf.interval=.95, .drop=TRUE) {
library(plyr)
# New version of length which can handle NA's: if na.rm==T, don't count them
length2 <- function (x, na.rm=FALSE) {
if (na.rm) sum(!is.na(x))
else length(x)
}
# This does the summary. For each group's data frame, return a vector with
# N, mean, and sd
datac <- ddply(data, groupvars, .drop=.drop,
.fun = function(xx, col) {
c(N = length2(xx[[col]], na.rm=na.rm),
mean = mean (xx[[col]], na.rm=na.rm),
sd = sd (xx[[col]], na.rm=na.rm)
)
},
measurevar
)
# Rename the "mean" column
datac <- rename(datac, c("mean" = measurevar))
datac$se <- datac$sd / sqrt(datac$N) # Calculate standard error of the mean
# Confidence interval multiplier for standard error
# Calculate t-statistic for confidence interval:
# e.g., if conf.interval is .95, use .975 (above/below), and use df=N-1
ciMult <- qt(conf.interval/2 + .5, datac$N-1)
datac$ci <- datac$se * ciMult
return(datac)
}
pd <- position_dodge(0.1)
aqsyncsum<-summarySE(aqsync[aqsync$region1%in%c(6:9)&aqsync$subj%in%factor(c(1:30))&aqsync$is_correct==1&!is.na(aqsync$cleanrt),], measurevar="cleanrt", groupvars=c("condition","region1"))
outplot<-ggplot(aqsyncsum, aes(x=factor(region1), y=cleanrt, group=factor(condition),linetype=factor(condition))) +
geom_errorbar(aes(ymin=cleanrt-se, ymax=cleanrt+se), width=.1,position=pd) +
geom_line(position=pd) +
geom_point(position=pd) +
scale_y_continuous("Reading time (ms)")+
scale_x_discrete("Region",breaks=c("6", "7","8", "9"),
labels=c("\nMezitím\nMeanwhile", "Z rozhlasu\nz rozhlasu\nfrom radio","vyhrávala\nvyhrávala\nplayed", "hudba\nhudba\nmusic"))+
scale_linetype_manual(name="",
labels = c("Explicit",
"Implicit"),
values = c("0"="solid",
"1"="dashed"))+
theme_bw()
outplot
aqsync7<-aqsync[aqsync$region1%in%c(7),]
aqsync8<-aqsync[aqsync$region1%in%c(8),]
aqsync9<-aqsync[aqsync$region1%in%c(9),]
x<-lmer(normclrt~condition+(1|subjv)+(1|item),data=aqsync7)
xa<-lmer(normclrt~condition+(1|subjv)+(1|item),data=aqsync8)
xb<-lmer(normclrt~condition+(1|subjv)+(1|item),data=aqsync9)
tab_model(x,xa,xb,show.std=T,show.est=F,show.ci=F)
normclrt | normclrt | normclrt | ||||
---|---|---|---|---|---|---|
Predictors | std. Beta | p | std. Beta | p | std. Beta | p |
(Intercept) | 0.01 | <0.001 | 0.01 | <0.001 | -0.01 | 0.343 |
condition | 0.13 | <0.001 | -0.06 | <0.001 | -0.02 | 0.235 |
Random Effects | ||||||
σ2 | 0.31 | 0.25 | 0.35 | |||
τ00 | 0.41 subjv | 0.39 subjv | 0.62 subjv | |||
0.02 item | 0.01 item | 0.04 item | ||||
ICC | 0.58 | 0.61 | 0.65 | |||
N | 109 subjv | 109 subjv | 109 subjv | |||
20 item | 20 item | 20 item | ||||
Observations | 1902 | 1901 | 1881 | |||
Marginal R2 / Conditional R2 | 0.017 / 0.584 | 0.004 / 0.616 | 0.000 / 0.650 |
aqprecsum<-summarySE(aqprec[aqprec$region1%in%c(6:9)&aqprec$subj%in%factor(c(1:30))&aqprec$is_correct==1&!is.na(aqprec$cleanrt),], measurevar="cleanrt", groupvars=c("condition","region1"))
outplot<-ggplot(aqprecsum, aes(x=factor(region1), y=cleanrt, group=factor(condition),linetype=factor(condition))) +
geom_errorbar(aes(ymin=cleanrt-se, ymax=cleanrt+se), width=.1,position=pd) +
geom_line(position=pd) +
geom_point(position=pd) +
scale_y_continuous("Reading time (ms)")+
scale_x_discrete("Region",breaks=c("6", "7","8", "9"),
labels=c("\nPotom\nThen", "Do třídy\ndo třídy\nin classroom","přišel\npřišel\ncame", "ředitel\nředitel\ndirector"))+
scale_linetype_manual(name="",
labels = c("Explicit",
"Implicit"),
values = c("0"="solid",
"1"="dashed"))+
theme_bw()
outplot
# Precedence modeling
aqprec7<-aqprec[aqprec$region1%in%c(7),]
aqprec8<-aqprec[aqprec$region1%in%c(8),]
aqprec9<-aqprec[aqprec$region1%in%c(9),]
x<-lmer(normclrt~condition+(1|subjv)+(1|item),data=aqprec7)
xa<-lmer(normclrt~condition+(1|subjv)+(1|item),data=aqprec8)
xb<-lmer(normclrt~condition+(1|subjv)+(1|item),data=aqprec9)
tab_model(x,xa,xb,show.std=T,show.est=F,show.ci=F)
normclrt | normclrt | normclrt | ||||
---|---|---|---|---|---|---|
Predictors | std. Beta | p | std. Beta | p | std. Beta | p |
(Intercept) | 0.01 | <0.001 | 0.01 | <0.001 | 0.00 | 0.528 |
condition | 0.14 | <0.001 | -0.07 | <0.001 | -0.00 | 0.912 |
Random Effects | ||||||
σ2 | 0.28 | 0.24 | 0.23 | |||
τ00 | 0.60 subjv | 0.52 subjv | 0.67 subjv | |||
0.01 item | 0.00 item | 0.01 item | ||||
ICC | 0.68 | 0.69 | 0.75 | |||
N | 109 subjv | 109 subjv | 108 subjv | |||
20 item | 20 item | 20 item | ||||
Observations | 1950 | 1954 | 1927 | |||
Marginal R2 / Conditional R2 | 0.021 / 0.691 | 0.005 / 0.690 | 0.000 / 0.747 |