为什么 "digits" 参数不影响 print(summary(fit)) 的输出?

Why does "digits" argument not affect output of print(summary(fit))?

我从 here 中找到了解决方案。如果我 运行 mtcars 示例,数字将按预期显示。
但是当我使用 Avertising dataset 和下面的脚本时, 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 传递给此函数,其中帮助说明

digits minimum number of significant digits to be used for most numbers.

备注'most numbers'。

查看源代码,这最终将在包含系数的舍入值绝对值及其标准误差的向量上调用 format,并传递相同的 digits 参数值。

来自 format

的帮助

digits

how many significant digits are to be used for numeric and complex x. The default, NULL, uses getOption("digits"). This is a suggestion: enough decimal places will be used so that the smallest (in magnitude) number has this many significant digits, and also to satisfy nsmall. (For the interpretation for complex numbers see signif.) see signif.)

因此,由于您有足够的小数点用于最小的系数及其标准误差,因此具有足够的有效数字。

在这种情况下,它是 newspaper 的系数。