This topic contains 3 replies, has 2 voices, and was last updated by henrik 2 months, 4 weeks ago.

AuthorPosts

April 10, 2018 at 18:03 UTC #229
I am comparing the results of emmeans across different models with a toy dataset. I am fitting a model in which a continuous outcome is predicted by a 3level factor and a control variable. I have fit the model in two ways, with a linear regression model using the lm function in R (representing the factor my two dummy codes). And as an ANCOVA using the aov_ez function. The emmeans that I obtain from the lm and ancova model are not exactly the same, although I expected them to be. Likewise, the contrasts from the ANCOVA model that should correspond with the dummy coded effects aren’t precisely the same. Is there a reason these would be slightly different? Do I need to modify my aov_ez model in some way to make the emmeans results and contrasts equivalent? I do get the exact same results if there is no covariate.
Linear model:
lm.1 < lm(sleep ~ cond.f + anxiety.m, data = slp)
summary(lm.1)compare < emmeans(lm.1, ~ cond.f + anxiety.m)
compareANCOVA:
anvmod < aov_ez(id = “id”, dv = “sleep”, data = slp, between = c(“cond.f”),
covariate = c(“anxiety.m”),
factorize = FALSE)
summary(anvmod)compare < lsmeans(anvmod, ~ cond.f + anxiety.m)
compare# make constrasts
cond2_1 < c(1, 1, 0)
cond3_1 < c(1, 0, 1)
summary(contrast(compare, list(cond2_1, cond3_1)))data are here: https://pastebin.com/qTajz9ak

April 11, 2018 at 20:44 UTC #233
This is indeed a bug in
afex
with ANCOVAs. It has to do with the way theaov
object is used internally and I am working on a fix. So long, one can circumvent the use of theaov
object and simply use thelm
object. This somewhat nonintuitively is done by settingmodel = "multivariate"
in the call toemmeans
:library(afex) slp < read.csv("https://pastebin.com/raw/qTajz9ak") lm.1 < lm(sleep ~ cond.f + anxiety.m, data = slp) emmeans(lm.1, ~ cond.f + anxiety.m) # cond.f anxiety.m emmean SE df lower.CL upper.CL # groupbased 4.746059e17 69.27959 0.7289347 596 67.84800 70.71119 # group + partner 4.746059e17 76.35960 0.7279758 596 74.92989 77.78931 # self help 4.746059e17 60.99081 0.7293691 596 59.55836 62.42325 # # Confidence level used: 0.95 anvmod < aov_ez(id = "id", dv = "sleep", data = slp, between = c("cond.f"), covariate = c("anxiety.m"), factorize = FALSE) emmeans(anvmod, ~ cond.f + anxiety.m, model = "multivariate") # cond.f anxiety.m lsmean SE df lower.CL upper.CL # groupbased 4.746059e17 69.27959 0.7289347 596 67.84800 70.71119 # group + partner 4.746059e17 76.35960 0.7279758 596 74.92989 77.78931 # self help 4.746059e17 60.99081 0.7293691 596 59.55836 62.42325 # # Confidence level used: 0.95
I will post here again, when I have fixed the bug in
afex
. Thanks a lot for reporting it! 
April 15, 2018 at 21:51 UTC #239
The development version of
afex
fromgithub
now returns the correct results. I will update the post when I submit this version toCRAN
.devtools::install_github("singmann/afex") library(afex) packageVersion("afex") # [1] ‘0.21.0’ slp < read.csv("https://pastebin.com/raw/qTajz9ak") lm.1 < lm(sleep ~ cond.f + anxiety.m, data = slp) emmeans(lm.1, ~ cond.f + anxiety.m) # cond.f anxiety.m emmean SE df lower.CL upper.CL # groupbased 4.746059e17 69.27959 0.7289347 596 67.84800 70.71119 # group + partner 4.746059e17 76.35960 0.7279758 596 74.92989 77.78931 # self help 4.746059e17 60.99081 0.7293691 596 59.55836 62.42325 # # Confidence level used: 0.95 anvmod < aov_ez(id = "id", dv = "sleep", data = slp, between = c("cond.f"), covariate = c("anxiety.m"), factorize = FALSE) emmeans(anvmod, ~ cond.f + anxiety.m) # cond.f anxiety.m emmean SE df lower.CL upper.CL # groupbased 4.746059e17 69.27959 0.7289347 596 67.84800 70.71119 # group + partner 4.746059e17 76.35960 0.7279758 596 74.92989 77.78931 # self help 4.746059e17 60.99081 0.7293691 596 59.55836 62.42325 # # Confidence level used: 0.95 emmeans(anvmod, ~ cond.f + anxiety.m, model = "multivariate") # cond.f anxiety.m emmean SE df lower.CL upper.CL # groupbased 4.746059e17 69.27959 0.7289347 596 67.84800 70.71119 # group + partner 4.746059e17 76.35960 0.7279758 596 74.92989 77.78931 # self help 4.746059e17 60.99081 0.7293691 596 59.55836 62.42325 # # Confidence level used: 0.95
Thanks again for reporting this.

June 25, 2018 at 08:46 UTC #272
A new version of
afex
, version0.212
, that fixes this bug, has just appeared onCRAN
: https://cran.rproject.org/package=afexI apologize for the delay!

AuthorPosts
You must be logged in to reply to this topic.