Skip to content

allFit fails after removing object with starting values for model parameters from workspace

4 messages · Gerrit Eichner, Ben Bolker

#
Dear lmer-experts,

if I refit a fitted model with all available optimizers AFTER
removing the object which contains the starting values for the
parameters of the model as in

theta <- c(1, 0.01, 0.2)
fm <- lmer(Reaction ~ Days + (Days | Subject), data = sleepstudy,
            start = theta)
rm(theta)
allFit(fm, verbose = FALSE)

none of the optimizers succeeds:

original model:
Reaction ~ Days + (Days | Subject)
optimizers (7): bobyqa, Nelder_Mead, nlminbwrap, nmkbw, optimx.L-BFGS-B, 
nloptwrap.NLOPT_LN_N...
7 optimizer(s) failed
differences in negative log-likelihoods:
max= -Inf ; std dev= NA
Warning messages:
1: In min(nllvec) : no non-missing arguments to min; returning Inf
2: In max(nllvec - min(nllvec)) :
   no non-missing arguments to max; returning -Inf


If I don't remove theta from my workspace everything works fine.
Is there a workaround for this - from my perspective - unwanted
behaviour? (I have situations where allFit is used in a different
environment from the one wherein the model was fit, e.g., after
fitting the model the object which contains the fit is saved and
later loaded in another R-session to be processed by allFit.)
I could, of course, save theta everytime as well ... Any ideas?

  Best regards  --  Gerrit

---------------------------------------------------------------------
Dr. Gerrit Eichner                   Mathematical Institute, Room 212
gerrit.eichner at math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
http://www.uni-giessen.de/eichner
#
I forgot to mention that I use lme4_1.1-21.9001
and
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

  --  Gerrit

---------------------------------------------------------------------
Dr. Gerrit Eichner                   Mathematical Institute, Room 212
gerrit.eichner at math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
http://www.uni-giessen.de/eichner
---------------------------------------------------------------------

Am 08.08.2019 um 15:06 schrieb Gerrit Eichner:
#
This is not surprising, as allFit() uses update(), which tries to
re-evaluate the function ... at the very least allFit needs a
documentation update with that hint ... (I also notice at a glance that
the allFit docs seem to be incomplete anyway).

  If you say more about your workflow we might be able to find a way to
help.  (If your workflow is this simple then the answer would be "well
then don't delete theta" ...)

  cheers
    Ben Bolker
On 2019-08-08 9:06 a.m., Gerrit Eichner wrote:
#
Thx a lot, Ben, for the fast reply which clearly explains the
cause of my problem. I've just found a solution which works for
me (and which is not as simple as "don't delete theta" ;-) ):
I "hardwire" theta's value into the function call:

theta <- c(1, 0.01, 0.2)
fm <- eval(bquote(
    lmer(Reaction ~ Days + (Days | Subject), data = sleepstudy,
         start = .(theta))
    ))

rm(theta)
allFit(fm, verbose = FALSE)


Works like a "charm", at least in my current workflow. :-)

  Thanks once more  --  Gerrit

---------------------------------------------------------------------
Dr. Gerrit Eichner                   Mathematical Institute, Room 212
gerrit.eichner at math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
http://www.uni-giessen.de/eichner
---------------------------------------------------------------------

Am 08.08.2019 um 15:26 schrieb Ben Bolker: