sim_covar: Simulate co-varying variables

View source: R/sim_multvar.R

sim_covarR Documentation

Simulate co-varying variables

Description

Adds a group of variables (columns) with a given variance and covariance to a data frame or tibble

Usage

sim_covar(.data = NULL, n_obs = NULL, n_vars, var, cov, name = NA, seed = NA)

Arguments

.data

An optional dataframe. If a dataframe is supplied, simulated categorical data will be added to the dataframe. Either '.data' or 'n_obs' must be supplied.

n_obs

Total number of observations/rows to simulate if '.data' is not supplied.

n_vars

Number of variables to simulate.

var

Variance used to construct variance-covariance matrix.

cov

Covariance used to construct variance-covariance matrix.

name

An optional name to be appended to the column names in the output.

seed

An optional seed for random number generation. If 'NA' (default) a random seed will be used.

Value

a tibble

See Also

sim_cat, sim_discr

Other multivariate normal functions: sim_cat(), sim_discr()

Examples

library(dplyr)
sim_cat(n_obs = 30, n_groups = 3) %>%
sim_covar(n_vars = 5, var = 1, cov = 0.5, name = "correlated")

holodeck documentation built on Aug. 26, 2023, 1:07 a.m.