[R-sig-ME] bug/problem with update for merMod
Ben Bolker
bbolker at gmail.com
Fri Feb 7 16:10:18 CET 2014
Alexandra Kuznetsova <alku at ...> writes:
>
> Dear all,
>
> I have an issue with update.merMod function. I would like
> to call it within a function and to send some extra
> parameters to it.
> The code below fails with an error:
>
updateModel <- function(model, reml, l)
{
nfit <- update(object=model, formula.=as.formula(paste(".~."))
, REML=reml ,contrasts=l, evaluate=FALSE)
env <- environment(formula(model))
nfit <- eval(nfit, envir = env)
#nfit <- eval.parent(nfit)
#nfit <- eval(nfit, parent.frame())
}
> m <- lmer(Reaction ~ Days +(1|Subject), data=sleepstudy)
> updateModel(m, FALSE, "contr.SAS")
>
> Error in model.matrix.default(fixedform, fr, contrasts) : object 'l' not found
>
> eval.parent(nfit) fails as well.
>
> If I use evaluate=TRUE, then there is no problem,
> but I need to use evaluate=FALSE
>
> > sessionInfo()
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
[snip]
> other attached packages:
> [1] lme4_1.1-2 Matrix_1.1-0
>
[snip]
> Is there some way to overcome this problem/bug?
>
> Thank you in advance for any suggestion!
>
> With best regards,
> Alexandra
>
It's not at all surprising that update fails when you do fancy
things with environments: it's a big headache trying to keep everything in
sync. If you get a chance could you post this at
https://github.com/lme4/lme4/issues ?
Ben Bolker
More information about the R-sig-mixed-models
mailing list