construct_re: Constructs random effect terms

construct_reR Documentation

Constructs random effect terms

Description

Constructs random effect terms

Usage

construct_re(re, data)

Arguments

re

A random effect as defined using re() which itself takes random effects specified in a model formula using the lme4 syntax.

data

A data.frame of observations used to define the random effects. Must contain the variables specified in the re() term.

Value

A list containing the transformed data ("data"), fixed effects terms ("terms") and a data.frame specifying the random effect structure between these terms (effects). Note that if the specified random effect was not a factor it will have been converted into one.

See Also

Functions used to help convert formulas into model designs as_string_formula(), construct_rw(), enw_formula(), enw_manual_formula(), parse_formula(), re(), remove_rw_terms(), rw(), rw_terms(), split_formula_to_terms()

Examples

# Simple examples
form <- epinowcast:::parse_formula(~ 1 + (1 | day_of_week))
data <- enw_example("prepr")$metareference[[1]]
random_effect <- re(form$random[[1]])
epinowcast:::construct_re(random_effect, data)

# A more complex example
form <- epinowcast:::parse_formula(
  ~ 1 + disp + (1 + gear | cyl) + (0 + wt | am)
)
random_effect <- re(form$random[[1]])
epinowcast:::construct_re(random_effect, mtcars)

random_effect2 <- re(form$random[[2]])
epinowcast:::construct_re(random_effect2, mtcars)

seabbs/epinowcast documentation built on July 22, 2024, 8:54 p.m.