Rooz
Rooz

Reputation:

Creating a matrix of summary output

How can I insert summary outputs from multiple regression analyses in a matrix type variable in R statistics package?

Here is my script, which runs the regression and collect intercepts and co-eff in a variable:

for (i in 2:(ncol(data.base)))     {
  Test <- lm(data.base[,i] ~ log(database$var.1))
      results <- rbind(results, c(Test$coefficients))
}

I would like to do is to import summary(lm-test) for each regression in to a matrix type variable. I assume the matrix type variable is what I need.

I appreciate your help.

Upvotes: 0

Views: 2003

Answers (1)

AdamO
AdamO

Reputation: 4930

Yuck! Some nasty variable naming there, in my opinion.

I see data.base has outcomes, and you don't want the first column but each is a separate outcome. You also have database which is a data.frame with a variable var.1. Run each regression, store them in a matrix format.

This is a start:

fits <- apply(data.base[, -1], 2, function(y) lm(y ~ log(database$var.1))
summ <- lapply(fits, summary)
summ <- lapply(fits, coef)
Reduce(cbind, summ)

Upvotes: 2

Related Questions