Skip to content
Prev 295763 / 398502 Next

Customized R Regression Output?

Hello,
No, using paste/as.formula you can do it in a loop. Example:

x1 <- 1:100
x2 <- log(x1^2)

y1 <- x1 + x2 + rnorm(100)
y2 <- x1*runif(100, 0.5, 1.0) + x2 + rnorm(100)

predictors <- c("x1", "x2")
responses <- c("y1", "y2")

fmla <- paste(responses, paste(predictors, collapse="+"), sep="~")

model <- vector("list", length(fmla))
for(i in seq_along(fmla))
	model[[i]] <- lm(as.formula(fmla[i]))

summary(model[[1]])


As for making a table of results, something like

estimate <- coef(summary(model[[2]]))[, 1]
p.value <- coef(summary(model[[2]]))[, 4]
cbind(estimate, p.value)


Hope this helps,

Rui Barradas

Chris87 wrote
--
View this message in context: http://r.789695.n4.nabble.com/Customized-R-Regression-Output-tp4631497p4631503.html
Sent from the R help mailing list archive at Nabble.com.