#R-Code based on data collected and analysed for the article "Exploring systematic orthographic crosslinguistic similarities to enhance foreign language vocabulary learning" by Nina Selina Hicks (-Mueller), accepted for publication in Language Teaching Research (September 2021)

#Code organized by:
###Import and organize data
###Initial differences
###Improvement by treatment and Yes/No test
###Linear mixed effect regression model

library("tidyverse")
## -- Attaching packages ----------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3     v purrr   0.3.4
## v tibble  3.0.3     v dplyr   1.0.1
## v tidyr   1.1.1     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.5.0
## Warning: package 'ggplot2' was built under R version 4.0.3
## -- Conflicts -------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library("ggplot2")
library("lme4")
## Loading required package: Matrix
## 
## Attaching package: 'Matrix'
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack
library("lmerTest")
## 
## Attaching package: 'lmerTest'
## The following object is masked from 'package:lme4':
## 
##     lmer
## The following object is masked from 'package:stats':
## 
##     step
library("ggpubr")
## Warning: package 'ggpubr' was built under R version 4.0.3
## Registered S3 methods overwritten by 'car':
##   method                          from
##   influence.merMod                lme4
##   cooks.distance.influence.merMod lme4
##   dfbeta.influence.merMod         lme4
##   dfbetas.influence.merMod        lme4
###################### IMPORT AND ORGANIZE DATA ########################

