Dimitri Szerman
2007-Apr-06 00:34 UTC
[R] lm() intercept at the end, rather than at the beginning
Hi, I wonder if someone has already figured out a way of making summary(mylm) # where mylm is an object of the class lm() to print the "(Intercept)" at the last line, rather than the first line of the output. I don't know about, say, biostatistics, but in economics the intercept is usually the least interesting of the parameters of a regression model. That's why, say, Stata prints by default the intercept at the end. Just a suggestion for R-developers... Thanks, Dimitri
Gabor Grothendieck
2007-Apr-06 01:26 UTC
[R] lm() intercept at the end, rather than at the beginning
Try this. It captures the output of x and sets idx to the line numbers of the coefficients, rearranging their order in the next line and printing them out in the line after that. my.print.summary.lm <- function(x, ...) { out <- capture.output(x) idx <- seq(grep("Intercept", out), grep("---", out)-1) out[idx] <- out[c(idx[-1], idx[1])] for(lin in replace(out, idx, out[rev(idx)])) cat(lin, "\n") invisible(x) } z <- summary(lm(conc ~ uptake, CO2)) my.print.summary.lm(z) On 4/5/07, Dimitri Szerman <dimitrijoe at gmail.com> wrote:> Hi, > > I wonder if someone has already figured out a way of making > > summary(mylm) # where mylm is an object of the class lm() > > to print the "(Intercept)" at the last line, rather than the first > line of the output. I don't know about, say, biostatistics, but in > economics the intercept is usually the least interesting of the > parameters of a regression model. That's why, say, Stata prints by > default the intercept at the end. Just a suggestion for > R-developers... > > Thanks, > Dimitri > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
Greg Snow
2007-Apr-09 14:53 UTC
[R] lm() intercept at the end, rather than at the beginning
Gabor has already showed you one way to make your own summary function that does this. I want to address a different aspect of your question. Your question implies that less interesting things belong at the bottom of the summary output. On the other hand, when I was teaching full time I tried to convince my students that the summary output for lm models (and others) should be read from the bottom up (and to some degree from right to left). After all, you really should not be looking at the p-values for the individual coefficients until after you look at the overall F-test p-value (at the very bottom), and you should not try to interpret the coefficient values until you have looked at their standard errors (and possibly p-values). Anything that I want to know about the residuals I learn from the diagnostic plots, not the 5 number summary that is at the top of the output (I am not arguing for that to go away, others may find it more useful than I do, and I do occasionally look at it, but it seems least important of the output). If your model includes interactions and/or polynomial terms, then these should be looked at before the main effects and linear terms (and the genererally are below their corresponding main effects/linear terms). And looking at the sequential test from the anova function when given only 1 model really only makes sense reading from the bottom up. So, if you think in those terms (and I like it staying that way, with a scrolling computer screen, reading from the bottom up is quicker and easier), then having the uninteresting intercept at the top of the list of the coefficients is the best place for it. Just a couple of thougts, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Dimitri Szerman > Sent: Thursday, April 05, 2007 6:34 PM > To: R-Help > Subject: [R] lm() intercept at the end, rather than at the beginning > > Hi, > > I wonder if someone has already figured out a way of making > > summary(mylm) # where mylm is an object of the class lm() > > to print the "(Intercept)" at the last line, rather than the > first line of the output. I don't know about, say, > biostatistics, but in economics the intercept is usually the > least interesting of the parameters of a regression model. > That's why, say, Stata prints by default the intercept at the > end. Just a suggestion for R-developers... > > Thanks, > Dimitri > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >