re2mgcv: Converts lme4 random-effect terms to mgcv 're' smooths

View source: R/utility.r

re2mgcvR Documentation

Converts lme4 random-effect terms to mgcv 're' smooths

Description

Converts lme4 random-effect terms to mgcv 're' smooths

Usage

re2mgcv(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. buildgam, buildbam) correctly apply marginality constraints between parametric terms and random-effect terms, the parametric terms 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 <- re2mgcv(temp ~ angle + (1|replicate) + (1|recipe),lme4::cake)
model <- buildgam(re$formula,re$data)
# note: the below does NOT work, as the dependent variable is looked up in the data by name!

re <- re2mgcv(log(Reaction) ~ Days + (Days|Subject),lme4::sleepstudy)

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