simulate_correlation: Simulate a correlation design

View source: R/api.R

simulate_correlationR Documentation

Simulate a correlation design

Description

A thin wrapper around simulate_correlated() that supplies defaults for means and sds, so simulate_correlation(n) generates a single standard normal variable. structure is forwarded only when it is supplied, which keeps simulate_correlated()'s own default resolution intact: "custom" when correlation is given, "exchangeable" when a non-zero rho is given, and "independent" otherwise.

Usage

simulate_correlation(
  n,
  means = 0,
  sds = 1,
  rho = 0,
  structure = c("independent", "exchangeable", "ar1", "custom"),
  correlation = NULL,
  variable_names = NULL,
  seed = NULL,
  batch = NULL
)

Arguments

n

Number of observations.

means, sds, rho, structure, correlation, variable_names, seed

Arguments passed to simulate_correlated(). Unlike that function, means defaults to 0. One variable is generated per element of means; sds must be a single value, which is recycled, or one value per mean.

batch

Optional single positive whole number. When given, the simulator runs batch times and returns a plain list of batch results, each exactly what the same call without batch returns. With a seed, every dataset gets its own seed drawn from seed, so the whole batch is reproducible; without one the datasets are consecutive draws from the session's random-number stream. The default NULL returns a single result.

Value

A simulab_sim base data.frame with one row per observation and an id column followed by one column per variable. The parameters, correlation and covariance components hold the requested means and standard deviations and the tidy correlation and covariance matrices; use components() to list them.

Examples

result <- simulate_correlation(n = 200, means = c(0, 0), sds = c(1, 1), rho = 0.6,
                               seed = 1)
head(result)
as.data.frame(result, what = "correlation")

simulab documentation built on Oct. 15, 2026, 5:08 p.m.