getDoublevertDefault: Retrieve default double-vertical-bar-expansion method

View source: R/utilities.R

getDoublevertDefaultR Documentation

Retrieve default double-vertical-bar-expansion method

Description

Retrieve information about whether random effect terms specified with double bars (||) should be split semantically into separate, intercept-free terms, or encoded with a diag() special

Usage

getDoublevertDefault()

Details

To set the global behaviour retrieved by getDoublevertDefault() to "diag_special", run options(lme4.doublevert.default = "diag_special")

The default value of "split" is backward compatible with the behaviour of lme4 < 2.0; double bars do not work as typically expected with factors as varying terms. That is, if g is a factor then (1 + g||f) will expand (with method "split") to (1|f) + (0 + g|f); the second term will not produce a covariance matrix where the contrasts generated by the factor are independent.

"diag_special" is probably the generally preferred option; by transforming (1+a+b||f) into diag(1+a+b|f), it ensures that variation across groups in the contrasts coded by the factor will be independent. This matches the results of specifying a double-bar term in afex::mixed(), or glmmTMB.

Note that if f is a factor, even with "diag_special" set, models containing (0+f||g) vs. (f||g) will give different results. (0+f||g) creates a set of dummy variables that are indicator variables for each level of the factor, so the random effect term will describe variation in the intercept for each level of the factor. With default treatment contrasts set, (f||g) (equivalent to (1+f||g) because R automatically adds the intercept term) will estimate variation first in the intercept in the baseline level of the factor, then in the differences between observations in the baseline and successive levels of the factor (see contr.treatment).

Value

a (1-element) character vector suitable for reformulas::findbars_x specifying whether to expand random-effects terms containing double bars (||) as a set of independent random effects terms ("split": i.e., (1+a+b||f) becomes (1|f) + (0+a|f) + (0+b|f)) or whether to specify that the covariance matrix is diagonal ("diag_special": i.e., diag(1+a+b|f)).


lme4 documentation built on March 6, 2026, 1:07 a.m.