[R] lm() intercept at the end, rather than at the beginning
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Apr 6 03:26:14 CEST 2007
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.
>
More information about the R-help
mailing list