[R] Customized R Regression Output?
Rui Barradas
ruipbarradas at sapo.pt
Sun May 27 15:43:23 CEST 2012
Hello,
>
> Do I really have to type in each single regression for each data set and
> copy the output into a table manually?
>
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
>
> Hello R-Experts,
>
> I am facing the problem that I have to estimate several parameters for a
> lot of different dependent variables.
>
> One single regression looks something like this:
>
> y = beta0 + beta1 * x1 + beta2 * x2 + beta3 * x1 * x2 + beta4 * x4 + beta5
> * lag(x4,-1)
>
> where y is the dependent variable and xi are the independent ones.
> Important to me are the different estimates of betai and their respective
> p-values only. Now I have aprx. 50 different data sets of y and x1 to x4.
> So for each data set I need the respective estimators and their p-values.
> Do I really have to type in each single regression for each data set and
> copy the output into a table manually?
>
> Isn't it possible to get an efficient output like the following?
>
> beta0(data set 1) | P-Value(beta0, data set 1) | beta1(data set 1) |
> P-Value(beta1, data set 1)| .... | P-Value(beta5, data set n)
>
>
> Or at least getting a vector with all the estimates of beta0 for each data
> set, another vector with all estimates of beta1 for each data set, and a
> matrix with P-values for each betai of each data set?
>
> The file containing the observations for xi and y for each set of data can
> be adjusted to any kind of format.
>
> Thank you very much in advance.
>
> With kind regards
> Christian
>
--
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.
More information about the R-help
mailing list