运行“保证金”的错误r的功能

发布于 2025-01-23 07:47:54 字数 1490 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

是你 2025-01-30 07:47:54

我怀疑该错误是在此行中:

mean(study_hours:courses_taken)

通常,r中的对象名称不包括结肠,所以我想您不能卑鄙。

从总的来说,我会注意到保证金软件包在许多情况下都可以很好地发挥作用,但是它并未积极开发。您可以尝试较新的marginaleffects package )。该软件包允许您以平均值计算边际效应(

library(marginaleffects)
mod <- lm(mpg ~ ., data = mtcars)
mfx <- marginaleffects(mod, newdata = datagrid())
summary(mfx)
#> Average marginal effects 
#>    Term   Effect Std. Error z value Pr(>|z|)    2.5 %   97.5 %
#> 1   cyl -0.11144    1.04502 -0.1066 0.915075 -2.15964  1.93676
#> 2  disp  0.01334    0.01786  0.7468 0.455209 -0.02166  0.04834
#> 3    hp -0.02148    0.02177 -0.9868 0.323717 -0.06415  0.02118
#> 4  drat  0.78711    1.63537  0.4813 0.630301 -2.41816  3.99238
#> 5    wt -3.71530    1.89441 -1.9612 0.049857 -7.42829 -0.00232
#> 6  qsec  0.82104    0.73083  1.1234 0.261255 -0.61137  2.25345
#> 7    vs  0.31776    2.10451  0.1510 0.879982 -3.80700  4.44252
#> 8    am  2.52023    2.05665  1.2254 0.220423 -1.51073  6.55119
#> 9  gear  0.65541    1.49326  0.4389 0.660724 -2.27132  3.58215
#> 10 carb -0.19942    0.82875 -0.2406 0.809845 -1.82374  1.42491
#> 
#> Model type:  lm 
#> Prediction type:  response

I suspect that the error is in this line:

mean(study_hours:courses_taken)

Typically, object names in R do not include colons, so I imagine that you can’t take the mean.

In passing, I’ll note that the margins package works great in many cases, but that it is not actively being developed. You could try the newer marginaleffects package (disclaimer: I am the author). That package allows you to compute marginal effects at the mean (documentation) easily by typing:

library(marginaleffects)
mod <- lm(mpg ~ ., data = mtcars)
mfx <- marginaleffects(mod, newdata = datagrid())
summary(mfx)
#> Average marginal effects 
#>    Term   Effect Std. Error z value Pr(>|z|)    2.5 %   97.5 %
#> 1   cyl -0.11144    1.04502 -0.1066 0.915075 -2.15964  1.93676
#> 2  disp  0.01334    0.01786  0.7468 0.455209 -0.02166  0.04834
#> 3    hp -0.02148    0.02177 -0.9868 0.323717 -0.06415  0.02118
#> 4  drat  0.78711    1.63537  0.4813 0.630301 -2.41816  3.99238
#> 5    wt -3.71530    1.89441 -1.9612 0.049857 -7.42829 -0.00232
#> 6  qsec  0.82104    0.73083  1.1234 0.261255 -0.61137  2.25345
#> 7    vs  0.31776    2.10451  0.1510 0.879982 -3.80700  4.44252
#> 8    am  2.52023    2.05665  1.2254 0.220423 -1.51073  6.55119
#> 9  gear  0.65541    1.49326  0.4389 0.660724 -2.27132  3.58215
#> 10 carb -0.19942    0.82875 -0.2406 0.809845 -1.82374  1.42491
#> 
#> Model type:  lm 
#> Prediction type:  response
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文