data <- read.csv("dataArticle2021.csv") #complete data
summary(data)
##       ID               Class              Group              Gender         
##  Length:260         Length:260         Length:260         Length:260        
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##     Grade           lang_groups           attitude        wnw_istd     
##  Length:260         Length:260         Min.   :0.000   Min.   :0.0000  
##  Class :character   Class :character   1st Qu.:2.000   1st Qu.:0.3575  
##  Mode  :character   Mode  :character   Median :2.330   Median :0.5000  
##                                        Mean   :2.328   Mean   :0.4840  
##                                        3rd Qu.:3.000   3rd Qu.:0.6000  
##                                        Max.   :3.000   Max.   :0.9300  
##                                                                        
##     tasks_n        evaluation      T1total_p         T1cog_p      
##  Min.   :0.000   Min.   :0.250   Min.   : 1.000   Min.   : 0.000  
##  1st Qu.:2.000   1st Qu.:1.750   1st Qu.: 5.000   1st Qu.: 5.000  
##  Median :3.000   Median :2.250   Median : 7.000   Median : 6.000  
##  Mean   :3.125   Mean   :2.133   Mean   : 7.338   Mean   : 6.269  
##  3rd Qu.:4.000   3rd Qu.:2.500   3rd Qu.:10.000   3rd Qu.: 8.000  
##  Max.   :7.000   Max.   :3.000   Max.   :15.000   Max.   :12.000  
##  NA's   :140     NA's   :140                                      
##    T1total_r         T1cog_r          T1cogtsz        T1cogpf    
##  Min.   : 1.000   Min.   : 0.000   Min.   :0.000   Min.   :0.00  
##  1st Qu.: 6.000   1st Qu.: 5.000   1st Qu.:1.000   1st Qu.:2.00  
##  Median : 8.000   Median : 7.000   Median :2.000   Median :3.00  
##  Mean   : 7.865   Mean   : 6.412   Mean   :2.446   Mean   :2.55  
##  3rd Qu.:10.000   3rd Qu.: 8.000   3rd Qu.:3.000   3rd Qu.:3.00  
##  Max.   :15.000   Max.   :12.000   Max.   :6.000   Max.   :4.00  
##                                                                  
##     T1cogdth        T1cogck         T1cogkch        T1noncog    
##  Min.   :0.000   Min.   :0.000   Min.   :0.000   Min.   :0.000  
##  1st Qu.:2.000   1st Qu.:2.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :4.000   Median :3.000   Median :1.000   Median :2.000  
##  Mean   :3.454   Mean   :3.035   Mean   :1.196   Mean   :2.523  
##  3rd Qu.:5.000   3rd Qu.:4.000   3rd Qu.:2.000   3rd Qu.:4.000  
##  Max.   :7.000   Max.   :5.000   Max.   :2.000   Max.   :6.000  
##                                                                 
##     T1total          T1cog         T2total_p         T2cog_p      
##  Min.   : 3.00   Min.   : 2.00   Min.   : 0.000   Min.   : 0.000  
##  1st Qu.:11.00   1st Qu.: 9.00   1st Qu.: 5.000   1st Qu.: 4.000  
##  Median :15.50   Median :13.00   Median : 8.000   Median : 7.000  
##  Mean   :15.20   Mean   :12.68   Mean   : 7.519   Mean   : 6.515  
##  3rd Qu.:19.25   3rd Qu.:16.00   3rd Qu.:10.000   3rd Qu.: 9.000  
##  Max.   :30.00   Max.   :24.00   Max.   :14.000   Max.   :12.000  
##                                                                   
##    T2total_r         T2cog_r          T2cogtsz        T2cogpf     
##  Min.   : 0.000   Min.   : 0.000   Min.   :0.000   Min.   :0.000  
##  1st Qu.: 7.000   1st Qu.: 6.000   1st Qu.:2.000   1st Qu.:2.000  
##  Median :10.000   Median : 8.000   Median :4.000   Median :3.000  
##  Mean   : 9.438   Mean   : 7.904   Mean   :3.469   Mean   :2.681  
##  3rd Qu.:12.000   3rd Qu.:10.000   3rd Qu.:5.000   3rd Qu.:4.000  
##  Max.   :15.000   Max.   :12.000   Max.   :6.000   Max.   :4.000  
##                                                                   
##     T2cogdth        T2cogck        T2cogkch        T2noncog        T2total     
##  Min.   :0.000   Min.   :0.00   Min.   :0.000   Min.   :0.000   Min.   : 0.00  
##  1st Qu.:2.000   1st Qu.:3.00   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:13.00  
##  Median :3.000   Median :4.00   Median :2.000   Median :3.000   Median :18.00  
##  Mean   :3.454   Mean   :3.45   Mean   :1.365   Mean   :2.538   Mean   :16.96  
##  3rd Qu.:5.000   3rd Qu.:5.00   3rd Qu.:2.000   3rd Qu.:4.000   3rd Qu.:22.00  
##  Max.   :7.000   Max.   :5.00   Max.   :2.000   Max.   :6.000   Max.   :29.00  
##                                                                                
##      T2cog         T3total_r         T3cog_r       T3total_p     
##  Min.   : 0.00   Min.   : 0.000   Min.   : 0.0   Min.   : 0.000  
##  1st Qu.:11.00   1st Qu.: 5.000   1st Qu.: 4.0   1st Qu.: 5.000  
##  Median :15.00   Median : 7.000   Median : 6.0   Median : 7.000  
##  Mean   :14.42   Mean   : 7.004   Mean   : 5.8   Mean   : 7.081  
##  3rd Qu.:19.00   3rd Qu.: 9.000   3rd Qu.: 7.0   3rd Qu.:10.000  
##  Max.   :24.00   Max.   :15.000   Max.   :12.0   Max.   :14.000  
##                                                                  
##     T3cog_p          T3cogtsz        T3cogpf         T3cogdth    
##  Min.   : 0.000   Min.   :0.000   Min.   :0.000   Min.   :0.000  
##  1st Qu.: 4.000   1st Qu.:2.000   1st Qu.:1.000   1st Qu.:2.000  
##  Median : 6.000   Median :3.000   Median :2.000   Median :3.000  
##  Mean   : 5.923   Mean   :2.973   Mean   :2.131   Mean   :2.942  
##  3rd Qu.: 8.000   3rd Qu.:4.000   3rd Qu.:3.000   3rd Qu.:4.000  
##  Max.   :12.000   Max.   :6.000   Max.   :4.000   Max.   :7.000  
##                                                                  
##     T3cogck         T3cogkch         T3noncog        T3total     
##  Min.   :0.000   Min.   :0.0000   Min.   :0.000   Min.   : 0.00  
##  1st Qu.:1.000   1st Qu.:0.0000   1st Qu.:1.000   1st Qu.:10.00  
##  Median :3.000   Median :1.0000   Median :2.000   Median :14.00  
##  Mean   :2.685   Mean   :0.9923   Mean   :2.362   Mean   :14.08  
##  3rd Qu.:4.000   3rd Qu.:2.0000   3rd Qu.:3.000   3rd Qu.:18.00  
##  Max.   :5.000   Max.   :2.0000   Max.   :6.000   Max.   :29.00  
##                                                                  
##      T3cog      
##  Min.   : 0.00  
##  1st Qu.: 8.00  
##  Median :12.00  
##  Mean   :11.72  
##  3rd Qu.:15.00  
##  Max.   :24.00  
## 
#wnw_istd = Index of Signal Detection, Yes/No vocabulary test 1 Level 1 (Meara 1992)
#tasks_n / evaluation = feedback of intervention group on number of tasks completed and pleasantness/usefulness/novelty
#T1/T2/T3 = pre-/post-/delayed post-test vocabulary learning activity, cog = cognates

#Improvement from T1 to T2 and T3 and overall score on vocabulary learning activities
data$T2T1cog <- data$T2cog - data$T1cog #improvement on cognates from T1 to T2
data$T3T1cog <- data$T3cog - data$T1cog #improvement on cognates from T1 to T3
data$overall <- data$T1total + data$T2total + data$T3total #overall performance across three tests on all items
data$cognates <- data$T1cog + data$T2cog + data$T3cog #overall performance across three tests on cognates

#Improvement from T1 to T2 on cognates by correspondence (proportional by number of items tested)
data$T2T1tsz <- (data$T2cogtsz - data$T1cogtsz)/6
data$T2T1pf <- (data$T2cogpf - data$T1cogpf)/4
data$T2T1thdt <- (data$T2cogdth - data$T1cogdth)/7
data$T2T1ck <- (data$T2cogck - data$T1cogck)/5
data$T2T1kch <- (data$T2cogkch - data$T1cogkch)/2

#Improvement from T1 to T3 on cognates by correspondence (proportional by number of items tested)
data$T3T1tsz <- (data$T3cogtsz - data$T1cogtsz)/6
data$T3T1pf <- (data$T3cogpf - data$T1cogpf)/4
data$T3T1thdt <- (data$T3cogdth - data$T1cogdth)/7
data$T3T1ck <- (data$T3cogck - data$T1cogck)/5
data$T3T1kch <- (data$T3cogkch - data$T1cogkch)/2

#Improvement by testing mode (receptive / productive)
data$T2T1rec <- data$T2cog_r - data$T1cog_p
data$T3T1rec <- data$T3cog_r - data$T1cog_p
data$T2T1pro <- data$T2cog_p - data$T1cog_p
data$T3T1pro <- data$T3cog_p - data$T1cog_p

#sum-code treatment groups and center Yes/No test
data$n.Group <- ifelse(data$Group == "intervention", 1, 0)
data$c.wnw_istd <- data$wnw_istd - mean(data$wnw_istd, na.rm = TRUE)

#Create subset intervention group only
dataint <- subset(data,n.Group==1)



######################### INITIAL DIFFERENCES ###############################

#Boxplots T1 by treatment (vocabulary learning activity and yes-no test) 
yesnobytreat<- ggplot(data = data, 
                         aes(x = Group, 
                             y = (wnw_istd), color = Group)) +
  scale_color_grey(start=0.6, end=0.1) +
  theme_classic() +
  geom_boxplot() + 
  geom_point(position = position_jitter(width = 0.4,
                                        height = 0.0),
             shape = 1) +
  xlab("Treatment group") + 
  ylab("Performance") + 
  theme_bw() +
  ggtitle("Yes/No test",
          sub = "initial vocabulary knowledge")

T1cogbytreat <- ggplot(data = data, 
                         aes(x = Group, 
                             y = (T1cog), color = Group)) +
  scale_color_grey(start=0.6, end=0.1) +
  theme_classic() +
  geom_boxplot() + 
  geom_point(position = position_jitter(width = 0.4,
                                        height = 0.0),
             shape = 1) +
  xlab("Treatment group") + 
  ylab("Performance") + 
  theme_bw() +
  ggtitle("Performance on cognates",
          sub ="Vocabulary learning activity T1") 

ggsave(file = "T1cogbytreat.eps", plot=T1cogbytreat, width = 3.10, height= 4.14)
ggsave(file = "yesnobytreat.eps", plot=yesnobytreat, width = 3.10, height= 4.14)

