ranef {lme4}R Documentation

Extract the modes of the random effects


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.


## S3 method for class 'merMod'
 ranef(object, condVar = TRUE,
      drop = FALSE, whichel = names(ans), postVar = FALSE, ...)
## S3 method for class 'ranef.mer'
 dotplot(x, data, main = TRUE, transf = I, ...)
## S3 method for class 'ranef.mer'
 qqmath(x, data, main = TRUE, ...)
## S3 method for class 'ranef.mer'
 as.data.frame(x, ...)



an object of a class of fitted models with random effects, typically a merMod object.


a logical argument indicating if the conditional variance-covariance matrices of the random effects should be added as an attribute.


should components of the return value that would be data frames with a single column, usually a column called ‘(Intercept)’, be returned as named vectors instead?


character vector of names of grouping factors for which the random effects should be returned.


a (deprecated) synonym for condVar


a random-effects object (of class ranef.mer) produced by ranef


include a main title, indicating the grouping factor, on each sub-plot?


transformation for random effects: for example, exp for plotting parameters from a (generalized) logistic regression on the odds rather than log-odds scale


This argument is required by the dotplot and qqmath generic methods, but is not actually used.


some methods for these generic functions require additional arguments.


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 (or a list of such arrays). 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 variance-covariance matrix for the entire random effects vector, conditional on the estimates of the model parameters and on the data, will be block diagonal; 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 variance-covariance matrix but the matrix itself is no longer block diagonal.



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 Q-Q plots.


library(lattice) ## for dotplot, qqmath
fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)
fm2 <- lmer(Reaction ~ Days + (1|Subject) + (0+Days|Subject), sleepstudy)
fm3 <- lmer(diameter ~ (1|plate) + (1|sample), Penicillin)
str(rr1 <- ranef(fm1))
dotplot(rr1)  ## default
## specify free scales in order to make Day effects more visible
dotplot(rr1,scales = list(x = list(relation = 'free')))[["Subject"]]
op <- options(digits = 4)
ranef(fm3, drop = TRUE)
## as.data.frame() provides RE's and conditional standard deviations:
str(dd <- as.data.frame(rr1))
if (require(ggplot2)) {
    ggplot(dd, aes(y=grp,x=condval)) +
        geom_point() + facet_wrap(~term,scales="free_x") +
        geom_errorbarh(aes(xmin=condval -2*condsd,
                           xmax=condval +2*condsd), height=0)

[Package lme4 version 1.1-32 Index]