[R] understanding print.summary.lm and perhaps print/show in general

Paul Bailey paul.bailey at alumni.grinnell.edu
Fri Mar 9 15:34:00 CET 2007


I'm trying to understand how R prints summary.lm objects and
trying to change it slightly for a summary function that
calculates standard errors using an alternative method.

I've found that I can modify a summary.lm object and then it
prints the modified way but I want to change a few things in
the print method that I think I might just be able to do. One
is that I want the coefficients table to print a different
header (other than "Std. Error"). I've tried changing the
column name of the summary$coef matrix and this works for
calls to printCoefmat but it still prints out "Std. Error"
when I pass  the summary.lm to the command line by itself. I
don't understand this behavior. When I do this (enter an
object on the command line by itself), does it then calls the
print / show method associated with that objects class, in
this case, summary.lm? Below is some sample code to reproduce
the behavior I don't understand and a comment regarding the
result I don't understand.

Cheers,
Paul

#####
lma <- lm(dist ~ speed, data=cars)
suma <- summary(lma)
colnames(suma$coef) <- c(LETTERS[1:4])
printCoefmat(suma$coef) # prints what I expect
suma
# the above is the print behavior question regards,
# why does the coefficients matrix have in its header
# the usual "Estimate Std. Error t value Pr(>|t|)"
# I expect "A B C D" as above in the call to printCoefmat



More information about the R-help mailing list