# Group initial differences between treatment groups
t.test(data$T1total~data$Group)
## 
##  Welch Two Sample t-test
## 
## data:  data$T1total by data$Group
## t = 1.7762, df = 257.99, p-value = 0.07687
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.1319172  2.5604886
## sample estimates:
##      mean in group control mean in group intervention 
##                   15.76429                   14.55000
t.test(data$T1cog~data$Group)
## 
##  Welch Two Sample t-test
## 
## data:  data$T1cog by data$Group
## t = 1.6756, df = 256.23, p-value = 0.09503
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.1618784  2.0094975
## sample estimates:
##      mean in group control mean in group intervention 
##                   13.10714                   12.18333
t.test(data$wnw_istd~data$Group)
## 
##  Welch Two Sample t-test
## 
## data:  data$wnw_istd by data$Group
## t = -0.29964, df = 257.78, p-value = 0.7647
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.05273264  0.03880407
## sample estimates:
##      mean in group control mean in group intervention 
##                  0.4807857                  0.4877500
chisq.test(table(data$Group,data$Gender),correct=FALSE)
## 
##  Pearson's Chi-squared test
## 
## data:  table(data$Group, data$Gender)
## X-squared = 0.33016, df = 1, p-value = 0.5656
chisq.test(table(data$Group,data$Grade),correct=FALSE)
## 
##  Pearson's Chi-squared test
## 
## data:  table(data$Group, data$Grade)
## X-squared = 3.6386, df = 1, p-value = 0.05645
chisq.test(table(data$Group,data$lang_groups),correct=FALSE)
## 
##  Pearson's Chi-squared test
## 
## data:  table(data$Group, data$lang_groups)
## X-squared = 2.0975, df = 1, p-value = 0.1475
################## IMPROVEMENT BY TREATMENT AND YES/NO TEST  #######################

# Boxplots improvement on cognates by treatment across all classes
impbytreat1 <- ggplot(data = data, 
                      aes(x = Group, 
                          y = T2T1cog)) +
  geom_boxplot() + 
  geom_point(position = position_jitter(width = 0.4,
                                        height = 0.0),
             shape = 1) +
  xlab("Treatment group") + 
  ylab("Improvement T2-T1") + 
  theme_bw() +
  ggtitle("Improvement on cognates T2-T1", 
          sub = "by treatment group") 

impbytreat2 <- ggplot(data = data, 
                      aes(x = Group, 
                          y = (T3T1cog))) +
  geom_boxplot() + 
  geom_point(position = position_jitter(width = 0.4,
                                        height = 0.0),
             shape = 1) +
  xlab("Treatment group") + 
  ylab("Improvement T3-T1") + 
  theme_bw() + 
  ggtitle("Improvement on cognates T3-T1", 
          sub = "by treatment group") 

ggsave(file = "impbytreat1.eps", plot=impbytreat1, width = 3.10, height= 4.14)
ggsave(file = "impbytreat2.eps", plot=impbytreat2, width = 3.10, height= 4.14)


#Boxplots Improvement by treatment and class with colors
T2T1byclass <- ggplot(data = data, 
                      aes(x = fct_reorder(Class,(T2T1cog)), 
                          y = (T2T1cog), color = Group)) +
  geom_boxplot() + 
  geom_point(position = position_jitter(width = 0.4,
                                        height = 0.0),
             shape = 1) +
  xlab("Class") + 
  ylab("Improvement T2-T1") + 
  theme_bw() +
  ggtitle("Improvement on cognates from T1 to T2",
          sub = "by class") 

T3T1byclass <- ggplot(data = data, 
                      aes(x = fct_reorder(Class,(T3T1cog)), 
                          y = (T3T1cog), color = Group)) +
  geom_boxplot() + 
  geom_point(position = position_jitter(width = 0.4,
                                        height = 0.0),
             shape = 1) +
  xlab("Class") + 
  ylab("Improvement T3-T1") + 
  theme_bw() +
  ggtitle("Improvement on cognates from T1 to T3", 
          sub = "by class") 

ggsave(file = "T2T1byclass.eps", plot=T2T1byclass, width = 6.21, height= 3.55)
ggsave(file = "T3T1byclass.eps", plot=T3T1byclass, width = 6.21, height= 3.55)


#Boxplots Improvement by treatment and class grey scales
T2T1byclassgrey <- ggplot(data = data, 
                      aes(x = fct_reorder(Class,(T2T1cog)), 
                          y = (T2T1cog), color = Group),
                      outlier.shape = NA) +
  scale_color_grey(start=0.6, end=0.1) +
  theme_classic() +
  geom_boxplot() + 
  geom_point(position = position_jitter(width = 0.4,
                                        height = 0.0),
             shape = 1) +
  xlab("Class") + 
  ylab("Improvement T2-T1") + 
  theme_bw() +
  ggtitle("Improvement on cognates from T1 to T2",
          sub = "by class") 

