[R] Organize regression output

Michael Dewey lists at dewey.myzen.co.uk
Sat Dec 10 10:49:29 CET 2016


Dear Francesca

i usually do this by collecting the models into a list not a vector

model <- list(ra = ra, rb = rb, and so on

and then I use lapply or sapply to process the model

lapply(mode, function(x) coef(x)[1])

or something like that, not tested

On 10/12/2016 07:32, francesca Pancotto wrote:
> Dear Contributors
>
> I would like to ask some help concerning the automatization process of an analysis, that sounds hard to my knowledge.
> I have a list of regression models.
> I call them models=c(ra,rb,rc,rd,re,rf,rg,rh)
>
> I can access the output of each of them using for example, for the first
>
> ra$coefficients
>
> and i obtain
>
> (Intercept)       coeff1          coeff2            age      		gender
>  0.62003033  0.00350807 -0.03817848 -0.01513533 -0.18668972
> and I know that ra$coefficients[1] would give me the intercept of this model.
>
> What i need to do is to collect the coefficients of each regression in models, and calculate and place in a table, the following simple summation:
>
>
> ra						rb	 						rc      ...
>
> intercept					intercept					intercept
> intercept+coeff1			intercept+coeff1			intercept+coeff1
> intercept+coeff2			intercept+coeff2			intercept+coeff2
> intercept+coeff1+coeff2		intercept+coeff1+coeff2		intercept+coeff1+coeff2
>
>
> The calculations are trivial(I know how to do it in steps) but what is difficult for me is to invent a procedure that organizes the data in an efficient way.
>
> I tried some step , starting with collecting the coefficients but i think I am going the wrong way
>
> calcolati <- list()
> for (i in c(ra,rb,rc,rd,re,rf,rg,rh))
> {
>   calcolati[[i]] <- i$coefficients[1]
> }
>
> Thanks for any help you can provide.
>
> f.
> ----------------------------------
> Francesca Pancotto
> Web: https://sites.google.com/site/francescapancotto/ <https://sites.google.com/site/francescapancotto/>
> Energie:
> http://www.energie.unimore.it/ <http://www.energie.unimore.it/>
> ----------------------------------
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

-- 
Michael
http://www.dewey.myzen.co.uk/home.html



More information about the R-help mailing list