Skip to content

Accessing and updating lmer objects

4 messages · Asaf Weinstein, Ben Bolker, Vincent Dorie

#
On 14-05-06 12:11 AM, Asaf Weinstein wrote:
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
1 day later
#
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.

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

            
#
On 14-05-08 01:30 PM, Vincent Dorie wrote:

            
merMod object, you need to propagate the changes to the various
  dependent matrix decompositions. For a lmm, it looks something like:
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.

  Thanks, Vince.  I think Asaf was trying to follow the step-by-step
procedure (not just calculate the deviance for a new set of procedures),
so this is exactly what he needs -- although it *might* be somewhat
higher-level than the description in the Bates manual referred to
previously. (If you look at the code in src/predModule.cpp::setTheta,
the payload is

	int    *lipt = d_Lind.data();
	double *LamX = d_Lambdat.valuePtr(), *thpt = d_theta.data();
	for (int i = 0; i < d_Lind.size(); ++i) {
	    LamX[i] = thpt[lipt[i] - 1];
	}

which is more or less equivalent to the R code referenced earlier.)

  I really would recommend that people interested in following the
details check out https://github.com/lme4/lme4pureR ... especially
https://github.com/lme4/lme4pureR/blob/master/R/JSS.R ...

  cheers
    Ben