在多时隙中按幅度对系数进行排序

时间:2016-10-23 01:22:29

标签: r coefplot

Previous question询问如何在coefplot中按降序绘制系数。答案是包括sort = 'magnitude'

然而,我发现使用multiplot绘制多个模型时此方法不起作用:

data(tips, package = "reshape2")
mod1 <- lm(tip ~ day + sex + smoker, data = tips)
mod2 <- lm(tip ~ day + sex + smoker + size, data = tips)
multiplot(mod1, mod2, decreasing = TRUE, sort = "magnitude")

有没有办法用multiplot执行此操作?我意识到这可能不是直截了当的。我只是想知道我是否遗漏了什么。

1 个答案:

答案 0 :(得分:3)

我不知道如何使用coefplot()执行此操作,但我可以提供类似dotwhisker包的解决方案:

适合模特:

data(tips, package = "reshape2")
mod1 <- lm(tip ~ day + sex + smoker, data = tips)
mod2 <- lm(tip ~ day + sex + smoker + size, data = tips)

library(dotwhisker)
## figure out order
ov <- names(sort(coef(mod2),decreasing=TRUE))
dwplot(list(mod1=mod1,mod2=mod2),order_vars=ov)+
    theme_bw()+
    geom_vline(xintercept=0,lty=2)

enter image description here