Re: [R] Outreg-like command?

From: Richard M. Heiberger <rmh_at_temple.edu>
Date: Thu 04 May 2006 - 07:59:03 EST


I think this is what you are asking for. It would be relatively easy to package this into a function that takes a list of lm objects as its argument.

tmp <- data.frame(matrix(rnorm(100), 25, 4)) names(tmp) <- c("y","x1","x2","x3")

t1.lm <- lm(y ~ x1, data=tmp)
t2.lm <- lm(y ~ x2, data=tmp)
t3.lm <- lm(y ~ x3, data=tmp)
t12.lm <- lm(y ~ x1 + x2, data=tmp)

t13.lm <- lm(y ~ x1 + x3, data=tmp)
t23.lm <- lm(y ~ x2 + x3, data=tmp)
t123.lm <- lm(y ~ x1 + x2 +x3, data=tmp)
vars <- list(names(coef(t1.lm)),
             names(coef(t2.lm)),
             names(coef(t3.lm)),
             names(coef(t12.lm)),
             names(coef(t13.lm)),
             names(coef(t23.lm)),
             names(coef(t123.lm))
             )

outreg <- array(0, dim=c(7, length(unique(unlist(vars))),2),
                dimnames=list(
                  c(deparse(terms(t1.lm)),
                    deparse(terms(t2.lm)),
                    deparse(terms(t3.lm)),
                    deparse(terms(t12.lm)),
                    deparse(terms(t13.lm)),
                    deparse(terms(t23.lm)),
                    deparse(terms(t123.lm))),
                  unique(unlist(vars)),
                  c("coef","se")))

outreg[1, vars[[1]], ] <- coef(summary(t1.lm))  [vars[[1]], c("Estimate", "Std. Error")]
outreg[2, vars[[2]], ] <- coef(summary(t2.lm))  [vars[[2]], c("Estimate", "Std. Error")]
outreg[3, vars[[3]], ] <- coef(summary(t3.lm))  [vars[[3]], c("Estimate", "Std. Error")]
outreg[4, vars[[4]], ] <- coef(summary(t12.lm)) [vars[[4]], c("Estimate", "Std. Error")]
outreg[5, vars[[5]], ] <- coef(summary(t13.lm)) [vars[[5]], c("Estimate", "Std. Error")]
outreg[6, vars[[6]], ] <- coef(summary(t23.lm)) [vars[[6]], c("Estimate", "Std. Error")] outreg[7, vars[[7]], ] <- coef(summary(t123.lm))[vars[[7]], c("Estimate", "Std. Error")]

outreg



R-help@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 Received on Thu May 04 09:13:09 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 04 May 2006 - 12:09:57 EST.

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