Skip to content
Back to formatted view

Raw Message

Message-ID: <971536df0911170711s16be9929g7a1b7698518f587a@mail.gmail.com>
Date: 2009-11-17T15:11:49Z
From: Gabor Grothendieck
Subject: Define lm/glm object without evaluating them
In-Reply-To: <9F0721FDD4F12D4B95AD894274F388EC01A2BBD9E8E9@DJFEXMBX01.djf.agrsci.dk>

If your models only consists of a formula just use the formula as your
specification where evaluation consists of passing the formula to lm
with a data argument.

# specification
fo <- rate ~ conc

# evaluation
lm(fo, Puromycin)


On Tue, Nov 17, 2009 at 4:11 AM, S?ren H?jsgaard
<Soren.Hojsgaard at agrsci.dk> wrote:
> 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