---
title: "ancova analysis"
output: html_document
date: "2024-05-27"
---

version of R:4.3.2
version of Rstudio: 2023.12.0+369
```{r warning=FALSE}
library(lmerTest) # version 3.1-3
library(lattice)  # version 0.21-9
library(MASS)     # version 7.3-60
library(plyr)     # version 1.8.9
library(plotrix)  # version 3.8-4
```


```{r}
rm(list=ls())
datafile0 = read.csv("ancova_speed.csv", sep = ",", dec = ".")
datafile <- datafile0
colnames(datafile)
nrow(datafile)
```


```{r}
datafile$pp = datafile[,1]
datafile$item = datafile[,2]
datafile$readingmode = datafile[,3]
datafile$predictability = datafile[,4]
datafile$condition = datafile[,5]
datafile$speed=datafile[,6]
datafile$speed <- scale(datafile$speed)
datafile$pp = as.factor(datafile$pp)
datafile$item = as.factor(datafile$item)
datafile$readingmode = factor(datafile$readingmode, levels = c("S","A"))
datafile$predictability = factor(datafile$predictability, levels = c("H","L"))
datafile$condition = factor(datafile$condition, levels = c("SH","SL","AH","AL"))
```




# ancova analysis for skipping rate
```{r warning=FALSE}
measure = "IA_SKIP"
datafile$depvar = datafile[,measure]
datafile$depvar = as.numeric(datafile$depvar)
contrasts(datafile$predictability) <- contr.sdif(2) 
contrasts(datafile$readingmode) <- contr.sdif(2) 
ancova_SKIP=glmer(depvar~readingmode*predictability+speed + (1|pp)+ (1|item),
                     datafile, family=binomial, control=glmerControl(optimizer="Nelder_Mead",optCtrl = list(maxfun = 200000)))
summary(ancova_SKIP)
anova(ancova_SKIP)
confint(ancova_SKIP)
```




# ancova analysis for FFD
```{r warning=FALSE}
measure = "FFD"
datafile$depvar = datafile[,measure]
datafile$depvar = as.numeric(datafile$depvar)
contrasts(datafile$predictability) <- contr.sdif(2) 
contrasts(datafile$readingmode) <- contr.sdif(2) 
ancova_FFD= lmer(depvar ~readingmode*predictability+ speed+(1+readingmode|pp) + (1|item), datafile)
summary(ancova_FFD, corr = FALSE)
anova(ancova_FFD)
confint(ancova_FFD)
```




#  ancova analysis for SFD
```{r warning=FALSE}
measure = "SFD"
datafile$depvar = datafile[,measure]
datafile$depvar = as.numeric(datafile$depvar)
contrasts(datafile$predictability) <- contr.sdif(2) 
contrasts(datafile$readingmode) <- contr.sdif(2) 
ancova_SFD= lmer(depvar ~readingmode*predictability+ speed+(1+readingmode|pp) + (1|item), datafile)
summary(ancova_SFD, corr = FALSE)
anova(ancova_SFD)
confint(ancova_SFD)
```




# ancova analysis for GD
```{r warning=FALSE}
measure = "GD"
datafile$depvar = datafile[,measure]
datafile$depvar = as.numeric(datafile$depvar)
contrasts(datafile$predictability) <- contr.sdif(2) 
contrasts(datafile$readingmode) <- contr.sdif(2) 
ancova_GD= lmer(depvar ~readingmode*predictability+speed+ (1+readingmode|pp) + (1|item), datafile)
summary(ancova_GD, corr = FALSE)
anova(ancova_GD)
confint(ancova_GD)
```




# ancova analysis for TRT
```{r warning=FALSE}
measure = "TRT"
datafile$depvar = datafile[,measure]
datafile$depvar = as.numeric(datafile$depvar)
contrasts(datafile$predictability) <- contr.sdif(2) 
contrasts(datafile$readingmode) <- contr.sdif(2) 
ancova_TRT= lmer(depvar ~readingmode*predictability+speed+ (1+readingmode+predictability|pp) + (1|item), datafile)
summary(ancova_TRT, corr = FALSE)
anova(ancova_TRT)
confint(ancova_TRT)
```




# ancova analysis for RPD
```{r warning=FALSE}
measure = "RPD"
datafile$depvar = datafile[,measure]
datafile$depvar = as.numeric(datafile$depvar)
contrasts(datafile$predictability) <- contr.sdif(2) 
contrasts(datafile$readingmode) <- contr.sdif(2) 
ancova_RPD= lmer(depvar ~readingmode*predictability+speed+ (1+readingmode|pp) + (1|item), datafile)
summary(ancova_RPD, corr = FALSE)
anova(ancova_RPD)
confint(ancova_RPD)
```


