[R] how to improve summary.lm

David Winsemius dwinsemius at comcast.net
Sun Aug 21 10:13:02 CEST 2011


On Aug 21, 2011, at 3:16 AM, Oliver Kullmann wrote:

> Hello,
>
> I need a shorter summary.lm, instead of
> --------------------------------------------
> Call:
> lm(formula = E$t ~ E$cfs)
>
> Residuals:
>       Min        1Q    Median        3Q       Max
> -0.239674 -0.007694  0.006430  0.014330  2.496551
>
> Coefficients:
>              Estimate Std. Error t value Pr(>|t|)
> (Intercept) -1.994e-02  1.419e-04  -140.5   <2e-16 ***
> E$cfs        1.675e-05  4.714e-09  3552.7   <2e-16 ***
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> Residual standard error: 0.03238 on 65268 degrees of freedom
> Multiple R-squared: 0.9949,     Adjusted R-squared: 0.9949
> F-statistic: 1.262e+07 on 1 and 65268 DF,  p-value: < 2.2e-16
> --------------------------------------------
>
> I need
>
> --------------------------------------------
> lm(formula = E$t ~ E$cfs)
>              Estimate Std. Error t value Pr(>|t|)
> (Intercept) -1.994e-02  1.419e-04  -140.5   <2e-16 ***
> E$cfs        1.675e-05  4.714e-09  3552.7   <2e-16 ***
> Multiple R-squared: 0.9949,     Adjusted R-squared: 0.9949
> --------------------------------------------
>
> I looked at the code of summary.lm, with the intention
> to copy parts of it into a new function "short_sum_lm",
> but couldn't find the parts I'm interested in.
>
> I hope it's not too complicated to achieve that.
> (In general it would be great to have more influence
> on the summary-function -- typically it's too spacious.)

When you simply type summary.lm there is an implicit call to  
print.summary.lm but its code is not visible unless you use  
getAnywhere(print.summary.lm ). Reading the code you find that the  
coefficient matrix and the significance stars are handled by a  
function , so this should give you what you want:

printCoefmat(summary(model)$coefficients)

-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list