formula_branch: Create a new formula branch.

View source: R/formula_branch.R

formula_branchR Documentation

Create a new formula branch.

Description

The function specifies the model formula for fitting 'lm_mverse()' and 'glm_mverse()'. You can list the model specification formulae individually or use covariates option paired with one or more formulae.

Usage

formula_branch(..., covariates = NULL, name = NULL)

Arguments

...

branch definition expressions.

covariates

(optional) A character vector of optional covariates. Each unique combination of the supplied covariates is translated into a unique branch option. See Details.

name

(optional) Name for the new formula.

Details

The optional argument covariates is allows you to specify a set of optional covariates in addition to other independent variable such as treatment variables and blocking variables which are specified using formula. For each covariate provided, a branch is added to the multiverse with the option to include or exclude the covariate in the model.

For example, formula_branch(y ~ x, covariates = c("c1", "c2")) creates the following 4 model specifications:

y ~ x

y ~ x + c1

y ~ x + c2

y ~ x + c1 + c2

Here, y is the outcome variable and x may be a treatment variable in an experiment setting. c1 and c2 may be additional covariates about the experiment units that may or may not be relevant.

Value

a formula_branch object.

See Also

Other formula branch functions: add_formula_branch()

Examples

# Define a formula branch.
model_specifications <- formula_branch(
  y ~ MasFem,
  y ~ MasFem + hurricane_strength,
  y ~ MasFem * hurricane_strength
)
# Create a mverse, add the branch.
mv <- create_multiverse(hurricane) %>%
  add_formula_branch(model_specifications)
# Specify the covariates separately.
model_specifications <- formula_branch(
  y ~ MasFem,
  covariates = c("hurricane_strength", "Year", "Category", "NDAM")
)
model_specifications

mverse documentation built on June 21, 2025, 5:09 p.m.