[R-sig-ME] Accessing and updating lmer objects

Vincent Dorie vjd4 at nyu.edu
Thu May 8 19:30:06 CEST 2014

After you install new random effect covariance parameters into a merMod object, you need to propagate the changes to the various dependent matrix decompositions. For a lmm, it looks something like:

newTheta <- c(1, 0, 1)
fm at pp$setTheta(newTheta)
fm at pp$updateDecomp()
fm at resp$updateMu(fm at pp$linPred(0.0))
fm at pp$updateRes(fm at resp$wtres);
fm at pp$solve()
fm at resp$updateMu(fm at pp$linPred(1.0))

And then to get the deviance for the object,

fm at resp$objective(fm at pp$ldL2(), fm at pp$ldRX2(), fm at pp$sqrL(1.0))

That's the R equivalent of what the C++ code does for each optimization step. If you're working with a glmm, the process is similar but you can see how to do it much more easily by calling glmer with devFunOnly = TRUE and examining the resulting function.

In fact, if all you want to do is install the parameters, you can grab the deviance function for a lmm/glmm and simply call that with your desired parameters to get an updated object. However, if you want to interject modifications you will need to modify the above steps.


On May 6, 2014, at 3:27 PM, Ben Bolker wrote:

> On 14-05-06 12:11 AM, Asaf Weinstein wrote:
>> Hi,
>> I am trying to follow the lme4 manual (Bates) where objects returned by
>> lmer() are accessed in the following way (for example):
>> fm08 at re@Lambda at x[] <- c(1,0,1)[fm08 at re@Lind]
>> If I understand correctly, accessing with "@" no longer works, and to
>> obtain, eg, Lambda, I'll need to use
>> getME(fm08, 'Lambda')
>> instead.
>> But how do I update an object (not just view it)? In other words, what
>> command replaces
>> fm08 at re@Lambda at x[] <- c(1,0,1)[fm08 at re@Lind] ?
>   I *believe* (without much testing) that if m is a merMod object this
> would be something like
> m at pp$Lambdat at x[] <- c(1,0,1)[m at pp$Lind]
> but I'm afraid that you might run into a _lot_ of roadblocks if you try
> to work your way through the old manual with the new lme4.  We are
> working on updated documentation ... it might make more sense to work
> either with lme4.0, or with the lme4pureR package from Github ...
>  Ben Bolker
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models

More information about the R-sig-mixed-models mailing list