Skip to content

design matrix for mixed effects model

2 messages · Wade Wall, Douglas Bates

2 days later
#
On Fri, Jan 7, 2011 at 1:51 PM, Wade Wall <wade.wall at gmail.com> wrote:
There is a method for model.matrix for models fit by lmer.  That
returns the model matrix for the fixed-effects parameters.  Right now
the model matrix for the random effects is kind of hidden in the
structure.  In the released version of the lme4 package the transpose
of the random effects model matrix is stored as the Zt slot of the
fitted model object.
num [1:30, 1] 1 1 1 1 1 1 1 1 1 1 ...
 - attr(*, "assign")= int 0
Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  ..@ i       : int [1:30] 0 0 0 0 0 1 1 1 1 1 ...
  ..@ p       : int [1:31] 0 1 2 3 4 5 6 7 8 9 ...
  ..@ Dim     : int [1:2] 6 30
  ..@ Dimnames:List of 2
  .. ..$ : NULL
  .. ..$ : NULL
  ..@ x       : num [1:30] 1 1 1 1 1 1 1 1 1 1 ...
  ..@ factors : list()
6 x 30 sparse Matrix of class "dgCMatrix"

[1,] 1 1 1 1 1 . . . . . . . . . . . . . . . . . . . . . . . . .
[2,] . . . . . 1 1 1 1 1 . . . . . . . . . . . . . . . . . . . .
[3,] . . . . . . . . . . 1 1 1 1 1 . . . . . . . . . . . . . . .
[4,] . . . . . . . . . . . . . . . 1 1 1 1 1 . . . . . . . . . .
[5,] . . . . . . . . . . . . . . . . . . . . 1 1 1 1 1 . . . . .
[6,] . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 1 1 1

As a result of your question and of looking at the slides for a short
course tomorrow, I think I should add an argument to the model.matrix
method to allow for extracting the model matrix for the random effects
without needing to know the details of the structure.