Learn R Programming

glmmTMB (version 1.0.2.1)

ranef.glmmTMB: Extract Random Effects

Description

Extract random effects from a fitted glmmTMB model, both for the conditional model and zero inflation.

Usage

# S3 method for glmmTMB
ranef(object, condVar = TRUE, ...)

# S3 method for ranef.glmmTMB as.data.frame(x, ...)

# S3 method for glmmTMB coef(object, condVar = FALSE, ...)

Arguments

object

a glmmTMB model.

condVar

whether to include conditional variances in result.

some methods for this generic function require additional arguments (they are unused here and will trigger an error)

x

a ranef.glmmTMB object (i.e., the result of running ranef on a fitted glmmTMB model)

Value

  • For ranef, an object of class ranef.glmmTMB with two components:

    cond

    a list of data frames, containing random effects for the conditional model.

    zi

    a list of data frames, containing random effects for the zero inflation.

    If condVar=TRUE, the individual list elements within the cond and zi components (corresponding to individual random effects terms) will have associated condVar attributes giving the conditional variances of the random effects values. These are in the form of three-dimensional arrays: see ranef.merMod for details. The only difference between the packages is that the attributes are called ‘postVar’ in lme4, vs. ‘condVar’ in glmmTMB.

  • For coef.glmmTMB: a similar list, but containing the overall coefficient value for each level, i.e., the sum of the fixed effect estimate and the random effect value for that level. Conditional variances are not yet available as an option for coef.glmmTMB.

  • For as.data.frame: a data frame with components

    component

    part of the model to which the random effects apply (conditional or zero-inflation)

    grpvar

    grouping variable

    term

    random-effects term (e.g., intercept or slope)

    grp

    group, or level of the grouping variable

    condval

    value of the conditional mode

    condsd

    conditional standard deviation

See Also

fixef.glmmTMB.

Examples

Run this code
# NOT RUN {
if (requireNamespace("lme4")) {
   data(sleepstudy, package="lme4")
   model <- glmmTMB(Reaction ~ Days + (1|Subject), sleepstudy)
   rr <- ranef(model)
   print(rr, simplify=FALSE)
   ## extract Subject conditional modes for conditional model
   rr$cond$Subject
   as.data.frame(rr)
}
# }

Run the code above in your browser using DataLab