【发布时间】:2018-12-23 23:18:29
【问题描述】:
我从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
我错过了一些明显的东西吗?
【问题讨论】:
-
我尝试使用 digits=2、1 和 0 并且输出发生了变化。但实际上它并不会在每个数字上都发生变化。奇怪的行为。
-
更多,当你看
?summary.lm时,digits应该是有效位数,就像你使用signif()时一样,但在fat中它是小数位数,就像你使用@时一样987654329@ -
我怀疑它默认打印的位数超过了指定的位数,因为您的
TV和newspaper变量的影响非常小/小数点后包含零。如果您仅使用radio作为解释变量来估计模型,digits = 2将按预期工作