r - 为什么“digits”参数不影响 print(summary(fit)) 的输出?
问题描述
我从这里找到了解决方案。如果我运行该mtcars
示例,则会按预期显示数字。
但是当我使用Avertising 数据集和以下脚本时,该digits
参数没有任何效果:
path <- "path_to_adverising_csv/"
file <- "Advertising.csv"
filename <- paste0(path, file)
advertising <- read.csv(filename, header = TRUE)
names(advertising)
advertising_fit <- lm(sales~TV+radio+newspaper, data = advertising)
print(summary(advertising_fit), digits = 2)
输出:
Call:
lm(formula = sales ~ TV + radio + newspaper, data = advertising)
Residuals:
Min 1Q Median 3Q Max
-8.828 -0.891 0.242 1.189 2.829
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.93889 0.31191 9.42 <2e-16 ***
TV 0.04576 0.00139 32.81 <2e-16 ***
radio 0.18853 0.00861 21.89 <2e-16 ***
newspaper -0.00104 0.00587 -0.18 0.86
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.69 on 196 degrees of freedom
Multiple R-squared: 0.897, Adjusted R-squared: 0.896
F-statistic: 570 on 3 and 196 DF, p-value: <2e-16
我错过了一些明显的东西吗?
解决方案
在引擎盖下,这是调用很好地printCoefMat
打印系数矩阵。被传递给帮助状态的这个函数digits
数字用于大多数数字的最小有效数字数。
注意“大多数数字”。
查看源代码,这最终将调用format
一个向量,其中包含系数的舍入值绝对值及其标准误差,并传递相同的digits
参数值。
从帮助format
数字
数字和复数 x 将使用多少位有效数字。默认值 NULL 使用 getOption("digits")。这是一个建议:将使用足够的小数位,以便最小(数量级)的数字具有这么多有效数字,并满足 nsmall。(复数的解释见signif。)见signif。)
因此,因为您有足够的小数点来表示最小的系数及其标准误差,以便有足够的有效数字。
在这种情况下,它是 的系数newspaper
。
推荐阅读
- c++ - 程序正在使用 while 循环,不允许用户输入第一个问题的答案
- excel - 是否可以将 url 指定为 vba 中 saveAs() 函数的路径?
- django - 为什么不使用sync_to_async就不能使用AsyncClient登录?
- sql - 两个日期之间的差异或不适用
- javascript - 对虚拟 DOM 感到困惑
- python - VS Code 的“排序导入”失败并出现异常
- xcode - 从 v0.61.5 手动升级到 v0.63.3 后如何修复“找不到 ReactCommon/CallInvoker.h 文件”
- swift - SwiftUI ObservedObject 未在视图中更新
- ssas - 如何从成员函数中动态更改维度(在 MDX 中)
- java - 重试数据库连接 Dropwizard