ranef.glmmTMB {glmmTMB} | R 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 |
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 |
Value
For
ranef
, an object of classranef.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 thecond
andzi
components (corresponding to individual random effects terms) will have associatedcondVar
attributes giving the conditional variances of the random effects values. These are in the form of three-dimensional arrays: seeranef.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 forcoef.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
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)
}