[R] List of lm objects

Spencer Graves spencer.graves at pdf.com
Thu Oct 23 22:34:45 CEST 2003


How about the following:

AList <- vector(mode="list", length=3)
for(i in 1:3){
y <- df[,i])
mod <- lm(y~Tr*Dose, data=x, contrasts=list(Tr=contr.sum, Dose=contr.sum))
AList[[i]] <- Anova(mod, type="III")
}

hope this helps. spencer graves

CENDOYA, Gabriela wrote:

>Hi R-Helpers:
>
>I’m trying to fit the same linear model to a bunch of variables in a data
>frame, so I was trying to adapt the codes John Fox, Spencer Graves and Peter
>Dalgaard  proposed and discused yesterday on this e-mail list:
>
>for (y in df[, 3:5]) {
>mod = lm(y ~ Trt*Dose, data = x, contrasts = list(Trt =
>contr.sum, Dose = contr.sum))
>Anova(mod, type = "III")
>} ##  by John Fox
>
>or
>for (myname in names(myframe)){
>  mycall <- substitute(lm(myvar~etc.etc.....),list(myvar=as.name(myname)))
>  myfit <- eval(mycall)
>  print(summary(myfit))
>} ## by Peter Dalgaard
>
>But instead of printing summary or Anova results, I need to generate a list
>containing all the lm() objects.
>Is that possible? How?
>
>Thanks, Gabriela.
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>  
>




More information about the R-help mailing list