如何在一个图中绘制不同模型的估计值
How to plot estimates from different models in one plot
我正在对两种不同的药物执行线性混合效应。我使用对比语句来确定时间的影响。
我正在尝试在一个图中绘制来自不同模型的估计值。
这是模型 1
的输出
confint(model1)
Estimate lwr upr
1 == 0 2.969735 -1.846697 5.786166
2 == 0 4.163577 0.646791 5.680363
3 == 0 2.193842 -3.377740 5.765425
模型 2 的输出
Linear Hypotheses:
Estimate lwr upr
1 == 0 65.0877 60.5934 65.5820
2 == 0 65.8362 62.9191 65.7532
3 == 0 0.9484 -4.6095 6.1064
我正在尝试绘制
模型 1(3 == 0 2.193842 -3.377740 5.765425) 和模型 2(3 == 0 0.9484 -4.6095 6.1064) 在一个图中的估计和 CI
你怎么做到的?
不清楚您正在创建什么类型的模型对象。
我建议使用 broom 包来创建估计数据框并将它们绑定在一起。
library(tidyverse)
lm1 <- lm(mpg ~ disp + hp, data = mtcars)
lm2 <- lm(Sepal.Length ~ Petal.Width + Species, data = iris)
bind_rows(
broom::tidy(lm1),
broom::tidy(lm2)
) %>%
ggplot(aes(x = term, y = estimate)) +
geom_point() +
coord_flip()
@thus__的回答很好。你可以使用 dotwhisker
包更轻松地做到这一点(尽管在你想要更多控制的情况下,了解手册 tidy
+combine 是很好的)。
设置模型:
library(lme4)
m1 <- lmer(Reaction~Days+(Days|Subject),sleepstudy)
m2 <- update(m1, . ~ . + I(Days^2))
剧情:
library(broom.mixed)
library(dotwhisker)
dwplot(list(m1,m2),effects="fixed")
我正在对两种不同的药物执行线性混合效应。我使用对比语句来确定时间的影响。
我正在尝试在一个图中绘制来自不同模型的估计值。 这是模型 1
的输出confint(model1)
Estimate lwr upr
1 == 0 2.969735 -1.846697 5.786166
2 == 0 4.163577 0.646791 5.680363
3 == 0 2.193842 -3.377740 5.765425
模型 2 的输出
Linear Hypotheses:
Estimate lwr upr
1 == 0 65.0877 60.5934 65.5820
2 == 0 65.8362 62.9191 65.7532
3 == 0 0.9484 -4.6095 6.1064
我正在尝试绘制 模型 1(3 == 0 2.193842 -3.377740 5.765425) 和模型 2(3 == 0 0.9484 -4.6095 6.1064) 在一个图中的估计和 CI 你怎么做到的?
不清楚您正在创建什么类型的模型对象。
我建议使用 broom 包来创建估计数据框并将它们绑定在一起。
library(tidyverse)
lm1 <- lm(mpg ~ disp + hp, data = mtcars)
lm2 <- lm(Sepal.Length ~ Petal.Width + Species, data = iris)
bind_rows(
broom::tidy(lm1),
broom::tidy(lm2)
) %>%
ggplot(aes(x = term, y = estimate)) +
geom_point() +
coord_flip()
@thus__的回答很好。你可以使用 dotwhisker
包更轻松地做到这一点(尽管在你想要更多控制的情况下,了解手册 tidy
+combine 是很好的)。
设置模型:
library(lme4)
m1 <- lmer(Reaction~Days+(Days|Subject),sleepstudy)
m2 <- update(m1, . ~ . + I(Days^2))
剧情:
library(broom.mixed)
library(dotwhisker)
dwplot(list(m1,m2),effects="fixed")