[R] List of lm objects

CENDOYA, Gabriela gcendoya at balcarce.inta.gov.ar
Thu Oct 23 18:42:44 CEST 2003


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.




More information about the R-help mailing list