Learn R Programming

GHRmodel (version 0.1.1)

cov_add: Add Covariates to All Combinations

Description

This function appends one or more covariate names to all elements (i.e., covariate sets) in a list of character vectors. This is useful when a covariate (like a confounder or control variable) needs to be included in every model. It also works with a single character vector input. The resulting list can be input into the covariates argument in write_inla_formulas.

Usage

cov_add(covariates, name, add = FALSE)

Value

A list of character vectors, with each vector containing the original covariates plus the additional ones specified in the name argument.

Arguments

covariates

A character vector or a list of character vectors, where each vector represents a set of covariates (e.g., from cov_multi).

name

A character vector of covariate names to be added to each set.

add

Boolean that indicates if the original combinations in the covariates argument must be kept. Defaults to FALSE.

Examples

Run this code
# Multiple combinations
cov_sets <- list(
  c("tmin", "pdsi"),
  c("tmin.l1", "pdsi"),
  c("tmin.l2", "pdsi")
)
cov_add(cov_sets, name = "urban")

Run the code above in your browser using DataLab