Extract the modes of the random effects
Description
A generic function to extract the conditional modes of the random effects from a fitted model object. For linear mixed models the conditional modes of the random effects are also the conditional means.
Usage
1 2 3 4 5 6 7 
Arguments
object 
an object of a class of fitted models with
random effects, typically a

condVar 
an optional logical argument indicating if the conditional variancecovariance matrices of the random effects should be added as an attribute. 
drop 
should components of the return value that would be data frames
with a single column, usually a column called
‘ 
whichel 
character vector of names of grouping factors for which the random effects should be returned. 
postVar 
a (deprecated) synonym for 
x 
a randomeffects object (of class 
main 
include a main title, indicating the grouping factor, on each subplot? 
data 
This argument is required by the 
... 
some methods for these generic functions require additional arguments. 
Details
If grouping factor i has k levels and j random effects
per level the ith component of the list returned by
ranef
is a data frame with k rows and j columns.
If condVar
is TRUE
the "postVar"
attribute is an array of dimension j by j by k. The kth
face of this array is a positive definite symmetric j by
j matrix. If there is only one grouping factor in the
model the variancecovariance matrix for the entire
random effects vector, conditional on the estimates of
the model parameters and on the data will be block
diagonal and this j by j matrix is the kth diagonal
block. With multiple grouping factors the faces of the
"postVar"
attributes are still the diagonal blocks
of this conditional variancecovariance matrix but the
matrix itself is no longer block diagonal.
Value
An object of class ranef.mer
composed of
a list of data frames, one for each grouping factor for
the random effects. The number of rows in the data frame
is the number of levels of the grouping factor. The
number of columns is the dimension of the random effect
associated with each level of the factor.
If condVar
is TRUE
each of the data frames
has an attribute called "postVar"
which is a
threedimensional array with symmetric faces; each face
contains the variancecovariance matrix for a particular
level of the grouping factor. (The name
of this attribute is a historical artifact,
and may be changed to condVar
at some point in the future.)
When drop
is TRUE
any components that would
be data frames of a single column are converted to named
numeric vectors.
Note
To produce a (list of) “caterpillar plots” of the random
effects apply dotplot
to
the result of a call to ranef
with condVar =
TRUE
; qqmath
will generate
a list of QQ plots.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  require(lattice)
fm1 < lmer(Reaction ~ Days + (DaysSubject), sleepstudy)
fm2 < lmer(Reaction ~ Days + (1Subject) + (0+DaysSubject), sleepstudy)
fm3 < lmer(diameter ~ (1plate) + (1sample), Penicillin)
ranef(fm1)
str(rr1 < ranef(fm1, condVar = TRUE))
dotplot(rr1) ## default
## specify free scales in order to make Day effects more visible
dotplot(rr1,scales = list(x = list(relation = 'free')))[["Subject"]]
if(FALSE) { ## condVar=TRUE is not yet implemented for multiple terms  FIXME
str(ranef(fm2, condVar = TRUE))
}
op < options(digits = 4)
ranef(fm3, drop = TRUE)
options(op)
