---
title: "LOG result of readmode_pred"
output:
  html_document: default
  word_document: default
date: "2024-05-11"
---
version of R:4.3.2
version of Rstudio: 2023.12.0+369

We run the models for each dependent variables (on FFD,SFD,GD,TRT,RPD) in the following order:

Full_mdoel=lmer(depvar~readingmode*predictability+(1+readingmode*predictability|pp)+(1+readingmode*predictability|item), datafile)
model=lmer(depvar~readingmode*predictability+(1+readingmode*predictability|pp)+(1|item), datafile)
model=lmer(depvar~readingmode*predictability+(0+readingmode*predictability|pp)+(1|item), datafile)
model=lmer(depvar~readingmode*predictability+(1+readingmode+predictability|pp)+(1|item), datafile)
model=lmer(depvar~readingmode*predictability+(0+readingmode+predictability|pp)+(1|item), datafile)
model=lmer(depvar ~readingmode*predictability+ (1+readingmode|pp) + (1|item), datafile)
model=lmer(depvar ~readingmode*predictability+ (0+readingmode|pp) + (1|item), datafile)
model=lmer(depvar ~readingmode*predictability+ (1+predictability|pp) + (1|item), datafile)
model=lmer(depvar ~readingmode*predictability+ (0+predictability|pp) + (1|item), datafile)
model=lmer(depvar ~readingmode*predictability+ (1|pp) + (1|item), datafile)


Only the model that successfully converged for each dependent variables was retained.

```{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("datanew.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$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"))
```




# FOR FIRST FIXATION DURATION (FFD)
```{r}
measure = "FFD"
datafile$depvar = datafile[,measure]
datafile$depvar = log(as.numeric(datafile$depvar))
```



## linear mixed effect model analysis for FFD
```{r}
contrasts(datafile$predictability) <- contr.sdif(2) 
contrasts(datafile$readingmode) <- contr.sdif(2) 
model_FFD= lmer(depvar ~readingmode*predictability+ (1+readingmode|pp) + (1|item), datafile)
summary(model_FFD, corr = FALSE)
confint(model_FFD)
```


## simple effect analysis for FFD
```{r}
contrast.matrix <- matrix(c(
  -1, 1, 0, 0, 
  0, 0, -1, 1), 4, 2,
  dimnames=list(c("SH","SL","AH","AL"), 
                c("SL-SH", "AL-AH")))
inv.contrast.matrix <- matrix(t(ginv(contrast.matrix)), 4, 2,
                              dimnames=list(c("SH","SL","AH","AL"), 
                                            c("SL-SH", "AL-AH")))
(contrasts(datafile$condition) <- fractions(inv.contrast.matrix))
depvar.lmer1 = lmer(depvar ~ condition + (1|pp)+(1|item), datafile)
summary(depvar.lmer1, corr = FALSE)
```




# FOR SINGLE FIXATION DURATION (SFD)
```{r}
measure = "SFD"
datafile$depvar = datafile[,measure]
datafile$depvar = log(as.numeric(datafile$depvar))
```


## linear mixed effect model analysis for SFD
```{r}
contrasts(datafile$predictability) <- contr.sdif(2) 
contrasts(datafile$readingmode) <- contr.sdif(2) 
model_SFD= lmer(depvar ~readingmode*predictability+ (1+readingmode|pp) + (1|item), datafile)
summary(model_SFD, corr = FALSE)
confint(model_SFD)
```


## simple effect analysis for SFD
```{r}
contrast.matrix <- matrix(c(
  -1, 1, 0, 0, 
  0, 0, -1, 1), 4, 2,
  dimnames=list(c("SH","SL","AH","AL"), 
                c("SL-SH", "AL-AH")))
inv.contrast.matrix <- matrix(t(ginv(contrast.matrix)), 4, 2,
                              dimnames=list(c("SH","SL","AH","AL"), 
                                            c("SL-SH", "AL-AH")))
(contrasts(datafile$condition) <- fractions(inv.contrast.matrix))
depvar.lmer1 = lmer(depvar ~ condition + (1|pp)+(1|item), datafile)
summary(depvar.lmer1, corr = FALSE)
```




