[R-SIG-Finance] create data frame with coefficients from many regressions

Bastian Offermann bastian2507hk at yahoo.co.uk
Mon Jul 22 20:28:26 CEST 2013



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
>
> _______________________________________________
> R-SIG-Finance at r-project.org 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.
>



More information about the R-SIG-Finance mailing list