Learn R Programming

cvms (version 0.2.0)

combine_predictors: Generate model formulas by combining predictors

Description

Create model formulas with every combination of your fixed effects, along with the dependent variable and random effects. 259,358 formulas have been precomputed with two- and three-way interactions for up to 8 fixed effects, with up to 5 included effects per formula. Uses the + and * operators, so lower order interactions are automatically included.

Usage

combine_predictors(dependent, fixed_effects, random_effects = NULL,
  max_fixed_effects = 5, max_interaction_size = 3,
  max_effect_frequency = NULL)

Arguments

dependent

Name of dependent variable. (Character)

fixed_effects

List of fixed effects. (Character)

Max. limit of 8 effects when interactions are included!

A fixed effect name cannot contain: white spaces, "*" or "+".

Effects in sublists will be interchanged. This can be useful, when we have multiple versions of a predictor (e.g. x1 and log(x1)) that we do not wish to have in the same formula.

Example of interchangeable effects:

list( list( "x1", "log_x1" ), "x2", "x3" )

random_effects

The random effects structure. (Character)

Is appended to the model formulas.

max_fixed_effects

Maximum number of fixed effects in a model formula. (Integer)

Max. limit of 5 when interactions are included!

max_interaction_size

Maximum number of effects in an interaction. (Integer)

Max. limit of 3.

Use this to limit the n-way interactions allowed. 0 or 1 excludes interactions all together.

A model formula can contain multiple interactions.

max_effect_frequency

Maximum number of times an effect is included in a formula string.

Value

List of model formulas.

E.g.:

c("y ~ x1 + (1|z)", "y ~ x2 + (1|z)", "y ~ x1 + x2 + (1|z)", "y ~ x1 * x2 + (1|z)").

Examples

Run this code
# NOT RUN {
# Attach packages
library(cvms)

# Create effect names
dependent <- "y"
fixed_effects <- c("a","b","c")
random_effects <- "(1|e)"

# }
# NOT RUN {
# Create model formulas
combine_predictors(dependent, fixed_effects,
                   random_effects)

# }
# NOT RUN {
# Create effect names with interchangeable effects in sublists
fixed_effects <- list("a",list("b","log_b"),"c")

# }
# NOT RUN {
# Create model formulas
combine_predictors(dependent, fixed_effects,
                   random_effects)
# }

Run the code above in your browser using DataLab