T3T1byclassgrey <- ggplot(data = data, 
                      aes(x = fct_reorder(Class,(T3T1cog)), 
                          y = (T3T1cog), color = Group)) +
  scale_color_grey(start=0.6, end=0.1) +
  theme_classic() +
  geom_boxplot() + 
  geom_point(position = position_jitter(width = 0.4,
                                        height = 0.0),
             shape = 1) +
  xlab("Class") + 
  ylab("Improvement T3-T1") + 
  theme_bw() +
  ggtitle("Improvement on cognates from T1 to T3", 
          sub = "by class") 

ggsave(file = "T2T1byclassgrey.eps", plot=T2T1byclassgrey, width = 6.21, height= 3.55)
ggsave(file = "T3T1byclassgrey.eps", plot=T3T1byclassgrey, width = 6.21, height= 3.55)

#Linear Regression Model
summary(lmer(T2T1cog~n.Group*c.wnw_istd+(1|Class), data=data))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: T2T1cog ~ n.Group * c.wnw_istd + (1 | Class)
##    Data: data
## 
## REML criterion at convergence: 1391.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9402 -0.5673 -0.0047  0.6155  4.2187 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Class    (Intercept)  0.3352  0.579   
##  Residual             12.5278  3.539   
## Number of obs: 260, groups:  Class, 17
## 
## Fixed effects:
##                    Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)          0.7012     0.3555  14.4984   1.972 0.067944 .  
## n.Group              2.3383     0.5288  12.8455   4.422 0.000709 ***
## c.wnw_istd           2.0317     1.4850 255.9994   1.368 0.172456    
## n.Group:c.wnw_istd  -2.7803     2.4316 255.8053  -1.143 0.253935    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) n.Grop c.wnw_
## n.Group     -0.672              
## c.wnw_istd   0.032 -0.021       
## n.Grp:c.wn_ -0.019  0.006 -0.611
summary(lmer(T3T1cog~n.Group*c.wnw_istd+(1|Class), data=data))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: T3T1cog ~ n.Group * c.wnw_istd + (1 | Class)
##    Data: data
## 
## REML criterion at convergence: 1407.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.2239 -0.5721  0.0485  0.6493  2.1598 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Class    (Intercept)  1.11    1.054   
##  Residual             12.97    3.601   
## Number of obs: 260, groups:  Class, 17
## 
## Fixed effects:
##                    Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)         -2.0707     0.4590  15.5077  -4.511 0.000382 ***
## n.Group              2.5096     0.6924  13.9929   3.625 0.002762 ** 
## c.wnw_istd          -1.1345     1.5273 253.5325  -0.743 0.458292    
## n.Group:c.wnw_istd  -0.9916     2.4978 252.4969  -0.397 0.691700    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) n.Grop c.wnw_
## n.Group     -0.663              
## c.wnw_istd   0.039 -0.026       
## n.Grp:c.wn_ -0.024  0.012 -0.611
################## IMPROVEMENT BY TYPE OF CORRESPONDENCE #######################

#Improvement by class per correspondence rule
imp_cog_rule <- data %>% 
  group_by(Class, Group, n.Group) %>% 
  summarise(
    mean_T2T1_ck = mean(T2T1ck), mean_T3T1_ck = mean(T3T1ck),
    mean_T2T1_pf = mean(T2T1pf), mean_T3T1_pf = mean(T3T1pf),
    mean_T2T1_thdt = mean(T2T1thdt), mean_T3T1_thdt = mean(T3T1thdt),
    mean_T2T1_tsz = mean(T2T1tsz), mean_T3T1_tsz = mean(T3T1tsz),
    mean_T2T1_kch = mean(T2T1kch), mean_T3T1_kch = mean(T3T1kch),
    .groups = "drop"
  )

#rearrange data
imp_rule <- imp_cog_rule %>%
  pivot_longer(cols = starts_with("mean"),
  names_to = c("time", "rule"),
  names_pattern = "mean_(.*)_(.*)",
  values_to = "mean",
  values_drop_na = TRUE)
imp_rule$rule <- factor(imp_rule$rule,
                            levels=c("ck", "pf", "thdt", "tsz", "kch"))

#boxplot
impbycorrespondence <- ggplot(data = imp_rule,
       aes(x = Group, 
           y = (mean), color = Group)) +
  ylim(c(-0.4, +0.4)) +
  theme_classic() +
  geom_boxplot() + 
  geom_point(position = position_jitter(width = 0.1,
                                        height = 0.0),
             shape = 1) +
  facet_grid(time~rule) +
  xlab("Treatment group") + 
  ylab("Progress") + 
  theme_bw() +
  ggtitle("Improvement by type of correspondence",
          sub = "by treatment (M per class) and test time")

