GGPLOT基于predivions(),get_datagrid()和get_predicated()函数

问题描述 投票:0回答:1

我运行此回归:

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 )
生产:

theet,这与第一个不同。 1 在您的第一个调用中,您可以将

ggplot

作为y轴上的变量提供,但是从回归模型中的Thje预备值将其标记为the the the the the

barthot
r database ggplot2 r-marginaleffects
1个回答
0
投票
estimate

取代您期望的情节:

pred

用Rreprexv2.1.1
于2025-03-11创建
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.