Number of levels per random-effect grouping factor
Value
brms's named list, one integer per grouping factor, or NULL
for a fit with no grouping factor. Smooth, Gaussian-process, CAR
and SPDE blocks are random-effect blocks here and are not grouping
factors in brms, so they are excluded; their parameters are in
VarCorr() and confint_varcorr().
Examples
set.seed(1)
dd <- data.frame(x = rnorm(100),
g = factor(rep(1:10, 10)),
h = factor(rep(1:4, each = 25)))
dd$y <- rnorm(100, 1 + 0.5 * dd$x + rnorm(10, 0, 0.8)[dd$g], 1)
fit <- frm(bf(y ~ x + (1 | g) + (1 | h)) + gaussian(), data = dd)
# one count per distinct grouping factor
ngrps(fit)
#> $g
#> [1] 10
#>
#> $h
#> [1] 4
#>
# the count that decides whether a variance component is trustworthy,
# and the unit influence() deletes when given `groups`
ngrps(fit)[["h"]]
#> [1] 4