【问题标题】:control the digit display of fit summary after regression控制回归后拟合汇总的位数显示
【发布时间】:2014-03-27 06:49:59
【问题描述】:

如何控制summary(fit) 的数字显示,现在它显示的小数点后数字太多了。尝试使用options(digits=3),但它不起作用

> fit <- lm(y ~ x1 + x2 + x3)
> summary(fit) # show results

【问题讨论】:

    标签: r


    【解决方案1】:
    fit <- lm(mpg~wt,mtcars)
    print(summary(fit),digits=2)
    
    # Call:
    # lm(formula = mpg ~ wt, data = mtcars)
    
    # Residuals:
    #    Min     1Q Median     3Q    Max 
    #  -4.54  -2.36  -0.13   1.41   6.87 
    
    # Coefficients:
    #             Estimate Std. Error t value Pr(>|t|)    
    # (Intercept)    37.29       1.88    19.9   <2e-16 ***
    # wt             -5.34       0.56    -9.6    1e-10 ***
    # ---
    # Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
    
    # Residual standard error: 3 on 30 degrees of freedom
    # Multiple R-squared:  0.75,    Adjusted R-squared:  0.74 
    # F-statistic:  91 on 1 and 30 DF,  p-value: 1.3e-10
    

    【讨论】:

    • 有没有办法只使用系数矩阵来完成这项工作?
    • print(summary(fit)$coefficients,digits=2)print(coefficients(summary(fit)),digits=2)
    • 啊。谢谢。我认为在将 Rmd 文件编译为 HTML 时无法使其正常工作,但仅在 R 中运行代码时,它显然适用于系数矩阵。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-09
    • 1970-01-01
    • 2018-05-11
    • 2023-01-15
    • 2011-05-20
    • 2021-11-18
    相关资源
    最近更新 更多