0
我有一个看起来像这样的数据:如何绘制R中lmer回归模型的估计值?
height <- c(1,2,3,4,2,4,6,8)
weight <- c(12,13,14,15,22,23,24,25)
type <- c("Wheat","Wheat","Wheat","Wheat","Rice","Rice","Rice","Rice")
set <- c(1,1,1,1,2,2,2,2)
dat <- data.frame(set,type,height,weight)
我运行集11聚物模型作为R中随机效应:
mod <- lmer(weight~height + type + (1|set), data = dat)
现在,我要绘制的模型的估计和在x轴和高度在y轴上绘制回归,具有重量,小刻面(〜型)
我使用预测函数如下
dat$pred <- predict(mod, type = "response")
我想达到ggplot,将是这样的:
ggplot(dat,aes(x = weight, y = height)) +
geom_point() + geom_smooth(method="lm", fill=NA) + facet_grid(~ type, scales = "free")
然而,我注意到,预测函数只具有单一的输出。我如何绘制以实现与上述相同?或者我必须存储两个不同的预测响应,然后将其插入ggplot的x,y?