[R] Define lm/glm object without evaluating them

Søren Højsgaard Soren.Hojsgaard at agrsci.dk
Tue Nov 17 10:11:15 CET 2009


For e.g. lm/glm type models I would like to separate model specification and model fitting and then only fit the models later 'when data arrives'. To be specific, I would like make a specification like
m1 <- lm(rate~conc)
m2 <- lm(rate~I(conc^2))

and then later I want to 'put data into' the objects and evaluate (fit the model), e.g. something like
update(m1, data=Puromycin)
update(m2, data=Puromycin)

The 'closest' I can get to what I want is
1) Specification:
m.list <-expression(lm(rate~conc), lm(rate~I(conc^2)))
2) Update with data:
m.list2 <- lapply(m.list, function(m) {m$data=Puromycin; return(m)})
3) Now, evaluate:
lapply(m.list2, eval)
Can anyone point me to a simpler approach?
Regards
Søren




More information about the R-help mailing list