我运行此回归:
mod <- lm(barthtot ~ c172code +c12hour* c161sex , efc)
pred <- predictions(mod, newdata = datagrid(c172code = unique , c12hour=unique,
c161sex = unique))
然后我生成了这个图:
ggplot(pred, aes(c12hour, barthtot, colour = c161sex )) + facet_wrap(~c172code )+
geom_line(position = position_dodge(0.2)) +
ggtitle("Predicted values of barthtot")
i试图使用
get_datagrid()
和
get_predicted()
函数重现相同的图:
library(easystats)
vizdata <- get_datagrid(efc, by = c("c12hour", "c161sex","c172code"))
vizdata$Predicted <- get_predicted(mod, vizdata)
ggplot(efc, aes(x = c12hour , y = barthtot, color =c161sex )) +
geom_line(data = vizdata, aes(y = Predicted), linewidth = 1) +facet_wrap(~c172code )
生产:
ggplot
作为y轴上的变量提供,但是从回归模型中的Thje预备值将其标记为the the the the the
barthot
estimate
取代您期望的情节:
pred
用Rreprexv2.1.1于2025-03-11创建