gpt4 book ai didi

在 R 中复制 Stata 边距

转载 作者:行者123 更新时间:2023-12-04 00:07:09 26 4
gpt4 key购买 nike

我有一个回归模型,其中包含一堆与回归变量交互的指标变量。在这种情况下,P 值可能适用于模型选择。我知道 Stata 有一个名为 margins 的命令,在这种情况下它真的很有帮助。示例:

margins, dydx(*)

来自 relevant Stata manual

Description

Margins are statistics calculated from predictions of a previously fit model at fixed values of some covariates and averaging or otherwise integrating over the remaining covariates. The margins command estimates margins of responses for specified values of covariates and presents the results as a table. Capabilities include estimated marginal means, least-squares means, average and conditional marginal and partial effects (which may be reported as derivatives or as elasticities), average and conditional adjusted predictions, and predictive margins.

R中有没有类似的功能?

最佳答案

我制作了一个 R 端口的 Stata 边距命令,称为 - 直观地说 - margins .行为是您可能期望的:

library("margins")
x <- lm(mpg ~ cyl * hp + wt, data = mtcars)
summary(margins(x))
## factor AME SE z p lower upper
## cyl 0.0381 0.5999 0.0636 0.9493 -1.1376 1.2139
## hp -0.0463 0.0145 -3.1909 0.0014 -0.0748 -0.0179
## wt -3.1198 0.6613 -4.7176 0.0000 -4.4160 -1.8236

与Stata相比:

quietly reg mpg c.cyl##c.hp wt
margins, dydx(*)
------------------------------------------------------------------------------
| Delta-method
| dy/dx Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
cyl | .0381376 .5998897 0.06 0.950 -1.192735 1.26901
hp | -.0463187 .014516 -3.19 0.004 -.076103 -.0165343
wt | -3.119815 .661322 -4.72 0.000 -4.476736 -1.762894
------------------------------------------------------------------------------

关于在 R 中复制 Stata 边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36605570/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com