【发布时间】:2023-03-21 06:24:01
【问题描述】:
受到文档中linear models example 的启发,我想在运行lm 命令后打印一个漂亮的摘要。
当我运行时(见示例中的最后一行)
print(base.summary(stats.lm('foo ~ bar'))
我得到一个完整的函数列表,开头如下:
Call:
(function (formula, data, subset, weights, na.action, method = "qr",
model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok = TRUE,
contrasts = NULL, offset, ...)
{
ret.x <- x
ret.y <- y
cl <- match.call()
mf <- match.call(expand.dots = FALSE)
底部有所需的R 输出:
Coefficients:
Estimate Std. Error t value Pr(>|t|)
foo 5.0320 0.2202 22.85 9.55e-15 ***
bar 4.6610 0.2202 21.16 3.62e-14 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.6964 on 18 degrees of freedom
Multiple R-squared: 0.9818, Adjusted R-squared: 0.9798
F-statistic: 485.1 on 2 and 18 DF, p-value: < 2.2e-16
这有一定的问题,但当提供给lm 的数据是pandas.DataFrame 时变得不可行,因为base.summary 似乎想要打印所有数据。
有没有办法在pd.DataFrame 中获得格式良好的R 输出而不需要所有额外的gubbins?
【问题讨论】:
-
broomR 中的包?? -
@Metrics 这看起来是个不错的选择。如果这个问题能让我了解
rpy2的情况,那就太好了。比如,我如何明确地处理来自lm的返回类型?