ggsave(file = "impbycorrespondence.eps", plot=impbycorrespondence, width = 6.21, height= 3.55)

#Linear Mixed-Effect Regression Models T2-T1
summary(lmer(T2T1ck~n.Group+(1|Class), data=data))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: T2T1ck ~ n.Group + (1 | Class)
##    Data: data
## 
## REML criterion at convergence: 52.2
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.55632 -0.61851 -0.01167  0.62805  2.47739 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Class    (Intercept) 0.002593 0.05092 
##  Residual             0.067223 0.25927 
## Number of obs: 260, groups:  Class, 17
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)  
## (Intercept)  0.04323    0.02760 16.66389   1.566   0.1361  
## n.Group      0.08342    0.04122 14.77796   2.024   0.0615 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##         (Intr)
## n.Group -0.670
summary(lmer(T2T1pf~n.Group+(1|Class), data=data))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: T2T1pf ~ n.Group + (1 | Class)
##    Data: data
## 
## REML criterion at convergence: 116.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.1387 -0.6612  0.1423  0.8217  2.7558 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Class    (Intercept) 0.004715 0.06867 
##  Residual             0.085648 0.29266 
## Number of obs: 260, groups:  Class, 17
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)   
## (Intercept) -0.03923    0.03345 15.47588  -1.173  0.25855   
## n.Group      0.16731    0.05017 13.79543   3.335  0.00499 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##         (Intr)
## n.Group -0.667
summary(lmer(T2T1thdt~n.Group+(1|Class), data=data))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: T2T1thdt ~ n.Group + (1 | Class)
##    Data: data
## 
## REML criterion at convergence: -16.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.6327 -0.7248 -0.0572  0.6722  3.2101 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Class    (Intercept) 0.002727 0.05222 
##  Residual             0.051199 0.22627 
## Number of obs: 260, groups:  Class, 17
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)  
## (Intercept) -0.03500    0.02567 16.58268  -1.363   0.1910  
## n.Group      0.08515    0.03849 14.77952   2.212   0.0431 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##         (Intr)
## n.Group -0.667
summary(lmer(T2T1tsz~n.Group+(1|Class), data=data))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: T2T1tsz ~ n.Group + (1 | Class)
##    Data: data
## 
## REML criterion at convergence: 31.4
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -3.12462 -0.55625  0.08973  0.77913  2.75051 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Class    (Intercept) 0.00116  0.03407 
##  Residual             0.06278  0.25055 
## Number of obs: 260, groups:  Class, 17
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)  0.12687    0.02402 13.97110   5.283 0.000116 ***
## n.Group      0.09554    0.03563 12.33509   2.682 0.019569 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##         (Intr)
## n.Group -0.674
summary(lmer(T2T1kch~n.Group+(1|Class), data=data))
## boundary (singular) fit: see ?isSingular
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: T2T1kch ~ n.Group + (1 | Class)
##    Data: data
## 
## REML criterion at convergence: 267.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.7798 -0.2717 -0.1612  0.9823  2.3469 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Class    (Intercept) 0.000    0.0000  
##  Residual             0.159    0.3987  
## Number of obs: 260, groups:  Class, 17
## 
## Fixed effects:
##              Estimate Std. Error        df t value Pr(>|t|)  
## (Intercept)   0.06429    0.03370 258.00000   1.908   0.0575 .
## n.Group       0.04405    0.04960 258.00000   0.888   0.3753  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##         (Intr)
## n.Group -0.679
## convergence code: 0
## boundary (singular) fit: see ?isSingular
#Linear Mixed-Effect Regression Models T3-T1
summary(lmer(T3T1ck~n.Group+(1|Class), data=data))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: T3T1ck ~ n.Group + (1 | Class)
##    Data: data
## 
## REML criterion at convergence: 96.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.3353 -0.7768 -0.0743  0.5978  3.7003 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Class    (Intercept) 0.004499 0.06708 
##  Residual             0.079179 0.28139 
## Number of obs: 260, groups:  Class, 17
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept) -0.13151    0.03239 17.02798  -4.061 0.000811 ***
## n.Group      0.12598    0.04859 15.19965   2.593 0.020236 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##         (Intr)
## n.Group -0.666
summary(lmer(T3T1pf~n.Group+(1|Class), data=data))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: T3T1pf ~ n.Group + (1 | Class)
##    Data: data
## 
## REML criterion at convergence: 108
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.6113 -0.5759 -0.1241  0.6094  2.6216 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Class    (Intercept) 0.005911 0.07688 
##  Residual             0.082169 0.28665 
## Number of obs: 260, groups:  Class, 17
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept) -0.18877    0.03489 14.16051  -5.410 8.83e-05 ***
## n.Group      0.18559    0.05252 12.69758   3.534  0.00379 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##         (Intr)
## n.Group -0.664
summary(lmer(T3T1thdt~n.Group+(1|Class), data=data))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: T3T1thdt ~ n.Group + (1 | Class)
##    Data: data
## 
## REML criterion at convergence: -28.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.4746 -0.6189  0.0357  0.6578  3.2892 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Class    (Intercept) 0.005836 0.07639 
##  Residual             0.047625 0.21823 
## Number of obs: 260, groups:  Class, 17
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)  
## (Intercept) -0.08927    0.03086 15.65601  -2.892   0.0108 *
## n.Group      0.04601    0.04682 14.29743   0.983   0.3421  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##         (Intr)
## n.Group -0.659
summary(lmer(T3T1tsz~n.Group+(1|Class), data=data))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: T3T1tsz ~ n.Group + (1 | Class)
##    Data: data
## 
## REML criterion at convergence: 22.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.5628 -0.5718  0.1340  0.7291  2.3325 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Class    (Intercept) 0.005279 0.07266 
##  Residual             0.058498 0.24186 
## Number of obs: 260, groups:  Class, 17
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)  
## (Intercept)  0.03516    0.03126 15.59927   1.125   0.2776  
## n.Group      0.12054    0.04720 14.09217   2.554   0.0229 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##         (Intr)
## n.Group -0.662
summary(lmer(T3T1kch~n.Group+(1|Class), data=data))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: T3T1kch ~ n.Group + (1 | Class)
##    Data: data
## 
## REML criterion at convergence: 301.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.1770 -0.8667  0.1905  0.3214  2.7177 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Class    (Intercept) 0.006008 0.07751 
##  Residual             0.177095 0.42083 
## Number of obs: 260, groups:  Class, 17
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)  
## (Intercept) -0.10969    0.04382 13.48376  -2.503   0.0259 *
## n.Group      0.02603    0.06534 11.92433   0.398   0.6974  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##         (Intr)
## n.Group -0.671
####################### IMPROVEMENT BY TEST MODE ########################################

