[R] Organize regression output

Jim Lemon drjimlemon at gmail.com
Sun Dec 11 10:51:35 CET 2016


Hi Francesca,
I'm not sure what you are doing here, but try this:

regnames<-paste("r",letters[1:8],sep="")
for(i in 1:8) {
 response<-rnorm(20)
 coef1<-rnorm(20)
 coef2<-rnorm(20)
 age<-sample(20:50,20)
 gender<-sample(c("M","F"),20,TRUE)
 assign(regnames[i],lm(response~coef1+coef2+age+gender))
}
reglist<-list(ra,rb,rc,rd,re,rf,rg,rh)
cumsumcoef<-function(x) return(cumsum(x$coef))
coefsumlist<-as.data.frame(lapply(reglist,cumsumcoef))
names(coefsumlist)<-regnames
coefsumlist

Jim

On Sat, Dec 10, 2016 at 6:32 PM, francesca Pancotto
<francesca.pancotto at gmail.com> 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.



More information about the R-help mailing list