【问题标题】:Stata plot in R/Python [closed]R / Python中的Stata图[关闭]
【发布时间】:2021-10-30 19:50:20
【问题描述】:

R 中的以下绘图使用了哪个函数? 至少在我看来它是一个预定义的函数。

编辑:好吧,根据 Claudio,它似乎是 Stata。

新问题: python/R中是否有任何可比的东西来获得这个输出? 如何计算系数?这是什么系数?

【问题讨论】:

  • 无:这是 Stata 标准输出,而不是 R。或者您的问题是“如何在 R 中获得类似的输出”?
  • 啊,好吧。我不知道它是Stata。 R/Python 中是否有类似的输出?
  • 看起来像 Stata。
  • 如果您在 R 中构建回归模型,然后使用summary(model_name),您将获得此处所示的大部分输出。

标签: python r statistics stata


【解决方案1】:

您可以使用pystata 包,它允许您在 Python 环境中运行 stata。可以从here下载

【讨论】:

  • 它不是 coefplot。这只是一个简单的线性回归,使用regress 命令运行
  • @C.Robin 感谢您的评论。我编辑了答案
【解决方案2】:

我们可以在 R 中使用lm() 获得相同的信息,并结合broomkable 获得表格:

model <- lm(mpg ~ disp + qsec, data=mtcars)
summary(model) # show results

coefficients(model) # model coefficients
confint(model, level=0.95) # CIs for model parameters
fitted(model) # predicted values
residuals(model) # residuals
anova(model) # anova table
vcov(model) # covariance matrix for model parameters
influence(model) # regression diagnostics


Combining with:
library(broom) # for tidy()
library(knitr) # for kable()

out <- tidy(model)
out1 <- tidy(anova(model))
kable(out1)
kable(out)

输出:

|term      | df|     sumsq|    meansq|  statistic|   p.value|
|:---------|--:|---------:|---------:|----------:|---------:|
|disp      |  1| 808.88850| 808.88850| 74.8166388| 0.0000000|
|qsec      |  1|   3.62193|   3.62193|  0.3350037| 0.5671961|
|Residuals | 29| 313.53676|  10.81161|         NA|        NA|
> kable(out)


|term        |   estimate| std.error|  statistic|   p.value|
|:-----------|----------:|---------:|----------:|---------:|
|(Intercept) | 25.5045079| 7.1840940|  3.5501356| 0.0013359|
|disp        | -0.0398877| 0.0052882| -7.5428272| 0.0000000|
|qsec        |  0.2122880| 0.3667758|  0.5787951| 0.5671961|

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-18
    • 1970-01-01
    • 2019-05-04
    • 1970-01-01
    相关资源
    最近更新 更多