[R] Outreg-like command?
Richard M. Heiberger
rmh at temple.edu
Wed May 3 23:59:03 CEST 2006
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
More information about the R-help
mailing list