我有一个纵向研究的数据,并计算回归使用lmer 4::lmer函数。之后,我计算了这些数据的对比,但我很难解释我的结果,因为它们是出乎意料的。我想我可能是在密码上弄错了。不幸的是,我不能用一个例子来复制我的结果,但是我会在下面发布失败的例子和我的实际结果。
我的研究结果:
library(lme4)
library(lmerTest)
library(emmeans)
#regression
regmemory <- lmer(memory ~ as.factor(QuartileConsumption)*Age+
(1 + Age | ID) + sex + education +
HealthScore, CognitionData)
#results
summary(regmemory)
#Fixed effects:
# Estimate Std. Error df t value Pr(>|t|)
#(Intercept) -7.981e-01 9.803e-02 1.785e+04 -8.142 4.15e-16 ***
#as.factor(QuartileConsumption)2 -8.723e-02 1.045e-01 2.217e+04 -0.835 0.40376
#as.factor(QuartileConsumption)3 5.069e-03 1.036e-01 2.226e+04 0.049 0.96097
#as.factor(QuartileConsumption)4 -2.431e-02 1.030e-01 2.213e+04 -0.236 0.81337
#Age -1.709e-02 1.343e-03 1.989e+04 -12.721 < 2e-16 ***
#sex 3.247e-01 1.520e-02 1.023e+04 21.355 < 2e-16 ***
#education 2.979e-01 1.093e-02 1.061e+04 27.266 < 2e-16 ***
#HealthScore -1.098e-06 5.687e-07 1.021e+04 -1.931 0.05352 .
#as.factor(QuartileConsumption)2:Age 1.101e-03 1.842e-03 1.951e+04 0.598 0.55006
#as.factor(QuartileConsumption)3:Age 4.113e-05 1.845e-03 1.935e+04 0.022 0.98221
#as.factor(QuartileConsumption)4:Age 1.519e-03 1.851e-03 1.989e+04 0.821 0.41174
#contrasts
emmeans(regmemory, poly ~ QuartileConsumption * Age)$contrast
#$contrasts
# contrast estimate SE df z.ratio p.value
# linear 0.2165 0.0660 Inf 3.280 0.0010
# quadratic 0.0791 0.0289 Inf 2.733 0.0063
# cubic -0.0364 0.0642 Inf -0.567 0.5709回归结果中的相互作用项不显着,但线性对比是显著的。对比的p值不应该是无意义的吗?
下面是我为重新创建这些结果而编写的代码,但失败了:
library(dplyr)
library(lme4)
library(lmerTest)
library(emmeans)
data("sleepstudy")
#create quartile column
sleepstudy$Quartile <- sample(1:4, size = nrow(sleepstudy), replace = T)
#regression
model1 <- lmer(Reaction ~ Days * as.factor(Quartile) + (1 + Days | Subject), data = sleepstudy)
#results
summary(model1)
#Fixed effects:
# Estimate Std. Error df t value Pr(>|t|)
#(Intercept) 258.1519 9.6513 54.5194 26.748 < 2e-16 ***
#Days 9.8606 2.0019 43.8516 4.926 1.24e-05 ***
#as.factor(Quartile)2 -11.5897 11.3420 154.1400 -1.022 0.308
#as.factor(Quartile)3 -5.0381 11.2064 155.3822 -0.450 0.654
#as.factor(Quartile)4 -10.7821 10.8798 154.0820 -0.991 0.323
#Days:as.factor(Quartile)2 0.5676 2.1010 152.1491 0.270 0.787
#Days:as.factor(Quartile)3 0.2833 2.0660 155.5669 0.137 0.891
#Days:as.factor(Quartile)4 1.8639 2.1293 153.1315 0.875 0.383
#contrast
emmeans(model1, poly ~ Quartile*Days)$contrast
#contrast estimate SE df t.ratio p.value
# linear -1.91 18.78 149 -0.102 0.9191
# quadratic 10.40 8.48 152 1.227 0.2215
# cubic -18.21 18.94 150 -0.961 0.3379在本例中,线性对比度的p值与回归的交互作用不显著。是我做错了什么,还是预期到了这些结果?
发布于 2022-04-27 18:59:14
查看原始模型的emmeans()调用:
emmeans(regmemory, poly ~ QuartileConsumption * Age)这就要求我们获得QuartileConsumption和Age组合的边际均值,并从这些结果中得到多项式对比。Age似乎是一个定量变量,因此在计算边际均值时,我们只使用Age的平均值(参见ref_grid()和vignette("basics", "emmeans")的文档)。因此,未在OP中显示的边缘均值显示将以以下一般形式显示:
QuartileConsumption Age emmean
------------------------------------
1 <mean> <est1>
2 <mean> <est2>
3 <mean> <est3>
4 <mean> <est4>..。所显示的对比是这四种估计的线性、二次和三次趋势,按所示顺序排列。
请注意,这些边际均值与交互效应无关;如果我正确理解数据结构,它们只是从模型中预测的QuartileConsumption的平均Age水平(以及平均教育程度,平均健康分数)。因此,从本质上说,多项式对比估计了平均年龄的四水平因子的多项式趋势.特别要注意的是,age是固定不变的,所以我们肯定没有研究Age的任何影响。
我猜你们想要做的是评估年龄趋势在这个因素的四个层次上是如何变化的。如果是这样的话,一件有用的事情就是
slopes <- emtrends(regmemory, ~ QuartileConsumption, var = "age")
slopes # display the estimated slope at each level
pairs(slopes) # pairwise comparisons of these slopes请参阅vignette("interactions", "emmeans")和关于与协变量交互的一节。
https://stackoverflow.com/questions/72033135
复制相似问题