create data frame with coefficients from many regressions

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

create data frame with coefficients from many regressions

iza.ch1
Hi !

I want to ask if somebody knows the way to create data frame with coefficients from many regressions
I regress the first column from ret against the first columns from median, then the second with the second and so on.
This is the code used for regression

i<-1:6
lapply(seq_len(ncol(ret)),function(i) {lm(ret[,i]~median[,i])}

I get 6 results for each regression

[[1]]

Call:
lm(formula = ret[, i] ~ median[, i])

Coefficients:
(Intercept)  median[, i]  
          0            1  


[[2]]

Call:
lm(formula = ret[, i] ~ median[, i])

Coefficients:
(Intercept)  median[, i]  
-1.411e-17    1.000e+00

now I would like to create a data frame with intercepts which looks like it

                        [[1]]          [[2]]
Intercept
median

I tried to use ddply command but it does not work. I will be very grateful for the hint :)

Thank you in advance

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Re: create data frame with coefficients from many regressions

Bastian Offermann


summary(lm(y ~ x))$coef[1,]

gives you the intercept, standard error, p-value etc.

then write a function and use lapply( yourlist, function)

Am 2013-07-22 1:54 PM, schrieb iza.ch1:

> Hi !
>
> I want to ask if somebody knows the way to create data frame with coefficients from many regressions
> I regress the first column from ret against the first columns from median, then the second with the second and so on.
> This is the code used for regression
>
> i<-1:6
> lapply(seq_len(ncol(ret)),function(i) {lm(ret[,i]~median[,i])}
>
> I get 6 results for each regression
>
> [[1]]
>
> Call:
> lm(formula = ret[, i] ~ median[, i])
>
> Coefficients:
> (Intercept)  median[, i]
>            0            1
>
>
> [[2]]
>
> Call:
> lm(formula = ret[, i] ~ median[, i])
>
> Coefficients:
> (Intercept)  median[, i]
> -1.411e-17    1.000e+00
>
> now I would like to create a data frame with intercepts which looks like it
>
>                          [[1]]          [[2]]
> Intercept
> median
>
> I tried to use ddply command but it does not work. I will be very grateful for the hint :)
>
> Thank you in advance
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
>

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Re: create data frame with coefficients from many regressions

Jeffrey Ryan
In reply to this post by iza.ch1
The results of an lapply call can be joined together easily with do.call(cbind or do.call(rbind or do.call(c. Though what you need is probably requiring one additional step to use a custom function to get the result you want in some sensible structure for the above.

This isn't at all a finance question though. Should be redirected to r-help.

Thanks
Jeff

Jeffrey Ryan    |    Founder    |    [hidden email]

www.lemnica.com

On Jul 22, 2013, at 12:54 PM, "iza.ch1" <[hidden email]> wrote:

> Hi !
>
> I want to ask if somebody knows the way to create data frame with coefficients from many regressions
> I regress the first column from ret against the first columns from median, then the second with the second and so on.
> This is the code used for regression
>
> i<-1:6
> lapply(seq_len(ncol(ret)),function(i) {lm(ret[,i]~median[,i])}
>
> I get 6 results for each regression
>
> [[1]]
>
> Call:
> lm(formula = ret[, i] ~ median[, i])
>
> Coefficients:
> (Intercept)  median[, i]  
>          0            1  
>
>
> [[2]]
>
> Call:
> lm(formula = ret[, i] ~ median[, i])
>
> Coefficients:
> (Intercept)  median[, i]  
> -1.411e-17    1.000e+00
>
> now I would like to create a data frame with intercepts which looks like it
>
>                        [[1]]          [[2]]
> Intercept
> median
>
> I tried to use ddply command but it does not work. I will be very grateful for the hint :)
>
> Thank you in advance
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.