[R-sig-ME] Design Matrix for Random effects

Ben Bolker bbolker at gmail.com
Sat Jun 1 00:09:40 CEST 2013


Steve Walker <steve.walker at ...> writes:

> 
> Hi Robert,
> 
> In stable (i.e. cran) lme4, Zt can be obtained without fitting the model 
> using this command:
> 
> lmer(Reaction ~ Days + (Days|Subject), data=sleepstudy, doFit = 
> FALSE)$FL$trms[[1]]$Zt
> 
> In development (i.e. github) lme4, you can use this command:
> 
> lFormula(Reaction ~ Days + (Days|Subject), data=sleepstudy)$reTrms$Zt
> 
> or these two:
> 
> dv <- lmer(Reaction ~ Days + (Days|Subject), data=sleepstudy, 
> devFunOnly 
> = TRUE)
> environment(dv)$pp$Zt
> 
> Cheers,
> Steve
> 

  It can be done even one step more directly:

mkReTrms(list(quote(Days|Subject)),sleepstudy)$Zt

the slightly convoluted form of the first argument is because
mkReTrms (see ?mkReTrms) wants a list of the random-effects
bits extracted from the formula, so it needs to be a list
of 'language' objects.  Alternatively:

mkReTrms(findbars(~(Days|Subject)),sleepstudy)$Zt

 I have a minor preference for these because they depend
a little less on the detailed form in which things are
stored in the package.

  Ben Bolker



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