Skip to content

Usage

ref_simulate(
n = 400,
kind = c("gaussian", "shash", "longitudinal"),
sites = 4,
site_shift = 0,
site_log_scale = 0,
scale = c("constant", "age"),
skew = 0.6,
tail = 0.85,
visits = 3,
tau_b = sqrt(0.5),
tau_g = sqrt(0.35),
sigma_e = sqrt(0.15),
ell = 5,
lag = NULL,
seed = NULL
)

Synthetic data with known generative structure for examples and law tests. Every kind returns age, sex, site, an outcome y, and three correlated Gaussian markers marker_01..marker_03. The true generative parameters are stored in attr(x, "truth").

Argument Description
n Number of rows (for "longitudinal", approximate).
kind Generator name.
sites Number of sites.
site_shift Location shift per site in outcome units, recycled
to sites.
site_log_scale Log-scale shift per site, recycled to sites.
scale "constant" or "age"-dependent outcome scale.
skew, tail SHASH skew and tail ("shash" only).
visits Mean visits per subject ("longitudinal" only).
tau_b, tau_g, sigma_e Standard deviations of the stable, dynamic,
and measurement components ("longitudinal" only). They are
rescaled to sum to unit variance.
ell Matern-3/2 length-scale in time units ("longitudinal"
only).
lag Optional fixed lag ("longitudinal" only): every subject
then has exactly two visits this far apart, the design under which
the Matern length-scale is not identified.
seed Optional seed; the global RNG state is restored afterwards.
  • "gaussian": y is Gaussian with location $\mu(age, sex)$ and either a constant or an age-dependent scale.
  • "shash": y is sinh-arcsinh with the same location and scale and constant skew and tail.
  • "longitudinal": subjects have 2 to visits + 1 visits with irregular lags (or exactly two visits a fixed lag apart when lag is given). The normal score of y follows a stable subject component plus a Matern-3/2 process in time plus measurement noise, $z_i(t) = \tau_b b_i + \tau_g g_i(t) + \sigma_e e_{it}$, with $\tau_b^2 + \tau_g^2 + \sigma_e^2 = 1$ so that marginal scores are standard normal. Adds participant_id and visit columns.

A data frame with a truth attribute listing the generative parameters. For "longitudinal", truth$correlation(lag) gives the implied correlation of normal scores at a given lag.

ref <- ref_simulate(200, seed = 1)
attr(ref, "truth")$sigma
function(age, scale) {
if (identical(scale, "age")) 1.2 + 0.02 * pmax(age - 40, 0) else rep(1.3, length(age))
}
<bytecode: 0x56419d082228>
<environment: namespace:referent>
long <- ref_simulate(300, kind = "longitudinal", seed = 2)
attr(long, "truth")$correlation(2)
[1] 0.7963404