The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(emmeans)
Welcome to emmeans.
Caution: You lose important information if you filter this package's results.
See '? untidy'
setwd("D:/Canna_d/EM5_stuff/EM5_data")study_time <-read.csv("Em5_1_data.csv", header = T)# Make condsFile an ordered factorstudy_time$condsFile <-factor(study_time$condsFile,levels =c("noDelay", "longDelay", "totalResponse"),ordered =TRUE)# Model for study timestudyTimeGlmm <-glmer(mean_StudyTime ~ condsFile + age.ct + age.ct*condsFile + (1|participant), data = study_time, family =inverse.gaussian(link ="identity"), nAGQ =0)# Model for MUMU_LMM <-lmer(mean_MU ~ condsFile + age.ct + age.ct*condsFile + (1|participant), data = study_time)# Study time contrastsst_contrasts <-emmeans(studyTimeGlmm, "condsFile")
NOTE: Results may be misleading due to involvement in interactions
# Use -.6, 0, .6# do the contrasts, but separately for st_contrasts_new <-emmeans(studyTimeGlmm, ~ condsFile | age.ct, at =list(age.ct =c(-.6, 0, .6))) contrast(st_contrasts_new, "poly")
^ That makes sense. If you look at the age plot, the younger kids have an opposite trend, so we have a negative estimate. Kids in the middle age are in the middle, and then older kids have a positive estimate because they are showing the expected linear increase across delay conditions.
# OK no age modelst_noAge <-glmer(mean_StudyTime ~ condsFile + (1|participant), data = study_time, family =inverse.gaussian(link ="identity"), nAGQ =0)st_contrasts_noAge <-emmeans(st_noAge, "condsFile")st_result_noAge <-contrast(st_contrasts_noAge, "poly")st_result_noAge
contrast estimate SE df z.ratio p.value
linear 0.383 0.336 Inf 1.139 0.2547
quadratic -1.061 0.656 Inf -1.617 0.1058
^ That is poor model specification anyway (we know age has an effect) I just wanted to see what it looked like.
Possible linear contrasts method (old)
library(lme4)setwd("D:/Canna_d/EM5_stuff/EM5_data")study_time <-read.csv("Em5_1_data.csv", header = T)# Make condsFile an ordered factorstudy_time$condsFile <-factor(study_time$condsFile,levels =c("noDelay", "longDelay", "totalResponse"),ordered =TRUE)# Polynomial contrastscontrasts(study_time$condsFile) <-contr.poly(3)# Model for study timestudyTimeGlmm <-glmer(mean_StudyTime ~ condsFile + age.ct + age.ct*condsFile + (1|participant), data = study_time, family =inverse.gaussian(link ="identity"), nAGQ =0)# Model for MUMU_LMM <-lmer(mean_MU ~ condsFile + age.ct + age.ct*condsFile + (1|participant), data = study_time)# Summariessummary(studyTimeGlmm)
Linear mixed model fit by REML ['lmerMod']
Formula: mean_MU ~ condsFile + age.ct + age.ct * condsFile + (1 | participant)
Data: study_time
REML criterion at convergence: 972.5
Scaled residuals:
Min 1Q Median 3Q Max
-3.8939 -0.4581 0.0386 0.4729 3.3342
Random effects:
Groups Name Variance Std.Dev.
participant (Intercept) 0.5515 0.7426
Residual 2.6985 1.6427
Number of obs: 243, groups: participant, 82
Fixed effects:
Estimate Std. Error t value
(Intercept) 1.91184 0.13362 14.308
condsFile.L 0.52311 0.18337 2.853
condsFile.Q 0.07132 0.18206 0.392
age.ct 0.75940 0.18022 4.214
condsFile.L:age.ct 0.79834 0.24749 3.226
condsFile.Q:age.ct 0.23387 0.24554 0.952
Correlation of Fixed Effects:
(Intr) cndF.L cndF.Q age.ct cF.L:.
condsFile.L -0.014
condsFile.Q 0.008 -0.012
age.ct 0.000 0.000 0.000
cndsFl.L:g. 0.000 0.000 0.000 -0.015
cndsFl.Q:g. 0.000 0.000 0.000 0.009 -0.014
In this output, condsFile.L is the overall linear trend; condsFile.Q is a quadratic trend (not of interest here); age.ct is the fixed effect of age (centered); condsFile.L:age.ct is the interaction between age and the linear trend of condition; condsFile.Q:age.ct is the interaction between age and the quadratic trend of condition (not of interest).