ranef.glmmTMB: Extract Random Effects

View source: R/methods.R

ranef.glmmTMBR Documentation

Extract Random Effects

Description

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

Usage

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

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

## S3 method for class '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

Note

When a model has no zero inflation, the ranef and coef print methods simplify the structure shown, by default. To show the full list structure, use print(ranef(model),simplify=FALSE) or the analogous code for coef. In all cases, the full list structure is used to access the data frames, see example.

See Also

fixef.glmmTMB.

Examples

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)
}

glmmTMB documentation built on Oct. 7, 2023, 5:07 p.m.