brm_simulate_categorical {brms.mmrm}R Documentation

Append simulated categorical covariates

Description

Simulate and append non-time-varying categorical covariates to an existing brm_data() dataset.

Usage

brm_simulate_categorical(data, names, levels, probabilities = NULL)

Arguments

data

Classed tibble as from brm_data() or brm_simulate_outline().

names

Character vector with the names of the new covariates to simulate and append. Names must all be unique and must not already be column names of data.

levels

Character vector of unique levels of the simulated categorical covariates.

probabilities

Either NULL or a numeric vector of length length(levels) with levels between 0 and 1 where all elements sum to 1. If NULL, then all levels are equally likely to be drawn. If not NULL, then probabilities is a vector of sampling probabilities corresponding to each respective level of levels.

Details

Each covariate is a new column of the dataset with one independent random categorical draw for each patient, using a fixed set of levels (via base::sample() with replace = TRUE). All covariates simulated this way are independent of everything else in the data, including other covariates (to the extent that the random number generators in R work as intended).

Value

A classed tibble, like from brm_data() or brm_simulate_outline(), but with new categorical covariate columns and with the names of the new covariates appended to the brm_covariates attribute. Each new categorical covariate column is a character vector, not the factor type in base R.

See Also

Other simulation: brm_simulate_continuous(), brm_simulate_outline(), brm_simulate_prior(), brm_simulate_simple()

Examples

data <- brm_simulate_outline()
brm_simulate_categorical(
  data = data,
  names = c("site", "region"),
  levels = c("area1", "area2")
)
brm_simulate_categorical(
  data = data,
  names = c("site", "region"),
  levels = c("area1", "area2"),
  probabilities = c(0.1, 0.9)
)

[Package brms.mmrm version 0.1.0 Index]