re2uncorr: Converts lme4 random-effect terms to uncorrelated lme4...

View source: R/utility.r

re2uncorrR Documentation

Converts lme4 random-effect terms to uncorrelated lme4 random-effect terms, including factor random slopes

Description

lme4 and similar packages (e.g. glmmTMB) have an issue where correlations between factor random slopes are not dropped, even if using the double-bar syntax or diag to diagonalize the random-effects formula. re2uncorr works around this issue by explicitly converting factor random slopes to numerics, which do not suffer from this problem.

Usage

re2uncorr(formula, data, drop = TRUE)

Arguments

formula

The lme4 formula.

data

The data.

drop

Logical indicating whether constant, non-intercept columns should be dropped. Default TRUE. A warning is issued if a column needed to be dropped. Note that repeated intercept columns are silently merged without a warning.

Details

To ensure that the various buildmer functions (e.g. buildmer, buildglmmTMB) correctly apply marginality constraints between fixed effects and random-effect terms, the fixed effects are renamed using the same name-mangling scheme that is automatically applied to the random effects. To ensure that the mangled names will be grouped together, instead of passing the returned formula, use the returned termlist with a dep argument. See the description of the dep argument in buildmerControl.

Value

A list containing a new formula (has a dependent variable but loses track of what terms belong together in a single block), a buildmer term list (lacks the dependent variable but represents what terms belong together), and a new data set.

Examples

library(buildmer)
re <- re2uncorr(f1 ~ vowel*timepoint*following +
	(vowel*timepoint*following|participant) + (timepoint|word),vowels)

model <- buildmer(re$formula,re$data)

buildmer documentation built on June 27, 2026, 1:06 a.m.