gen_simData_hetero: Simulated Dataset Generation for High-Dimensional Mediation...

View source: R/2_generate_simulationData_heterogeneous_design.R

gen_simData_heteroR Documentation

Simulated Dataset Generation for High-Dimensional Mediation Analysis

Description

Generates synthetic datasets mimicking high-dimensional mediation structures, optionally incorporating transferable source data under varying covariate correlation and heterogeneity levels. This function supports heterogeneous settings for data generation.

Usage

gen_simData_hetero(
  n = 100,
  p_x = 5,
  rho = 0,
  p_m = 100,
  h = 0,
  source = FALSE,
  transferable = TRUE,
  seed = NULL
)

Arguments

n

Integer. Number of observations (sample size). Default is 100.

p_x

Integer. Number of covariates (confounders). Default is 5.

rho

Numeric. Correlation coefficient (0–1) controlling correlation between mediators. Default is 0 (no correlation).

p_m

Integer. Number of mediators. Default is 100.

h

Integer. Degree of heterogeneity (for source data). Default is 0.

source

Logical. If TRUE, generate source (external) dataset. Default is FALSE.

transferable

Logical. If TRUE, generates a transferable source dataset sharing mediator-outcome structure with the target. Default is TRUE.

seed

Integer. Optional random seed for reproducibility. Default is NULL.

Details

This function generates data according to a structural equation model (SEM):

  • Treatment D depends linearly on covariates X.

  • Mediators M depend on D and X, with residual correlation controlled by rho.

  • Outcome Y depends on D, M, and X.

  • If source = TRUE, then a source dataset is simulated with potentially transferable mechanisms.

Value

A list with the following components:

  • data: A data.frame of dimension n × (2 + p_m + p_x) containing outcome (Y), treatment (D), mediators (M1–Mp_m), and covariates (X1–Xp_x).

  • effect: A named list of true total, direct, and indirect effects, exposure-mediator effects and mediator-outcome effects.

Examples

source_data <- gen_simData_hetero(
  n = 100, p_x = 5, rho = 0, p_m = 100, h = 0,
  source = TRUE, transferable = TRUE, seed = 123
)
source_data <- gen_simData_hetero(
  n = 100, p_x = 5, rho = 0, p_m = 100, h = 0,
  source = FALSE, transferable = TRUE, seed = 123
)

TransHDM documentation built on Nov. 24, 2026, 9:06 a.m.