Hello,

Actually, Bert is right, c() seems better. Chris wants a table with one row per dataset and columns like he wrote in a previous post.
Something like this could do it.

#------------------------ this was already posted
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]))

#------------------------ make the table
nr <- length(model)
nc <- nrow(coef(summary(model[[1]])))
tbl <- matrix(nrow=nr, ncol=2*nc + 1, dimnames=list(seq_len(nr), seq_len(2*nc + 1)))
for(i in seq_along(model)){
    smry <- summary(model[[i]])
    tbl[i, ] <- c(t(coef(smry)[ , c(1, 4)]), smry$r.squared)  # uses c()
}
colnames(tbl)[2*1:nc - 1] <- rownames(coef(smry))
colnames(tbl)[2*1:nc] <- paste("p.value", 0:(nc - 1), sep=".") # see below
colnames(tbl)[2*nc + 1] <- "R2"
tbl


If the only purpose is a printout, I would skip the 'paste', it would be obvious which regressor the p.value corresponds to. But if the matrix is to be used for other ends, duplicate names are a bad idea.

Rui Barradas


Em 27-05-2012 19:55, Özgür Asar escreveu:
Dear Bert Gunter,

Doesn't the summary(lm1)$coef have a matrix form? Then, while working with
columns of a matrix, can't one use c/rbind functions?

But list seem to better for what Chris asked. Nonetheless, c does not.

Best
Ozgur

-----
************************************
Ozgur ASAR

Research Assistant
Middle East Technical University
Department of Statistics
06531, Ankara Turkey
Ph: 90-312-2105309
http://www.stat.metu.edu.tr/people/assistants/ozgur/
--
View this message in context: 
http://r.789695.n4.nabble.com/Customized-R-Regression-Output-tp4631497p4631531.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org 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.

______________________________________________
R-help@r-project.org 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.

Reply via email to