[R] How to Package Extra Results to summary.lm

From: Matthew Dubins <matt.dubins_at_utoronto.ca>
Date: Fri, 21 Mar 2008 17:49:56 -0400

Dear R users,

I came up with some simple functions to give me the standard betas and tolerance values from a predefined lm() model. I have been trying to insert the results from these functions into the coefficients matrix in a modified summary.lm function that I'm calling summary2 (I'd never edit the summary.lm function directly!!). I managed to get the results inserted into the output, but a few things have changed: 1) Now instead of the Pr(>|t|) column being the only one to ever be expressed in scientific notation, the other columns (except for the new 'Tolerance' column) are also expressed in scientific notation, with 3 decimal places before the exponent value. 2) The stars that would previously indicate the significance of the coefficients no longer show up, and neither does the legend that explains the stars on the bottom. 3) I get a warning message at the bottom of the output saying the following:

"Warning message:
In cbind(betas, est, se, tval, 2 * pt(abs(tval), rdf, lower.tail = FALSE), :
  number of rows of result is not a multiple of vector length (arg 1)"

In order to give you a 'paper trail', following are the new functions I defined, the url linking you to my summary2 script and a dataset I've been using to test the summary function, and the regression results from using summary2 on this dataset:

std.betas = function(mod)


        coefs = coef(mod)
        sds = sd(mod$model[,2:length(names(mod$model))])
        sd.Y = sd(mod$model[,1])
        coefs.in.sds = coefs[2:length(coefs)]/sd.Y
        std.betas = coefs.in.sds / (1/sds)


tolerance = function(model) # Dependent on car package



http://www.utsc.utoronto.ca/~mdubins/summary2.R http://www.utsc.utoronto.ca/~mdubins/Tab15-1.dat

> summary2(b)

lm(formula = Overall ~ Teach + Exam + Knowledge + Grade + Enroll)


     Min 1Q Median 3Q Max -0.69991 -0.16245 0.01669 0.20511 0.82464


            Std.Estimate Estimate Std. Error t value Pr(>|t|) Tolerance
(Intercept) 6.620e-01 -1.195e+00 6.312e-01 -1.893e+00 6.494e-02 0.418
Teach 1.061e-01 7.632e-01 1.329e-01 5.742e+00 8.068e-07 0.325
Exam 3.251e-01 1.320e-01 1.628e-01 8.107e-01 4.219e-01 0.675
Knowledge -1.055e-01 4.890e-01 1.365e-01 3.581e+00 8.491e-04 0.620
Grade 1.242e-01 -1.843e-01 1.655e-01 -1.114e+00 2.715e-01 0.653
Enroll 6.620e-01 5.255e-04 3.901e-04 1.347e+00 1.848e-01 0.418

Residual standard error: 0.3202 on 44 degrees of freedom Multiple R-squared: 0.7554, Adjusted R-squared: 0.7277 F-statistic: 27.18 on 5 and 44 DF, p-value: 1.979e-12

Warning message:
In cbind(betas, est, se, tval, 2 * pt(abs(tval), rdf, lower.tail = FALSE), :
  number of rows of result is not a multiple of vector length (arg 1)

All I want is to have the extra Std.Estimate and Tolerance columns without changing anything else in the regression output. Any help is appreciated!

Matthew Dubins

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 21 Mar 2008 - 21:52:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 21 Mar 2008 - 22:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive