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, ...)Value
For
ranef, an object of classranef.glmmTMBwith 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.
- disp
a list of data frames, containing random effects for the dispersion model.
If
condVar=TRUE, the individual list elements within thecond,zi, anddispcomponents (corresponding to individual random effects terms) will have associatedcondVarattributes giving the conditional variances of the random effects values. These are in the form of three-dimensional arrays: seeranef.merModfor 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.
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)
}
#> $cond
#> $cond$Subject
#> (Intercept)
#> 308 40.635100
#> 309 -77.565868
#> 310 -62.878597
#> 330 4.390390
#> 331 10.178966
#> 332 8.191284
#> 333 16.440371
#> 334 -2.986056
#> 335 -45.117116
#> 337 71.919659
#> 349 -21.119006
#> 350 14.059946
#> 351 -7.833567
#> 352 36.245868
#> 369 7.010745
#> 370 -6.339513
#> 371 -3.282264
#> 372 18.049738
#>
#>
#> $zi
#> list()
#>
#> $disp
#> list()
#>
#> component grpvar term grp condval condsd
#> cond.1 cond Subject (Intercept) 308 40.635100 12.53484
#> cond.2 cond Subject (Intercept) 309 -77.565868 12.65076
#> cond.3 cond Subject (Intercept) 310 -62.878597 12.59611
#> cond.4 cond Subject (Intercept) 330 4.390390 12.49122
#> cond.5 cond Subject (Intercept) 331 10.178966 12.49348
#> cond.6 cond Subject (Intercept) 332 8.191284 12.49251
#> cond.7 cond Subject (Intercept) 333 16.440371 12.49794
#> cond.8 cond Subject (Intercept) 334 -2.986056 12.49095
#> cond.9 cond Subject (Intercept) 335 -45.117116 12.54509
#> cond.10 cond Subject (Intercept) 337 71.919659 12.62843
#> cond.11 cond Subject (Intercept) 349 -21.119006 12.50264
#> cond.12 cond Subject (Intercept) 350 14.059946 12.49600
#> cond.13 cond Subject (Intercept) 351 -7.833567 12.49235
#> cond.14 cond Subject (Intercept) 352 36.245868 12.52583
#> cond.15 cond Subject (Intercept) 369 7.010745 12.49202
#> cond.16 cond Subject (Intercept) 370 -6.339513 12.49178
#> cond.17 cond Subject (Intercept) 371 -3.282264 12.49100
#> cond.18 cond Subject (Intercept) 372 18.049738 12.49943