混合效应模型中的负预测系数在ggplot2中产生正斜率

时间:2017-03-14 21:57:25

标签: r ggplot2 linear-regression lme4 mixed-models

我使用lmer() lme4包中的R函数为实验数据拟合了混合效应回归模型。

require(lme4)

mod = lmer(y ~ x1 + x2 + x3 + (x1|re1) + (x1|re2), data = dat, REML = FALSE)

summary(mod)

Fixed effects:
                   Estimate   Std. Error     df     t value  Pr(>|t|)    
(Intercept)       7.008e+00   3.318e-02  4.850e+01  211.166  < 2e-16 ***
x1                -6.686e-02  2.028e-02  3.400e+01  -3.297   0.00229 ** 
x2                -4.357e-02  1.313e-02  4.870e+01  -3.318   0.00172 ** 
x3                -5.302e-03  1.373e-02  7.110e+01  -0.386   0.70054    

请注意,感兴趣的预测变量x1具有负系数,因此我预计当感兴趣的预测变量增加时,因变量会减少。

为了可视化模型预测,我使用predict()函数生成了模型预测。

dat$preds = predict(mod, dat, type = "response")

然后,我使用ggplot2包将这些预测与感兴趣的预测器进行了对比。

require(ggplot2)

ggplot(dat, aes(x=x1, y=preds)) +
  geom_point(shape=16, cex=1) +
  geom_smooth(method=lm) +
  xlab("x1") + ylab("predicted y") +
  theme(axis.title=element_text(size=26), axis.text=element_text(size=16))

plot of model predictions y' as a function of variable of interest x1

我惊讶地发现功能的斜率是正的。但是,如果模型中预测因子的系数为负,那怎么可能呢?我的代码中是否有一些错误,或者我将x1的估计解释为负斜率是错误的?

0 个答案:

没有答案