options(dplyr.width = Inf)
knitr::opts_chunk$set(message = FALSE, warning = FALSE, cache=TRUE)
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(lme4)
## Loading required package: Matrix
library(tidyr)
##
## Attaching package: 'tidyr'
## The following object is masked from 'package:Matrix':
##
## expand
library(magrittr)
##
## Attaching package: 'magrittr'
## The following object is masked from 'package:tidyr':
##
## extract
library(lsmeans)
## Warning: package 'lsmeans' was built under R version 3.2.4
## Loading required package: estimability
library(langcog)
##
## Attaching package: 'langcog'
## The following object is masked from 'package:base':
##
## scale
theme_manylabs <- theme_bw() +
theme(axis.text = element_text(size = 14),
axis.title = element_text(size = 16, family="Arial"),
text = element_text(family="Arial"),
legend.key = element_rect(fill = "navy"),
legend.background = element_rect(fill = "white"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
axis.line = element_line(),
strip.background = element_rect(fill = "white", colour = NA),
strip.text.x = element_text(size = 14, face = "bold", colour = "black"))
Create basics of data.
data <- expand.grid(Lab = factor(paste0('Lab',1:20)),
Subject = 1:30,
Trial = 1:16)
Simulation sequence:
blocks <- factor(c('IDS','IDS','ADS','ADS'))
langs <- factor(c('English','French','Spanish','German','Japanese'))
methods <- factor(c('HPP','SingleScreen','AnotherMethod'))
sessions <- factor(c('First','Second'))
bilingual <- c(TRUE, FALSE)
lt_max <- 20 # max LT in a trial
data %<>%
mutate(Subject = factor(toupper(paste0(Lab,'-',Subject))),
Block = ((Trial-1) %/% 4) + 1) %>%
group_by(Subject,Block) %>%
mutate(Condition = sample(blocks)) %>%
group_by(Lab) %>%
mutate(.LabDiff = runif(1, 0, .5)) %>%
ungroup() %>%
mutate(LT = ifelse(Condition == 'IDS',
rlnorm(n(), 1.5 + .LabDiff, .7),
rlnorm(n(), 1.5, .7))) %>%
group_by(Subject) %>%
mutate(LT = LT + runif(1,0,.5)) %>%
ungroup() %>%
mutate(LT = ifelse(LT > lt_max, lt_max, LT)) %>%
group_by(Lab) %>%
mutate(.LabMeanAge = round(runif(1, 3, 12))) %>%
ungroup() %>%
group_by(Subject) %>%
mutate(Age = round(runif(1, .LabMeanAge-.5, .LabMeanAge+.5),2)) %>%
ungroup() %>%
group_by(Lab) %>%
mutate(Method = sample(methods,1)) %>%
ungroup() %>%
group_by(Subject) %>%
mutate(Session = sample(sessions,1),
Language = sample(langs, 1),
Bilingual = sample(bilingual, 1)) %>%
arrange(Lab,Subject,Trial) %>%
select(-starts_with("."))
lt_min <- 2 # minumum LT for inclusion
z_threshold <- 3 # outlier threshold (sds)
min_trials_per_type <- 4 # min trials per type for inclusion
data_clean <- data %>%
filter(LT >= lt_min) %>%
group_by(Subject) %>%
mutate(log_lt = log(LT),
.scaled_log_lt = as.numeric(langcog::scale(log_lt))) %>%
filter(abs(.scaled_log_lt) < z_threshold) %>%
group_by(Subject) %>%
mutate(.N_IDS = sum(Condition == "IDS"),
.N_ADS = sum(Condition == "ADS")) %>%
filter(.N_IDS >= min_trials_per_type &
.N_ADS >= min_trials_per_type) %>%
select(-starts_with("."))
ggplot(data_clean, aes(x = LT)) +
geom_histogram() +
facet_grid(~Condition)
ggplot(data_clean, aes(x=log_lt)) +
geom_histogram() +
facet_grid(~Condition)
agg_subjects <- data_clean %>%
group_by(Lab, Method, Session, Subject, Language, Bilingual, Condition, Age) %>%
summarise(MeanLogLT = mean(log_lt)) %>%
mutate(ConditionC = ifelse(Condition == "IDS", .5, -.5))
agg_subjects_paired <- agg_subjects %>%
select(-ConditionC) %>%
spread(Condition, MeanLogLT) %>%
mutate(Diff = IDS - ADS,
Prop = IDS / (IDS + ADS))
ggplot(agg_subjects, aes(x=Condition, y=MeanLogLT)) +
geom_boxplot() +
theme_manylabs
ggplot(agg_subjects, aes(x=Condition, y=MeanLogLT)) +
stat_summary(fun.y='mean', geom='bar') +
stat_summary(fun.data='mean_cl_normal', geom='errorbar', width=.1, fun.args=list(mult=2)) +
theme_manylabs
ggplot(agg_subjects_paired, aes(x='Overall', y=Diff)) +
geom_boxplot() +
geom_hline(yintercept=0, linetype="dashed", alpha=.5) +
scale_x_discrete('') +
theme_manylabs
ggplot(agg_subjects_paired, aes(x='Overall', y=Diff)) +
stat_summary(fun.y='mean', geom='bar') +
stat_summary(fun.data='mean_cl_normal', geom='errorbar', width=.1, fun.args=list(mult=2)) +
geom_hline(yintercept=0, linetype="dashed", alpha=.5) +
scale_x_discrete('') +
theme_manylabs
t.test(agg_subjects_paired$Diff)
##
## One Sample t-test
##
## data: agg_subjects_paired$Diff
## t = 13.359, df = 599, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## 0.1488969 0.2002224
## sample estimates:
## mean of x
## 0.1745596
mean(agg_subjects_paired$Diff) / sd(agg_subjects_paired$Diff)
## [1] 0.545371
model <- lmer(MeanLogLT ~ ConditionC +
(ConditionC | Lab) +
(1 | Subject),
data=agg_subjects, REML=FALSE)
summary(model)
## Linear mixed model fit by maximum likelihood ['lmerMod']
## Formula: MeanLogLT ~ ConditionC + (ConditionC | Lab) + (1 | Subject)
## Data: agg_subjects
##
## AIC BIC logLik deviance df.resid
## -234.5 -198.9 124.3 -248.5 1193
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.04878 -0.70263 0.02433 0.65148 3.09279
##
## Random effects:
## Groups Name Variance Std.Dev. Corr
## Subject (Intercept) 0.0003239 0.01800
## Lab (Intercept) 0.0032653 0.05714
## ConditionC 0.0111353 0.10552 1.00
## Residual 0.0455710 0.21347
## Number of obs: 1200, groups: Subject, 600; Lab, 20
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) 1.77120 0.01421 124.69
## ConditionC 0.17456 0.02662 6.56
##
## Correlation of Fixed Effects:
## (Intr)
## ConditionC 0.797
drop1(model,~.,test="Chi")
## Single term deletions
##
## Model:
## MeanLogLT ~ ConditionC + (ConditionC | Lab) + (1 | Subject)
## Df AIC LRT Pr(Chi)
## <none> -234.53
## ConditionC 1 -213.51 23.016 1.606e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ggplot(agg_subjects_paired, aes(x=Lab, y=Diff)) +
stat_summary(fun.y='mean', geom='point') +
stat_summary(fun.data='mean_cl_normal', geom='errorbar', width=.1, fun.args=list(mult=2)) +
geom_hline(yintercept=0, linetype="dashed", alpha=.5) +
scale_x_discrete('') +
coord_flip() +
theme_manylabs
model <- lmer(MeanLogLT ~ ConditionC + (1 + ConditionC | Lab) + (1 | Subject), data=agg_subjects, REML=F)
fixed_effect <- fixef(model)[['ConditionC']]
lab_ranefs <- data.frame(Lab = factor(rownames(ranef(model)$Lab),
levels=rownames(ranef(model)$Lab)),
ConditionRanef = ranef(model)$Lab$ConditionC +
fixed_effect)
ggplot(lab_ranefs, aes(x=Lab, y=ConditionRanef, group=Lab)) +
geom_point() +
geom_errorbar(aes(ymin=fixed_effect, ymax=ConditionRanef), width=.1) +
geom_hline(yintercept=0, linetype="dashed", alpha=.5) +
geom_hline(yintercept=fixed_effect, linetype="solid", alpha=.5) +
scale_x_discrete('') +
scale_y_continuous('Random Effect') +
coord_flip() +
theme_manylabs
agg_subjects %<>%
ungroup() %>%
mutate(AgeC = Age - mean(Age))
ggplot(agg_subjects_paired, aes(x=Age, y=Diff)) +
geom_point() +
stat_smooth() +
geom_hline(yintercept=0, linetype="dashed", alpha=.5) +
theme_manylabs
model <- lmer(MeanLogLT ~ ConditionC*AgeC + (1 + ConditionC + AgeC | Lab) + (1 | Subject), data=agg_subjects, REML=F)
summary(model)
## Linear mixed model fit by maximum likelihood ['lmerMod']
## Formula: MeanLogLT ~ ConditionC * AgeC + (1 + ConditionC + AgeC | Lab) +
## (1 | Subject)
## Data: agg_subjects
##
## AIC BIC logLik deviance df.resid
## -226.7 -165.6 125.4 -250.7 1188
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.02938 -0.71851 0.03284 0.65509 3.06598
##
## Random effects:
## Groups Name Variance Std.Dev. Corr
## Subject (Intercept) 3.247e-04 0.018018
## Lab (Intercept) 2.753e-03 0.052468
## ConditionC 1.101e-02 0.104933 1.00
## AgeC 1.306e-05 0.003614 1.00 1.00
## Residual 4.555e-02 0.213422
## Number of obs: 1200, groups: Subject, 600; Lab, 20
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) 1.770240 0.013348 132.62
## ConditionC 0.174560 0.026502 6.59
## AgeC 0.006479 0.006488 1.00
## ConditionC:AgeC 0.002580 0.012569 0.21
##
## Correlation of Fixed Effects:
## (Intr) CndtnC AgeC
## ConditionC 0.778
## AgeC 0.201 0.110
## CondtnC:AgC 0.092 0.000 0.744
drop1(model,~.,test="Chi")
## Single term deletions
##
## Model:
## MeanLogLT ~ ConditionC * AgeC + (1 + ConditionC + AgeC | Lab) +
## (1 | Subject)
## Df AIC LRT Pr(Chi)
## <none> -226.71
## ConditionC 1 -205.96 22.7478 1.847e-06 ***
## AgeC 1 -227.81 0.9000 0.3428
## ConditionC:AgeC 1 -228.67 0.0398 0.8420
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# model with linear+quadratic random effect of age, but only linear fixed effect
model <- lmer(MeanLogLT ~ ConditionC*poly(AgeC,1) +
(1 + ConditionC + poly(AgeC,2) | Lab) +
(1 | Subject),
data=agg_subjects, REML=FALSE)
# model with linear+quadratic random and fixed effects of age
model_2 <- lmer(MeanLogLT ~ ConditionC*poly(AgeC,2) +
(1 + ConditionC + poly(AgeC,2) | Lab) +
(1 | Subject), data=agg_subjects,
REML=FALSE)
anova(model,model_2)
## Data: agg_subjects
## Models:
## model: MeanLogLT ~ ConditionC * poly(AgeC, 1) + (1 + ConditionC + poly(AgeC,
## model: 2) | Lab) + (1 | Subject)
## model_2: MeanLogLT ~ ConditionC * poly(AgeC, 2) + (1 + ConditionC + poly(AgeC,
## model_2: 2) | Lab) + (1 | Subject)
## Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq)
## model 16 -218.76 -137.32 125.38 -250.76
## model_2 18 -215.11 -123.49 125.55 -251.11 0.345 2 0.8415
data_clean %<>%
ungroup() %>%
mutate(TrialC = Trial - mean(Trial),
ConditionC = ifelse(Condition == "IDS", .5, -.5),
AgeC = Age - mean(Age))
ggplot(data_clean, aes(x=Trial, y=log_lt, color=Condition)) +
stat_summary(fun.y='mean', geom='point') +
stat_summary(fun.y='mean', geom='line') +
stat_summary(fun.data='mean_cl_normal', geom='errorbar', width=.1, fun.args=list(mult=2)) +
theme_manylabs
# model <- lmer(log_lt ~ ConditionC*AgeC*TrialC +
# (1 + ConditionC + AgeC + TrialC | Lab) +
# (1 + TrialC + ConditionC | Subject),
# data=data_clean, REML=FALSE)
# summary(model)
# drop1(model,~.,test="Chi")
Note age | lab
doesn’t converge.
ggplot(agg_subjects_paired, aes(x=Method, y=Diff)) +
stat_summary(fun.y='mean', geom='bar') +
stat_summary(fun.data='mean_cl_normal', geom='errorbar', width=.1, fun.args=list(mult=2)) +
geom_hline(yintercept=0, linetype="dashed", alpha=.5) +
scale_x_discrete('') +
theme_manylabs
contrasts(agg_subjects$Method) <- contr.sum(length(unique(agg_subjects$Method)))
model <- lmer(MeanLogLT ~ ConditionC * Method * AgeC +
(1 + ConditionC | Lab) +
(1 | Subject),
data=agg_subjects, REML=FALSE)
summary(model)
## Linear mixed model fit by maximum likelihood ['lmerMod']
## Formula:
## MeanLogLT ~ ConditionC * Method * AgeC + (1 + ConditionC | Lab) +
## (1 | Subject)
## Data: agg_subjects
##
## AIC BIC logLik deviance df.resid
## -225.4 -138.9 129.7 -259.4 1183
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.00357 -0.71266 0.03329 0.64608 3.13331
##
## Random effects:
## Groups Name Variance Std.Dev. Corr
## Subject (Intercept) 0.0003446 0.01856
## Lab (Intercept) 0.0018302 0.04278
## ConditionC 0.0068996 0.08306 1.00
## Residual 0.0454818 0.21326
## Number of obs: 1200, groups: Subject, 600; Lab, 20
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) 1.775822 0.012455 142.58
## ConditionC 0.191141 0.024345 7.85
## Method1 -0.004426 0.017262 -0.26
## Method2 -0.001249 0.019217 -0.07
## AgeC 0.009258 0.005979 1.55
## ConditionC:Method1 -0.006858 0.033742 -0.20
## ConditionC:Method2 0.002398 0.037564 0.06
## ConditionC:AgeC 0.008104 0.011694 0.69
## Method1:AgeC -0.001418 0.008400 -0.17
## Method2:AgeC -0.019021 0.008397 -2.27
## ConditionC:Method1:AgeC 0.017986 0.016430 1.09
## ConditionC:Method2:AgeC -0.042832 0.016422 -2.61
##
## Correlation of Fixed Effects:
## (Intr) CndtnC Methd1 Methd2 AgeC CnC:M1 CnC:M2 CnC:AC Mt1:AC
## ConditionC 0.696
## Method1 -0.057 -0.041
## Method2 0.247 0.171 -0.609
## AgeC -0.048 -0.034 0.284 -0.297
## CndtnC:Mth1 -0.041 -0.057 0.696 -0.423 0.191
## CndtnC:Mth2 0.171 0.247 -0.423 0.696 -0.200 -0.609
## CondtnC:AgC -0.034 -0.048 0.191 -0.200 0.669 0.285 -0.297
## Method1:AgC 0.281 0.188 0.153 0.052 -0.019 0.101 0.036 -0.015
## Method2:AgC -0.326 -0.220 0.058 -0.256 -0.019 0.040 -0.174 -0.007 -0.480
## CndtC:M1:AC 0.188 0.281 0.101 0.036 -0.015 0.153 0.052 -0.018 0.668
## CndtC:M2:AC -0.220 -0.326 0.040 -0.174 -0.007 0.057 -0.256 -0.020 -0.324
## Mt2:AC CC:M1:
## ConditionC
## Method1
## Method2
## AgeC
## CndtnC:Mth1
## CndtnC:Mth2
## CondtnC:AgC
## Method1:AgC
## Method2:AgC
## CndtC:M1:AC -0.324
## CndtC:M2:AC 0.674 -0.480
model_null <- lmer(MeanLogLT ~ ConditionC*AgeC +
(1 + ConditionC + AgeC | Lab) +
(1 | Subject), data=agg_subjects,
REML=FALSE)
anova(model, model_null)
## Data: agg_subjects
## Models:
## model_null: MeanLogLT ~ ConditionC * AgeC + (1 + ConditionC + AgeC | Lab) +
## model_null: (1 | Subject)
## model: MeanLogLT ~ ConditionC * Method * AgeC + (1 + ConditionC | Lab) +
## model: (1 | Subject)
## Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq)
## model_null 12 -226.71 -165.63 125.35 -250.71
## model 17 -225.41 -138.88 129.70 -259.41 8.7008 5 0.1216
# post-hoc least-squares contrasts
lstrends(model, ~ Method, var="ConditionC", adjust="none")
## Method ConditionC.trend SE df lower.CL upper.CL
## AnotherMethod 0.1842822 0.04681684 25.28 0.08791604 0.2806484
## HPP 0.1935387 0.05733986 25.23 0.07549909 0.3115783
## SingleScreen 0.1956007 0.04079170 24.53 0.11150624 0.2796952
##
## Confidence level used: 0.95
ggplot(agg_subjects_paired, aes(x=Session, y=Diff)) +
stat_summary(fun.y='mean', geom='bar') +
stat_summary(fun.data='mean_cl_normal', geom='errorbar', width=.1, fun.args=list(mult=2)) +
geom_hline(yintercept=0, linetype="dashed", alpha=.5) +
scale_x_discrete('') +
theme_manylabs
contrasts(agg_subjects$Session) <- contr.sum(length(unique(agg_subjects$Session)))
model <- lmer(MeanLogLT ~ ConditionC*Session*AgeC + (1 + ConditionC + AgeC | Lab) + (1 | Subject), data=agg_subjects, REML=F)
summary(model)
## Linear mixed model fit by maximum likelihood ['lmerMod']
## Formula:
## MeanLogLT ~ ConditionC * Session * AgeC + (1 + ConditionC + AgeC |
## Lab) + (1 | Subject)
## Data: agg_subjects
##
## AIC BIC logLik deviance df.resid
## -220.8 -139.4 126.4 -252.8 1184
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.0015 -0.7208 0.0313 0.6550 3.0355
##
## Random effects:
## Groups Name Variance Std.Dev. Corr
## Subject (Intercept) 3.061e-04 0.017496
## Lab (Intercept) 2.738e-03 0.052325
## ConditionC 1.101e-02 0.104925 1.00
## AgeC 1.312e-05 0.003622 1.00 1.00
## Residual 4.549e-02 0.213280
## Number of obs: 1200, groups: Subject, 600; Lab, 20
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) 1.770588 0.013323 132.89
## ConditionC 0.174327 0.026511 6.58
## Session1 0.005381 0.006257 0.86
## AgeC 0.006616 0.006481 1.02
## ConditionC:Session1 -0.003099 0.012428 -0.25
## ConditionC:AgeC 0.003013 0.012586 0.24
## Session1:AgeC 0.002205 0.003207 0.69
## ConditionC:Session1:AgeC 0.005766 0.006368 0.91
##
## Correlation of Fixed Effects:
## (Intr) CndtnC Sessn1 AgeC CnC:S1 CnC:AC Ss1:AC
## ConditionC 0.777
## Session1 0.031 0.000
## AgeC 0.201 0.110 -0.016
## CndtnC:Sss1 -0.001 0.033 0.014 -0.009
## CondtnC:AgC 0.092 0.000 -0.014 0.742 -0.008
## Sessin1:AgC -0.001 0.000 0.002 0.044 0.002 -0.006
## CndtC:S1:AC 0.000 -0.001 0.002 0.001 0.001 0.054 0.005
model_null <- lmer(MeanLogLT ~ ConditionC*AgeC + (1 + ConditionC + AgeC | Lab) + (1 | Subject), data=agg_subjects, REML=F)
anova(model,model_null)
## Data: agg_subjects
## Models:
## model_null: MeanLogLT ~ ConditionC * AgeC + (1 + ConditionC + AgeC | Lab) +
## model_null: (1 | Subject)
## model: MeanLogLT ~ ConditionC * Session * AgeC + (1 + ConditionC + AgeC |
## model: Lab) + (1 | Subject)
## Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq)
## model_null 12 -226.71 -165.63 125.35 -250.71
## model 16 -220.79 -139.35 126.40 -252.79 2.0872 4 0.7197
# post-hoc least-squares contrasts
lstrends(model, ~ Session, var="ConditionC", adjust="none")
## Session ConditionC.trend SE df lower.CL upper.CL
## First 0.1712280 0.03076858 33.45 0.1086611 0.2337949
## Second 0.1774265 0.03004716 30.30 0.1160875 0.2387656
##
## Confidence level used: 0.95
ggplot(agg_subjects_paired, aes(x=Language, y=Diff)) +
stat_summary(fun.y='mean', geom='bar') +
stat_summary(fun.data='mean_cl_normal', geom='errorbar', width=.1, fun.args=list(mult=2)) +
geom_hline(yintercept=0, linetype="dashed", alpha=.5) +
scale_x_discrete('') +
theme_manylabs
contrasts(agg_subjects$Language) <- contr.sum(length(unique(agg_subjects$Language)))
model <- lmer(MeanLogLT ~ ConditionC*Language*AgeC + (1 + ConditionC + AgeC | Lab) + (1 | Subject), data=agg_subjects, REML=F)
summary(model)
## Linear mixed model fit by maximum likelihood ['lmerMod']
## Formula: MeanLogLT ~ ConditionC * Language * AgeC + (1 + ConditionC +
## AgeC | Lab) + (1 | Subject)
## Data: agg_subjects
##
## AIC BIC logLik deviance df.resid
## -211.8 -69.2 133.9 -267.8 1172
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.96484 -0.68570 0.02633 0.66545 3.01232
##
## Random effects:
## Groups Name Variance Std.Dev. Corr
## Subject (Intercept) 7.194e-04 0.026821
## Lab (Intercept) 2.810e-03 0.053008
## ConditionC 1.063e-02 0.103096 1.00
## AgeC 1.054e-05 0.003247 1.00 1.00
## Residual 4.451e-02 0.210968
## Number of obs: 1200, groups: Subject, 600; Lab, 20
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) 1.771e+00 1.344e-02 131.71
## ConditionC 1.746e-01 2.609e-02 6.69
## Language1 -2.240e-03 1.311e-02 -0.17
## Language2 -3.246e-04 1.231e-02 -0.03
## Language3 5.851e-03 1.223e-02 0.48
## Language4 -1.178e-02 1.239e-02 -0.95
## AgeC 6.377e-03 6.547e-03 0.97
## ConditionC:Language1 2.743e-02 2.580e-02 1.06
## ConditionC:Language2 3.385e-02 2.421e-02 1.40
## ConditionC:Language3 5.702e-03 2.407e-02 0.24
## ConditionC:Language4 -7.678e-02 2.438e-02 -3.15
## ConditionC:AgeC 2.390e-03 1.243e-02 0.19
## Language1:AgeC -4.657e-03 6.958e-03 -0.67
## Language2:AgeC 5.709e-06 6.611e-03 0.00
## Language3:AgeC 6.324e-03 6.399e-03 0.99
## Language4:AgeC 1.848e-03 6.299e-03 0.29
## ConditionC:Language1:AgeC 2.693e-03 1.368e-02 0.20
## ConditionC:Language2:AgeC 1.177e-02 1.301e-02 0.90
## ConditionC:Language3:AgeC -2.226e-02 1.258e-02 -1.77
## ConditionC:Language4:AgeC -2.152e-03 1.240e-02 -0.17
##
## Correlation of Fixed Effects:
## (Intr) CndtnC Langg1 Langg2 Langg3 Langg4 AgeC CnC:L1 CnC:L2
## ConditionC 0.779
## Language1 0.030 0.000
## Language2 -0.013 0.000 -0.268
## Language3 -0.015 0.000 -0.257 -0.234
## Language4 -0.004 0.000 -0.269 -0.233 -0.241
## AgeC 0.180 0.099 -0.016 -0.013 0.000 0.019
## CndtnC:Lng1 0.002 0.030 0.014 -0.008 0.000 -0.005 0.014
## CndtnC:Lng2 -0.002 -0.011 -0.008 0.016 -0.005 0.003 -0.013 -0.268
## CndtnC:Lng3 -0.001 -0.015 0.001 -0.005 0.016 -0.006 -0.006 -0.257 -0.234
## CndtnC:Lng4 0.000 -0.005 -0.005 0.003 -0.006 0.010 0.000 -0.269 -0.233
## CondtnC:AgC 0.083 0.000 0.006 -0.021 -0.009 0.003 0.744 -0.007 -0.003
## Langug1:AgC -0.019 0.000 -0.060 0.010 0.016 0.008 0.052 0.000 -0.002
## Langug2:AgC 0.008 0.000 0.014 0.027 -0.023 -0.023 0.013 0.002 0.003
## Langug3:AgC 0.009 0.000 0.015 -0.022 0.029 -0.028 0.003 0.002 -0.005
## Langug4:AgC 0.015 0.000 0.009 -0.022 -0.029 0.045 -0.013 0.002 0.001
## CndtC:L1:AC -0.001 -0.020 0.000 -0.002 0.002 0.002 -0.007 -0.064 0.013
## CndtC:L2:AC 0.002 0.009 0.002 0.003 -0.006 0.000 0.009 0.016 0.024
## CndtC:L3:AC 0.000 0.009 0.002 -0.004 0.003 -0.003 0.000 0.015 -0.021
## CndtC:L4:AC 0.001 0.015 0.002 0.001 -0.003 0.000 0.005 0.010 -0.024
## CnC:L3 CnC:L4 CnC:AC Ln1:AC Ln2:AC Ln3:AC Ln4:AC CC:L1: CC:L2:
## ConditionC
## Language1
## Language2
## Language3
## Language4
## AgeC
## CndtnC:Lng1
## CndtnC:Lng2
## CndtnC:Lng3
## CndtnC:Lng4 -0.240
## CondtnC:AgC 0.003 0.015
## Langug1:AgC 0.002 0.002 0.003
## Langug2:AgC -0.005 0.000 0.000 -0.297
## Langug3:AgC 0.003 -0.003 0.009 -0.270 -0.255
## Langug4:AgC -0.003 0.000 0.002 -0.276 -0.242 -0.241
## CndtC:L1:AC 0.016 0.010 0.040 0.018 -0.013 0.001 -0.006
## CndtC:L2:AC -0.022 -0.024 0.026 -0.013 0.014 -0.003 0.006 -0.297
## CndtC:L3:AC 0.025 -0.026 -0.010 0.001 -0.003 0.018 -0.008 -0.272 -0.253
## CndtC:L4:AC -0.027 0.043 -0.010 -0.006 0.006 -0.008 0.009 -0.276 -0.242
## CC:L3:
## ConditionC
## Language1
## Language2
## Language3
## Language4
## AgeC
## CndtnC:Lng1
## CndtnC:Lng2
## CndtnC:Lng3
## CndtnC:Lng4
## CondtnC:AgC
## Langug1:AgC
## Langug2:AgC
## Langug3:AgC
## Langug4:AgC
## CndtC:L1:AC
## CndtC:L2:AC
## CndtC:L3:AC
## CndtC:L4:AC -0.240
model_null <- lmer(MeanLogLT ~ ConditionC*AgeC + (1 + ConditionC + AgeC | Lab) + (1 | Subject), data=agg_subjects, REML=F)
anova(model,model_null)
## Data: agg_subjects
## Models:
## model_null: MeanLogLT ~ ConditionC * AgeC + (1 + ConditionC + AgeC | Lab) +
## model_null: (1 | Subject)
## model: MeanLogLT ~ ConditionC * Language * AgeC + (1 + ConditionC +
## model: AgeC | Lab) + (1 | Subject)
## Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq)
## model_null 12 -226.71 -165.626 125.35 -250.71
## model 28 -211.76 -69.236 133.88 -267.76 17.051 16 0.3823
# post-hoc least-squares contrasts
lstrends(model, ~ Language, var="ConditionC", adjust="none")
## Language ConditionC.trend SE df lower.CL upper.CL
## English 0.20201656 0.03835002 84.68 0.12576227 0.2782709
## French 0.20843726 0.03653104 70.12 0.13558062 0.2812939
## German 0.18029043 0.03641054 68.97 0.10765277 0.2529281
## Japanese 0.09781183 0.03671051 72.23 0.02463483 0.1709888
## Spanish 0.18438438 0.03697988 73.51 0.11069220 0.2580766
##
## Confidence level used: 0.95
ggplot(agg_subjects_paired, aes(x=Bilingual, y=Diff)) +
stat_summary(fun.y='mean', geom='bar') +
stat_summary(fun.data='mean_cl_normal', geom='errorbar', width=.1, fun.args=list(mult=2)) +
geom_hline(yintercept=0, linetype="dashed", alpha=.5) +
scale_x_discrete('') +
theme_manylabs
contrasts(agg_subjects$Bilingual) <- contr.sum(length(unique(agg_subjects$Bilingual)))
model <- lmer(MeanLogLT ~ ConditionC*Bilingual*AgeC + (1 + ConditionC + AgeC | Lab) + (1 | Subject), data=agg_subjects, REML=F)
summary(model)
## Linear mixed model fit by maximum likelihood ['lmerMod']
## Formula: MeanLogLT ~ ConditionC * Bilingual * AgeC + (1 + ConditionC +
## AgeC | Lab) + (1 | Subject)
## Data: agg_subjects
##
## AIC BIC logLik deviance df.resid
## -221.1 -139.7 126.5 -253.1 1184
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.98573 -0.71939 0.03742 0.66760 3.06556
##
## Random effects:
## Groups Name Variance Std.Dev. Corr
## Subject (Intercept) 3.198e-04 0.017884
## Lab (Intercept) 2.743e-03 0.052371
## ConditionC 1.098e-02 0.104794 1.00
## AgeC 1.256e-05 0.003544 1.00 1.00
## Residual 4.546e-02 0.213221
## Number of obs: 1200, groups: Subject, 600; Lab, 20
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) 1.7698215 0.0133292 132.78
## ConditionC 0.1747413 0.0264800 6.60
## Bilingual1 0.0072041 0.0062581 1.15
## AgeC 0.0064671 0.0064801 1.00
## ConditionC:Bilingual1 -0.0020391 0.0124148 -0.16
## ConditionC:AgeC 0.0026545 0.0125669 0.21
## Bilingual1:AgeC -0.0002909 0.0032065 -0.09
## ConditionC:Bilingual1:AgeC 0.0064829 0.0063567 1.02
##
## Correlation of Fixed Effects:
## (Intr) CndtnC Blngl1 AgeC CnC:B1 CnC:AC Bl1:AC
## ConditionC 0.777
## Bilingual1 -0.030 0.000
## AgeC 0.198 0.108 -0.016
## CndtnC:Bln1 -0.001 -0.028 0.014 -0.007
## CondtnC:AgC 0.091 0.000 -0.017 0.745 -0.003
## Bilngl1:AgC 0.004 0.000 0.010 0.020 0.009 0.014
## CndtC:B1:AC 0.002 0.002 0.009 0.017 0.007 0.024 0.014
model_null <- lmer(MeanLogLT ~ ConditionC*AgeC + (1 + ConditionC + AgeC | Lab) + (1 | Subject), data=agg_subjects, REML=F)
anova(model,model_null)
## Data: agg_subjects
## Models:
## model_null: MeanLogLT ~ ConditionC * AgeC + (1 + ConditionC + AgeC | Lab) +
## model_null: (1 | Subject)
## model: MeanLogLT ~ ConditionC * Bilingual * AgeC + (1 + ConditionC +
## model: AgeC | Lab) + (1 | Subject)
## Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq)
## model_null 12 -226.71 -165.63 125.35 -250.71
## model 16 -221.10 -139.66 126.55 -253.10 2.3909 4 0.6643
# post-hoc least-squares contrasts
lstrends(model, ~ Bilingual, var="ConditionC", adjust="none")
## Bilingual ConditionC.trend SE df lower.CL upper.CL
## FALSE 0.1727022 0.03007350 30.48 0.1113248 0.2340796
## TRUE 0.1767804 0.03069259 33.19 0.1143491 0.2392116
##
## Confidence level used: 0.95