#Improvement by class per test mode
imp_cog_mode <- data %>% 
  group_by(Class, Group, n.Group) %>% 
  summarise(
    mean_T2T1_receptive = mean(T2T1rec), mean_T3T1_receptive = mean(T3T1rec),
    mean_T2T1_productive = mean(T2T1pro), mean_T3T1_productive = mean(T3T1pro),
    .groups = "drop"
  )

#rearrange data
impmode <- imp_cog_mode %>%
  pivot_longer(cols = starts_with("mean"),
               names_to = c("time", "rule"),
               names_pattern = "mean_(.*)_(.*)",
               values_to = "mean",
               values_drop_na = TRUE)
impmode$rule <- factor(impmode$rule,
                       levels=c("receptive", "productive"))
impmodeT2T1 <- subset(impmode,time=="T2T1") #progress by mode from T1 to T2
impmodeT3T1 <- subset(impmode,time=="T3T1") #progress by mode from T1 to T3
  

#boxplot
plotmodeT2T1 <- ggplot(data = impmodeT2T1,
                             aes(x = Group, 
                                 y = (mean), color = Group)) +
  ylim(c(-2.5, +4)) +
  theme_classic() +
  geom_boxplot() + 
  geom_point(position = position_jitter(width = 0.1,
                                        height = 0.0),
             shape = 1) +
  facet_grid(.~rule) +
  xlab("Treatment group") + 
  ylab("Improvement") + 
  theme_bw() +
  ggtitle("Improvement by test mode from T1 to T2",
          sub = "by treatment (M per class)")

plotmodeT3T1 <- ggplot(data = impmodeT3T1,
                   aes(x = Group, 
                       y = (mean), color = Group)) +
  ylim(c(-2.5, +4)) +
  theme_classic() +
  geom_boxplot() + 
  geom_point(position = position_jitter(width = 0.1,
                                        height = 0.0),
             shape = 1) +
  facet_grid(.~rule) +
  xlab("Treatment group") + 
  ylab("Improvement") + 
  theme_bw() +
  ggtitle("Improvement by test mode from T1 to T3",
          sub = "by treatment (M per class)")

theme_set(theme_pubr())
impbymode <- ggarrange(plotmodeT2T1, plotmodeT3T1,
                    ncol = 2, nrow = 1)

