This function takes a vector of strings representing grouping factors and converts each string into a random effect term formatted for use in lme4 model formulas. Specifically, it formats them as random intercepts for the specified grouping factors.

convert_to_random_effects(variables)

Arguments

variables

A character vector where each element is the name of a grouping factor for which a random intercept will be included in the model.

Value

A character vector of random effect terms, each formatted as (1|group), where group is replaced with each string from the input vector.

Examples

grouping_factors <- c("school", "class")
random_effects <- convert_to_random_effects(grouping_factors)
print(random_effects)
#> [1] "(1|school)+(1|class)"