| simulate_mtl | R Documentation |
Generates a realistic simulated dataset with binary and continuous
features and a known ground-truth coefficient structure. The
mode argument selects the response type: piecewise-exponential
survival times (default), multi-task regression
targets, or multi-task binary classification labels. Designed
for demonstrating and testing orthoMTL.
simulate_mtl(
n = 200,
p = 30,
n_signals = 5,
n_continuous = 1,
thresholds = c(4, 6, 10, 15),
mode = c("survival", "regression", "classification"),
noise_sd = 1,
censoring_max = 25,
baseline_hazard = 0.05,
effect_strength = 0.8,
treatment_effect = -0.3,
seed = NULL
)
n |
Number of patients. Default: |
p |
Number of features excluding the treatment column.
Default: |
n_signals |
Number of features with true non-zero effects.
Default: |
n_continuous |
Number of continuous features (placed first
in the feature matrix). Default: |
thresholds |
Numeric vector of time thresholds defining the
task structure. Default: |
mode |
Character; the response type to generate. One of
|
noise_sd |
Standard deviation of the Gaussian noise added in
|
censoring_max |
Maximum censoring time. Censoring times are
drawn from |
baseline_hazard |
Baseline hazard rate per interval. Default:
|
effect_strength |
Multiplier controlling the magnitude of
feature effects. Default: |
treatment_effect |
Effect of treatment on the log-hazard
(negative = protective). Default: |
seed |
Optional random seed for reproducibility. Default:
|
Feature structure:
Continuous features are drawn from N(0, 1).
Binary features have prevalences drawn from Beta(2, 10),
producing a realistic range (~5-30%).
Treatment is balanced 1:1 via random assignment.
Effect templates: Each signal feature is assigned one of five temporal patterns:
"early": strong effect at early thresholds, fading to
zero at late.
"late": zero at early thresholds, emerging at late.
"constant": equal effect across all thresholds
(detectable by standard Cox models).
"increasing": effect grows over time.
"decreasing": effect shrinks over time.
Templates are assigned cyclically across signal features with random sign (risk-increasing or protective).
Survival time generation:
Uses a piecewise-exponential model where the hazard in each
interval is
h_k(i) = baseline_hazard * exp(X[i, ] %*% beta[, k]).
Patients progress through intervals sequentially; an event
occurs when the simulated time within an interval is shorter
than the interval width.
Censoring:
Independent of event times. C ~ Unif(0, censoring_max).
Observed time = min(T, C), event indicator = T <= C.
An object of class "simulated_mtl" containing:
The response type generated.
For mode = "regression" / "classification",
the n x length(thresholds) response matrix. NULL
in survival mode (use SurvTime/Event instead).
Survival mode only (NULL otherwise):
observed times and event indicators.
Numeric matrix of dimensions n x (p + 1).
Columns include n_continuous continuous features
(standard normal), p - n_continuous binary features
(prevalences drawn from Beta(2, 10)), and a
treatment column (balanced 1:1).
Numeric vector of observed survival times.
Binary vector: 1 = event observed,
0 = censored.
Binary vector (also present as last column
of X).
Character vector of column names of
X.
A list containing:
Matrix of true coefficients with
dimensions (p + 1) x length(thresholds).
Names of features with non-zero effects.
Names of features with zero effects.
Named character vector mapping signal features to their temporal effect template.
The thresholds used.
The baseline hazard used.
Input parameters stored for reference.
The matched function call.
create_longitudinal_labels,
orthoMTL
# Generate simulated data
sim <- simulate_mtl(n = 100, p = 20, n_signals = 4, seed = 42)
sim
# Inspect ground truth
sim$ground_truth$signal_features
sim$ground_truth$effect_types
sim$ground_truth$coefficients[sim$ground_truth$signal_features, ]
# Use in orthoMTL workflow
thresholds <- c(4, 6, 10, 15)
Y <- create_longitudinal_labels(sim$SurvTime, sim$Event, thresholds)
W <- create_indicator_matrix(Y)
K <- create_constraint_matrix(length(thresholds))
fit <- orthoMTL(sim$X, Y, lambda = 1e-3, K = K,
survival = TRUE, censored.mat = W)
summary(fit)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.