ggsave(file = "impbytestmode.eps", plot=impbymode, width = 6.21, height= 3.55)


#linear regression models by testing mode
summary(lmer(T2T1rec~n.Group+(1|Class), data=data))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: T2T1rec ~ n.Group + (1 | Class)
##    Data: data
## 
## REML criterion at convergence: 1208.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.2413 -0.5696  0.0261  0.6696  2.7837 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Class    (Intercept) 0.3152   0.5614  
##  Residual             5.8898   2.4269  
## Number of obs: 260, groups:  Class, 17
## 
## Fixed effects:
##             Estimate Std. Error      df t value Pr(>|t|)   
## (Intercept)   1.0264     0.2757 15.9048   3.724  0.00186 **
## n.Group       1.4159     0.4133 14.1724   3.426  0.00403 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##         (Intr)
## n.Group -0.667
summary(lmer(T3T1rec~n.Group+(1|Class), data=data))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: T3T1rec ~ n.Group + (1 | Class)
##    Data: data
## 
## REML criterion at convergence: 1197
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -3.11407 -0.56076 -0.01638  0.64865  2.55902 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Class    (Intercept) 0.5605   0.7487  
##  Residual             5.5334   2.3523  
## Number of obs: 260, groups:  Class, 17
## 
## Fixed effects:
##             Estimate Std. Error      df t value Pr(>|t|)   
## (Intercept)  -0.9362     0.3141 16.4659  -2.980  0.00862 **
## n.Group       1.1455     0.4752 14.9381   2.411  0.02927 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##         (Intr)
## n.Group -0.661
summary(lmer(T2T1pro~n.Group+(1|Class), data=data))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: T2T1pro ~ n.Group + (1 | Class)
##    Data: data
## 
## REML criterion at convergence: 1158.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.9601 -0.5549 -0.0024  0.5960  4.1144 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Class    (Intercept) 0.2605   0.5104  
##  Residual             4.8591   2.2043  
## Number of obs: 260, groups:  Class, 17
## 
## Fixed effects:
##             Estimate Std. Error      df t value Pr(>|t|)   
## (Intercept)  -0.2216     0.2505 16.8424  -0.885  0.38881   
## n.Group       1.1242     0.3756 15.0147   2.993  0.00909 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##         (Intr)
## n.Group -0.667
summary(lmer(T3T1pro~n.Group+(1|Class), data=data))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: T3T1pro ~ n.Group + (1 | Class)
##    Data: data
## 
## REML criterion at convergence: 1192
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.99685 -0.65384  0.01003  0.66800  2.55901 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Class    (Intercept) 0.6531   0.8082  
##  Residual             5.3924   2.3222  
## Number of obs: 260, groups:  Class, 17
## 
## Fixed effects:
##             Estimate Std. Error      df t value Pr(>|t|)   
## (Intercept)  -0.9890     0.3272 15.9504  -3.022  0.00812 **
## n.Group       1.5177     0.4963 14.5614   3.058  0.00820 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##         (Intr)
## n.Group -0.659
###################### ATTITUDE #############################
cor.test(dataint$evaluation, dataint$T2T1cog) #attitude towards intervention with progress
## 
##  Pearson's product-moment correlation
## 
## data:  dataint$evaluation and dataint$T2T1cog
## t = -0.32121, df = 118, p-value = 0.7486
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.2076975  0.1504820
## sample estimates:
##         cor 
## -0.02955654
cor.test(dataint$evaluation, dataint$T3T1cog)
## 
##  Pearson's product-moment correlation
## 
## data:  dataint$evaluation and dataint$T3T1cog
## t = 0.60729, df = 118, p-value = 0.5448
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1246704  0.2327311
## sample estimates:
##        cor 
## 0.05581825
cor.test(dataint$tasks_n, dataint$T2T1cog) #number of tasks completed with progress
## 
##  Pearson's product-moment correlation
## 
## data:  dataint$tasks_n and dataint$T2T1cog
## t = -0.4975, df = 118, p-value = 0.6198
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.2231619  0.1345945
## sample estimates:
##         cor 
## -0.04575058
cor.test(dataint$tasks_n, dataint$T3T1cog)
## 
##  Pearson's product-moment correlation
## 
## data:  dataint$tasks_n and dataint$T3T1cog
## t = -0.23777, df = 118, p-value = 0.8125
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.2003388  0.1579777
## sample estimates:
##         cor 
## -0.02188329