# FOR GAZE DURATION
```{r}
measure = "GD"
datafile$depvar = datafile[,measure]
datafile$depvar = log(as.numeric(datafile$depvar))
```


## linear mixed effect model analysis for GD
```{r warning=FALSE}
contrasts(datafile$predictability) <- contr.sdif(2) 
contrasts(datafile$readingmode) <- contr.sdif(2) 
model_GD= lmer(depvar ~readingmode*predictability+ (1+readingmode|pp) + (1|item), datafile)
summary(model_GD, corr = FALSE)
confint(model_GD)
```


## simple effect analysis for GD
```{r}
contrast.matrix <- matrix(c(
  -1, 1, 0, 0, 
  0, 0, -1, 1), 4, 2,
  dimnames=list(c("SH","SL","AH","AL"), 
                c("SL-SH", "AL-AH")))
inv.contrast.matrix <- matrix(t(ginv(contrast.matrix)), 4, 2,
                              dimnames=list(c("SH","SL","AH","AL"), 
                                            c("SL-SH", "AL-AH")))
(contrasts(datafile$condition) <- fractions(inv.contrast.matrix))
depvar.lmer1 = lmer(depvar ~ condition + (1|pp)+(1|item), datafile)
summary(depvar.lmer1, corr = FALSE)
```




# FOR TOTAL READING TIME (TRT)
```{r}
measure = "TRT"
datafile$depvar = datafile[,measure]
datafile$depvar = log(as.numeric(datafile$depvar))
```



## linear mixed effect model analysis for TRT
```{r warning=FALSE}
contrasts(datafile$predictability) <- contr.sdif(2) 
contrasts(datafile$readingmode) <- contr.sdif(2) 
model_TRT= lmer(depvar ~readingmode*predictability+ (1+readingmode+predictability|pp) + (1|item), datafile)
summary(model_TRT, corr = FALSE)
confint(model_TRT)
```


## simple effect analysis for TRT
```{r}
contrast.matrix <- matrix(c(
  -1, 1, 0, 0, 
  0, 0, -1, 1), 4, 2,
  dimnames=list(c("SH","SL","AH","AL"), 
                c("SL-SH", "AL-AH")))
inv.contrast.matrix <- matrix(t(ginv(contrast.matrix)), 4, 2,
                              dimnames=list(c("SH","SL","AH","AL"), 
                                            c("SL-SH", "AL-AH")))
(contrasts(datafile$condition) <- fractions(inv.contrast.matrix))
depvar.lmer1 = lmer(depvar ~ condition + (1|pp)+(1|item), datafile)
summary(depvar.lmer1, corr = FALSE)
```



# FOR REGRESSION PATH DURATION (RPD)
```{r}
measure = "RPD"
datafile$depvar = datafile[,measure]
datafile$depvar = log(as.numeric(datafile$depvar))
```


## linear mixed effect model analysis for RPD
```{r}
contrasts(datafile$predictability) <- contr.sdif(2) 
contrasts(datafile$readingmode) <- contr.sdif(2) 
model_RPD= lmer(depvar ~readingmode*predictability+ (0+readingmode+predictability|pp) + (1|item), datafile)
summary(model_RPD, corr = FALSE)
confint(model_RPD)
```


## simple effect analysis for RPD
```{r}
contrast.matrix <- matrix(c(
  -1, 1, 0, 0, 
  0, 0, -1, 1), 4, 2,
  dimnames=list(c("SH","SL","AH","AL"), 
                c("SL-SH", "AL-AH")))
inv.contrast.matrix <- matrix(t(ginv(contrast.matrix)), 4, 2,
                              dimnames=list(c("SH","SL","AH","AL"), 
                                            c("SL-SH", "AL-AH")))
(contrasts(datafile$condition) <- fractions(inv.contrast.matrix))
depvar.lmer1 = lmer(depvar ~ condition + (1|pp)+(1|item), datafile)
summary(depvar.lmer1, corr = FALSE)
```






