| Title: | High-Dimensional Mediation Analysis via Transfer Learning |
|---|---|
| Description: | Provides a framework for high-dimensional mediation analysis using transfer learning. The main function TransHDM() integrates large-scale source data to improve the detection power of potential mediators in small-sample target studies. It addresses data heterogeneity via transfer regularization and debiased estimation while controlling the false discovery rate. The package also includes utilities for data generation (gen_simData_homo(), gen_simData_hetero()), baseline methods such as lasso() and dblasso(), sure independence screening via SIS(), and model diagnostics through source_detection(). The methodology is described in Pan et al. (2025) <doi:10.1093/bib/bbaf460>. |
| Authors: | Huer Gao [aut, cre, cph], Lulu Pan [aut, cph], Yongfu Yu [ctb, cph], Guoyou Qin [ctb, cph] |
| Maintainer: | Huer Gao <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.1.3 |
| Built: | 2026-10-23 11:00:35 UTC |
| Source: | https://github.com/gaohuer/transhdm |
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.
gen_simData_hetero( n = 100, p_x = 5, rho = 0, p_m = 100, h = 0, source = FALSE, transferable = TRUE, seed = NULL )gen_simData_hetero( n = 100, p_x = 5, rho = 0, p_m = 100, h = 0, source = FALSE, transferable = TRUE, seed = NULL )
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. |
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.
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.
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 )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 )
Generates synthetic datasets mimicking high-dimensional mediation structures, optionally incorporating transferable source data under varying covariate correlation and heterogeneity levels. This function supports homogeneous settings for data generation.
gen_simData_homo( n = 100, p_x = 5, rho = 0, p_m = 100, h = 0, source = FALSE, transferable = TRUE, seed = NULL )gen_simData_homo( n = 100, p_x = 5, rho = 0, p_m = 100, h = 0, source = FALSE, transferable = TRUE, seed = NULL )
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. |
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.
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.
source_data <- gen_simData_homo( n = 100, p_x = 5, rho = 0, p_m = 100, h = 0, source = TRUE, transferable = TRUE, seed = 123 ) target_data <- gen_simData_homo( n = 100, p_x = 5, rho = 0, p_m = 100, h = 0, source = FALSE, transferable = TRUE, seed = 123 )source_data <- gen_simData_homo( n = 100, p_x = 5, rho = 0, p_m = 100, h = 0, source = TRUE, transferable = TRUE, seed = 123 ) target_data <- gen_simData_homo( n = 100, p_x = 5, rho = 0, p_m = 100, h = 0, source = FALSE, transferable = TRUE, seed = 123 )
Ground-truth mediation effects for the target cohort of the inflammatory
mediation benchmark dataset. Maps each candidate mediator to its true
exposure–mediator effect (), mediator–outcome effect
(), and indirect effect ().
data(inflam_effect)data(inflam_effect)
A data frame with 20 rows (one per mediator) and 4 columns:
mediator: mediator name.
alpha: true exposure–mediator effect.
beta: true mediator–outcome effect.
alpha_beta: true indirect (mediation) effect.
Four mediators have non-zero and are the true
active mediators. Because the mediator columns were randomly permuted during
data generation, these active mediators are scattered across the candidate
names — as in a real study, where the ground truth is unknown at analysis
time. This table lets users benchmark TransHDM against the
truth.
inflam_target, inflam_external1,
inflam_external2 for the associated cohorts.
data(inflam_effect) inflam_effect[inflam_effect$alpha_beta != 0, ]data(inflam_effect) inflam_effect[inflam_effect$alpha_beta != 0, ]
Simulated transferable external cohort for high-dimensional mediation analysis. It shares the mediator–outcome structure with the target cohort, making it suitable for transfer learning.
data(inflam_external1)data(inflam_external1)
A data frame with 200 rows (patients) and 25 columns, with the same
structure as inflam_target:
DSI: outcome — disease severity index.
IB: exposure — inflammatory biomarker.
CYT_01–SIG_04: 20 candidate mediators.
BIS, PRS, BRS: 3 covariates.
This large external cohort (n = 200) is generated under a transferable
setting: its exposure–mediator () and mediator–outcome
() coefficients match those of the target for the active
mediators. It is intended as the source in TransHDM with
transfer = TRUE.
Demonstration data only. Simulated for methodological demonstration of
the TransHDM workflow.
Generated with gen_simData_homo (n = 200, p_x = 3, p_m = 20,
rho = 0.1, seed = 123, source = TRUE, transferable = TRUE).
inflam_target for the target cohort, inflam_external2
for the non-transferable external cohort.
data(inflam_external1) str(inflam_external1)data(inflam_external1) str(inflam_external1)
Simulated non-transferable external cohort for high-dimensional mediation analysis. Its mediator structure differs from the target cohort, and the covariate distribution is shifted, so it should not be used for transfer.
data(inflam_external2)data(inflam_external2)
A data frame with 100 rows (patients) and 25 columns, with the same
structure as inflam_target:
DSI: outcome — disease severity index.
IB: exposure — inflammatory biomarker.
CYT_01–SIG_04: 20 candidate mediators.
BIS, PRS, BRS: 3 covariates.
This external cohort (n = 100) is generated under a non-transferable
setting with covariate shift. Its exposure–mediator and mediator–outcome
coefficients differ from the target, so naive transfer would degrade
performance. It is used with source_detection to demonstrate
detection of non-transferable sources.
Demonstration data only. Simulated for methodological demonstration of
the TransHDM workflow.
Generated with gen_simData_hetero (n = 100, p_x = 3, p_m = 20,
rho = 0.1, seed = 999, source = TRUE, transferable = FALSE).
inflam_target for the target cohort, inflam_external1
for the transferable external cohort.
data(inflam_external2) str(inflam_external2)data(inflam_external2) str(inflam_external2)
Simulated target cohort for a high-dimensional mediation analysis in which an inflammatory biomarker (exposure) influences a disease severity index (outcome) through a panel of candidate molecular mediators, adjusting for clinical covariates.
data(inflam_target)data(inflam_target)
A data frame with 50 rows (patients) and 25 columns:
DSI: outcome — disease severity index.
IB: exposure — inflammatory biomarker.
CYT_01–SIG_04: 20 candidate mediators across five
functional groups (cytokines CYT, immune markers IMM,
oxidative stress OXI, metabolic MET, signalling SIG).
BIS, PRS, BRS: 3 covariates (baseline
inflammatory status, physiological reserve score, baseline risk score).
Mediation model:
This is the small-sample target cohort (n = 50) that benefits from
transfer learning using the larger external cohorts. The mediator columns
have been randomly permuted, so the identity of the truly active mediators
is hidden; the ground truth is stored in inflam_effect.
Demonstration data only. Simulated for methodological demonstration of
the TransHDM workflow, not for drawing biological conclusions.
Generated with gen_simData_homo (n = 50, p_x = 3, p_m = 20,
rho = 0.1, seed = 123). See gen_data.R in the package source.
inflam_external1, inflam_external2 for the
external cohorts, and inflam_effect for the ground truth.
data(inflam_target) str(inflam_target)data(inflam_target) str(inflam_target)
Step 3 (final step) of the TransHDM pipeline: joint
multiple testing on the alpha and beta p-values obtained from
mediation_inference (Step 2). It estimates the null
proportion, controls the false discovery rate via HDMT::fdr_est,
identifies significant mediators, and summarises the direct, indirect,
and total effects into a "TransHDM" object.
Together with SIS (Step 1) and
mediation_inference (Step 2), this completes the three-step
TransHDM workflow.
joint_test(inference_result, p_cutoff = 0.05, verbose = TRUE)joint_test(inference_result, p_cutoff = 0.05, verbose = TRUE)
inference_result |
An object of class |
p_cutoff |
A numeric value (default: 0.05) specifying the maximum FDR threshold for identifying significant mediators. |
verbose |
A logical value (default: |
An object of class "TransHDM" — a list with:
contributions: Data frame of identified mediators with
columns mediator, alpha, alpha_pv, beta,
beta_pv, alpha_beta, ab_pv, pa.
effects: Data frame summarising indirect, direct, total
effects and proportion mediated (pe).
IDE_est: Named numeric vector of indirect effect estimates
for all mediators (non-selected set to zero).
DE_est: Estimated direct effect.
all_mediators: Data frame of all SIS-screened mediators with
columns mediator, alpha, alpha_pv, beta,
beta_pv, significant (logical).
TransHDM, mediation_inference, SIS
set.seed(123) target_data <- gen_simData_homo(n = 50, p_x = 3, p_m = 20, rho = 0.1)$data source_data <- gen_simData_homo(n = 100, p_x = 3, p_m = 20, rho = 0.1, source = TRUE, transferable = TRUE)$data M_vars <- paste0("M", 1:20) X_vars <- paste0("X", 1:3) # Full pipeline sis <- SIS(target_data, source_data, Y = "Y", D = "D", M = M_vars, X = X_vars, transfer = TRUE, topN = 10) infer <- mediation_inference(sis, M = M_vars, D = "D", X = X_vars, Y = "Y", transfer = TRUE) result <- joint_test(infer) plot(result)set.seed(123) target_data <- gen_simData_homo(n = 50, p_x = 3, p_m = 20, rho = 0.1)$data source_data <- gen_simData_homo(n = 100, p_x = 3, p_m = 20, rho = 0.1, source = TRUE, transferable = TRUE)$data M_vars <- paste0("M", 1:20) X_vars <- paste0("X", 1:3) # Full pipeline sis <- SIS(target_data, source_data, Y = "Y", D = "D", M = M_vars, X = X_vars, transfer = TRUE, topN = 10) infer <- mediation_inference(sis, M = M_vars, D = "D", X = X_vars, Y = "Y", transfer = TRUE) result <- joint_test(infer) plot(result)
Step 2 of the TransHDM pipeline: de-biased lasso estimation
following screening (SIS, Step 1). It consists of two
sub-steps:
Step 2.1 — Outcome model (beta): estimates mediator-outcome
effects by regressing the outcome Y on all retained mediators,
the exposure D, and covariates X.
Step 2.2 — Mediator models (alpha): estimates
exposure-mediator effects by regressing each mediator on D
and X.
Both steps support transfer learning. Results are passed to
joint_test (Step 3) for multiple testing.
mediation_inference( screen_result = NULL, target_data = NULL, source_data = NULL, Y = NULL, D = NULL, M = NULL, X = NULL, transfer = FALSE, verbose = TRUE, ncore = 1 )mediation_inference( screen_result = NULL, target_data = NULL, source_data = NULL, Y = NULL, D = NULL, M = NULL, X = NULL, transfer = FALSE, verbose = TRUE, ncore = 1 )
screen_result |
An object of class |
target_data |
A data frame containing the target dataset. Required
when |
source_data |
A data frame containing the source dataset (optional,
default: |
Y |
Character string specifying the outcome variable name. Required
only when |
D |
Character string specifying the exposure variable name.
Required only when |
M |
Character vector specifying the full set of mediator variable
names (before screening). Required only when |
X |
Character vector specifying covariate variable names.
Required only when |
transfer |
A logical value (default: |
verbose |
A logical value (default: |
ncore |
An integer (default: 1) specifying the number of CPU cores for parallel computation of mediator models. |
An object of class "mediation_inference" — a list with:
DE_est: Estimated direct effect of D on Y.
alpha_SIS_est: Named numeric vector of alpha estimates
(exposure-mediator effects) for all mediators in M.
Non-selected mediators are set to zero.
P_alpha_SIS: Named numeric vector of p-values for alpha.
beta_SIS_est: Named numeric vector of beta estimates
(mediator-outcome effects) for all mediators in M.
Non-selected mediators are set to zero.
P_beta_SIS: Named numeric vector of p-values for beta.
M: The full mediator name vector.
M_SIS: Mediators retained after screening.
D: The exposure variable name.
set.seed(123) target_data <- gen_simData_homo(n = 50, p_x = 3, p_m = 20, rho = 0.1)$data source_data <- gen_simData_homo(n = 100, p_x = 3, p_m = 20, rho = 0.1, source = TRUE, transferable = TRUE)$data M_vars <- paste0("M", 1:20) X_vars <- paste0("X", 1:3) # With screening (SIS) sis <- SIS(target_data, source_data, Y = "Y", D = "D", M = M_vars, X = X_vars, transfer = TRUE, topN = 10) infer <- mediation_inference(sis, transfer = TRUE) # Without screening (use all mediators directly) infer_ns <- mediation_inference( target_data = target_data, source_data = source_data, Y = "Y", D = "D", M = M_vars, X = X_vars, transfer = TRUE)set.seed(123) target_data <- gen_simData_homo(n = 50, p_x = 3, p_m = 20, rho = 0.1)$data source_data <- gen_simData_homo(n = 100, p_x = 3, p_m = 20, rho = 0.1, source = TRUE, transferable = TRUE)$data M_vars <- paste0("M", 1:20) X_vars <- paste0("X", 1:3) # With screening (SIS) sis <- SIS(target_data, source_data, Y = "Y", D = "D", M = M_vars, X = X_vars, transfer = TRUE, topN = 10) infer <- mediation_inference(sis, transfer = TRUE) # Without screening (use all mediators directly) infer_ns <- mediation_inference( target_data = target_data, source_data = source_data, Y = "Y", D = "D", M = M_vars, X = X_vars, transfer = TRUE)
S3 plot method for objects of class "source_detection".
Produces a bar chart of the -index for each source dataset, with
bars extending from a solid baseline at zero and a horizontal reference
line at the transferability threshold. Sources whose -index falls
on or below the threshold are considered transferable.
## S3 method for class 'source_detection' plot( x, fill_transferable = "white", fill_nontransferable = "white", color = "black", linewidth = 0.5, size.text = 3, show.values = TRUE, digits = 3, base_size = 12, threshold.linetype = "dashed", threshold.color = "gray30", ... )## S3 method for class 'source_detection' plot( x, fill_transferable = "white", fill_nontransferable = "white", color = "black", linewidth = 0.5, size.text = 3, show.values = TRUE, digits = 3, base_size = 12, threshold.linetype = "dashed", threshold.color = "gray30", ... )
x |
An object of class |
fill_transferable |
Fill color for transferable-source bars.
Default is |
fill_nontransferable |
Fill color for non-transferable-source bars.
Default is |
color |
Bar border color. Default is |
linewidth |
Bar border line width. Default is |
size.text |
Numeric; size of value labels on bars. Default is |
show.values |
Logical; if |
digits |
Integer; number of decimal places for displayed values.
Default is |
base_size |
Numeric; base font size passed to
|
threshold.linetype |
Linetype for the threshold reference line.
Default is |
threshold.color |
Color for the threshold reference line.
Default is |
... |
Additional arguments (currently unused). |
A ggplot object.
set.seed(123) target_data <- data.frame( Y = rnorm(200), D = rnorm(200), M1 = rnorm(200), M2 = rnorm(200), X1 = rnorm(200) ) source1 <- data.frame( Y = rnorm(300), D = rnorm(300), M1 = rnorm(300), M2 = rnorm(300), X1 = rnorm(300) ) source2 <- data.frame( Y = rnorm(250), D = rnorm(250), M1 = rnorm(250), M2 = rnorm(250), X1 = rnorm(250) ) result <- source_detection( target_data = target_data, source_data = list(source1, source2), Y = "Y", D = "D", M = c("M1", "M2"), X = "X1", kfold = 5, verbose = FALSE ) plot(result)set.seed(123) target_data <- data.frame( Y = rnorm(200), D = rnorm(200), M1 = rnorm(200), M2 = rnorm(200), X1 = rnorm(200) ) source1 <- data.frame( Y = rnorm(300), D = rnorm(300), M1 = rnorm(300), M2 = rnorm(300), X1 = rnorm(300) ) source2 <- data.frame( Y = rnorm(250), D = rnorm(250), M1 = rnorm(250), M2 = rnorm(250), X1 = rnorm(250) ) result <- source_detection( target_data = target_data, source_data = list(source1, source2), Y = "Y", D = "D", M = c("M1", "M2"), X = "X1", kfold = 5, verbose = FALSE ) plot(result)
S3 plot method for objects of class "TransHDM". Produces a bar chart
of the overall effects (indirect, direct, total, proportion mediated),
individual mediator effects, or p-values.
## S3 method for class 'TransHDM' plot( x, type = c("overall", "mediator", "pvalue", "alpha_beta"), fill = "white", color = "black", linewidth = 0.5, size.text = 3, show.values = TRUE, digits = 3, base_size = 12, label = c("significant", "all", "none"), ... )## S3 method for class 'TransHDM' plot( x, type = c("overall", "mediator", "pvalue", "alpha_beta"), fill = "white", color = "black", linewidth = 0.5, size.text = 3, show.values = TRUE, digits = 3, base_size = 12, label = c("significant", "all", "none"), ... )
x |
An object of class |
type |
Character string specifying the type of plot:
|
fill |
Bar fill color. Default is |
color |
Bar border color. Default is |
linewidth |
Bar border line width. Default is |
size.text |
Numeric; size of value labels on bars. Default is |
show.values |
Logical; if |
digits |
Integer; number of decimal places for displayed values.
Default is |
base_size |
Numeric; base font size passed to
|
label |
For |
... |
Additional arguments (currently unused). |
A ggplot object. The plot is printed
automatically when called interactively.
set.seed(123) target_data <- gen_simData_homo(n = 50, p_x = 3, p_m = 20, rho = 0.1)$data source_data <- gen_simData_homo(n = 100, p_x = 3, p_m = 20, rho = 0.1, source = TRUE, transferable = TRUE)$data result <- TransHDM( target_data = target_data, source_data = source_data, Y = "Y", D = "D", M = paste0("M", 1:20), X = paste0("X", 1:3), transfer = TRUE, ncore = 1, topN = 10 ) plot(result) plot(result, type = "mediator") plot(result, type = "pvalue") plot(result, type = "alpha_beta")set.seed(123) target_data <- gen_simData_homo(n = 50, p_x = 3, p_m = 20, rho = 0.1)$data source_data <- gen_simData_homo(n = 100, p_x = 3, p_m = 20, rho = 0.1, source = TRUE, transferable = TRUE)$data result <- TransHDM( target_data = target_data, source_data = source_data, Y = "Y", D = "D", M = paste0("M", 1:20), X = paste0("X", 1:3), transfer = TRUE, ncore = 1, topN = 10 ) plot(result) plot(result, type = "mediator") plot(result, type = "pvalue") plot(result, type = "alpha_beta")
Print method for dblasso objects
## S3 method for class 'dblasso' print(x, ...)## S3 method for class 'dblasso' print(x, ...)
x |
An object of class |
... |
Further arguments (currently not used). |
Invisibly returns x.
Print method for lasso objects
## S3 method for class 'lasso' print(x, ...)## S3 method for class 'lasso' print(x, ...)
x |
An object of class |
... |
Further arguments (currently not used). |
Invisibly returns x.
Print method for mediation_inference objects
## S3 method for class 'mediation_inference' print(x, ...)## S3 method for class 'mediation_inference' print(x, ...)
x |
An object of class |
... |
Further arguments (currently not used). |
Invisibly returns x.
Print method for SIS objects
## S3 method for class 'SIS' print(x, ...)## S3 method for class 'SIS' print(x, ...)
x |
An object of class |
... |
Further arguments (currently not used). |
Invisibly returns x.
Print method for source_detection objects
## S3 method for class 'source_detection' print(x, ...)## S3 method for class 'source_detection' print(x, ...)
x |
An object of class |
... |
Further arguments (currently not used). |
Invisibly returns x.
Displays the coefficient table from a debiased Lasso model summary. Supports fixed decimal places and scientific notation formatting.
## S3 method for class 'summary.dblasso' print(x, digits = 3, fixed = FALSE, ...)## S3 method for class 'summary.dblasso' print(x, digits = 3, fixed = FALSE, ...)
x |
An object of class |
digits |
Number of digits to display (default is 3). |
fixed |
Logical. If |
... |
Further arguments (currently not used). |
Invisibly returns x.
Print method for TransHDM objects
## S3 method for class 'TransHDM' print(x, ...)## S3 method for class 'TransHDM' print(x, ...)
x |
An object of class |
... |
Further arguments (currently not used). |
Invisibly returns x.
Step 1 of the TransHDM pipeline: dimension reduction via
Sure Independence Screening (SIS). Mediators are ranked based on the product
of their marginal associations with the exposure (alpha) and the outcome (beta),
and the top-ranked mediators are retained for downstream de-biased lasso
estimation (mediation_inference, Step 2) and joint testing
(joint_test, Step 3).
The function supports transfer learning, allowing information from a source dataset to be leveraged to improve screening stability and robustness in the target dataset.
SIS( target_data, source_data = NULL, Y, D, M, X, topN = NULL, transfer = FALSE, verbose = TRUE, ncore = 1, dblasso_method = FALSE )SIS( target_data, source_data = NULL, Y, D, M, X, topN = NULL, transfer = FALSE, verbose = TRUE, ncore = 1, dblasso_method = FALSE )
target_data |
A data frame containing the target dataset. All variables must be numeric. |
source_data |
A list of data frames containing source datasets (optional, default: NULL). All variables must be numeric and have the same column names as target_data. |
Y |
Character string specifying the outcome variable name. |
D |
Character string specifying the exposure (treatment) variable name. |
M |
Character vector specifying mediator variable names. |
X |
Character vector specifying covariate variable names. |
topN |
An integer specifying the number of mediators to retain after screening.
If |
transfer |
A logical value (default: FALSE) indicating whether to apply transfer learning by incorporating the source dataset in the screening procedure. |
verbose |
A logical value (default: TRUE) controlling whether progress messages are printed to the console. |
ncore |
An integer (default: 1) specifying the number of CPU cores for parallel computation. |
dblasso_method |
A logical value (default: FALSE). If TRUE, the debiased lasso (dblasso) is used to estimate marginal effects. If FALSE, standard linear or generalized linear models are used. |
A list of class "SIS" with the following components:
target_SIS: A data frame containing the outcome, exposure, selected
mediators, and covariates from the target dataset.
source_SIS: A data frame containing the same variables from the source
dataset if transfer = TRUE; otherwise NULL.
M_ID_name_SIS: A character vector of selected mediator names.
Y: The resolved outcome variable name.
D: The resolved exposure variable name.
M: The full mediator variable names (before screening).
X: The resolved covariate variable names.
TransHDM, mediation_inference,
joint_test
set.seed(123) # Target data M_target <- matrix(rnorm(200 * 50), nrow = 200) colnames(M_target) <- paste0("M", 1:50) target_data <- data.frame( Y = rnorm(200), D = rnorm(200), M_target, X1 = rnorm(200) ) # Source data M_source <- matrix(rnorm(300 * 50), nrow = 300) colnames(M_source) <- paste0("M", 1:50) source_data <- data.frame( Y = rnorm(300), D = rnorm(300), M_source, X1 = rnorm(300) ) # Run SIS result <- SIS( target_data = target_data, source_data = source_data, Y = "Y", D = "D", M = paste0("M", 1:50), X = "X1", transfer = TRUE, topN = 10 ) result$M_ID_name_SISset.seed(123) # Target data M_target <- matrix(rnorm(200 * 50), nrow = 200) colnames(M_target) <- paste0("M", 1:50) target_data <- data.frame( Y = rnorm(200), D = rnorm(200), M_target, X1 = rnorm(200) ) # Source data M_source <- matrix(rnorm(300 * 50), nrow = 300) colnames(M_source) <- paste0("M", 1:50) source_data <- data.frame( Y = rnorm(300), D = rnorm(300), M_source, X1 = rnorm(300) ) # Run SIS result <- SIS( target_data = target_data, source_data = source_data, Y = "Y", D = "D", M = paste0("M", 1:50), X = "X1", transfer = TRUE, topN = 10 ) result$M_ID_name_SIS
Determines whether external source datasets can be effectively transferred to the target data by comparing predictive performance using LASSO regression under a transfer learning framework.
source_detection( target_data, source_data = NULL, Y, D, M, X, kfold = 5, t = 0.02, verbose = TRUE )source_detection( target_data, source_data = NULL, Y, D, M, X, kfold = 5, t = 0.02, verbose = TRUE )
target_data |
A data frame containing the target dataset. All variables must be numeric. |
source_data |
A list of data frames containing source datasets (optional, default: NULL). All variables must be numeric and have the same column names as target_data. |
Y |
Character string specifying the outcome variable name. |
D |
Character string specifying the exposure (treatment) variable name. |
M |
Character vector specifying mediator variable names. |
X |
Character vector specifying covariate variable names. |
kfold |
Integer (default: 5). Number of folds for cross-validation. |
t |
Numeric (default: 0.02). Threshold constant for determining transferability. Larger values make the criterion more lenient. |
verbose |
Logical (default: TRUE). Whether to print progress messages. |
A list containing:
transfer.source.id: Indices of source datasets deemed transferable
source.loss: Mean validation loss for each source dataset
target.valid.loss: Mean validation loss using target-only model
T_index: Difference between source loss and target-only loss for each source
threshold: Calculated transferability threshold
loss.cv: Full k-fold cross-validation loss matrix
## Reproducible example set.seed(123) # Generate synthetic target data target_data <- data.frame( Y = rnorm(200), D = rnorm(200), M1 = rnorm(200), M2 = rnorm(200), X1 = rnorm(200) ) # Generate synthetic source data source1 <- data.frame( Y = rnorm(300), D = rnorm(300), M1 = rnorm(300), M2 = rnorm(300), X1 = rnorm(300) ) source2 <- data.frame( Y = rnorm(250), D = rnorm(250), M1 = rnorm(250), M2 = rnorm(250), X1 = rnorm(250) ) # Run source detection result <- source_detection( target_data = target_data, source_data = list(source1, source2), Y = "Y", D = "D", M = c("M1", "M2"), X = "X1", kfold = 5, t = 0.05, verbose = FALSE ) # Get Summary summary(result) # Transferable source indices result$transfer.source.id # Compare validation losses data.frame( Source = c(paste0("Source", seq_along(result$source.loss)), "Target"), Loss = c(result$source.loss, result$target.valid.loss) )## Reproducible example set.seed(123) # Generate synthetic target data target_data <- data.frame( Y = rnorm(200), D = rnorm(200), M1 = rnorm(200), M2 = rnorm(200), X1 = rnorm(200) ) # Generate synthetic source data source1 <- data.frame( Y = rnorm(300), D = rnorm(300), M1 = rnorm(300), M2 = rnorm(300), X1 = rnorm(300) ) source2 <- data.frame( Y = rnorm(250), D = rnorm(250), M1 = rnorm(250), M2 = rnorm(250), X1 = rnorm(250) ) # Run source detection result <- source_detection( target_data = target_data, source_data = list(source1, source2), Y = "Y", D = "D", M = c("M1", "M2"), X = "X1", kfold = 5, t = 0.05, verbose = FALSE ) # Get Summary summary(result) # Transferable source indices result$transfer.source.id # Compare validation losses data.frame( Source = c(paste0("Source", seq_along(result$source.loss)), "Target"), Loss = c(result$source.loss, result$target.valid.loss) )
Summary of Debiased Lasso Inference
## S3 method for class 'dblasso' summary(object, ...)## S3 method for class 'dblasso' summary(object, ...)
object |
An object of class |
... |
Further arguments (currently not used). |
An object of class "summary.dblasso".
Summary of Lasso Regression
## S3 method for class 'lasso' summary(object, ...)## S3 method for class 'lasso' summary(object, ...)
object |
A numeric vector of lasso coefficients with names. |
... |
Further arguments (currently not used). |
An object of class "summary.lasso".
Summary of Mediation Inference
## S3 method for class 'mediation_inference' summary(object, top = 10, digits = 4, ...)## S3 method for class 'mediation_inference' summary(object, top = 10, digits = 4, ...)
object |
An object of class |
top |
Integer, maximum number of mediators to display (default: 10). |
digits |
Number of digits for rounding estimates (default: 4). |
... |
Further arguments (unused). |
An object of class "summary.mediation_inference".
Summary of Source Detection Results
## S3 method for class 'source_detection' summary(object, ...)## S3 method for class 'source_detection' summary(object, ...)
object |
An object of class |
... |
Further arguments (unused). |
An object of class "summary.source_detection".
Summary of TransHDM Mediation Analysis
## S3 method for class 'TransHDM' summary(object, top = 10, digits = 4, ...)## S3 method for class 'TransHDM' summary(object, top = 10, digits = 4, ...)
object |
An object of class |
top |
Integer, maximum number of mediators to display. |
digits |
Number of digits for rounding estimates. |
... |
Further arguments (unused). |
An object of class "summary.TransHDM".
The TransHDM function performs high-dimensional mediation analysis
under a transfer learning framework. It identifies and estimates indirect
(mediation) effects of a high-dimensional set of mediators between an
exposure and an outcome by integrating a target dataset and a source datasets.
TransHDM( target_data, source_data = NULL, Y, D, M, X, transfer = FALSE, verbose = TRUE, ncore = 1, topN = NULL, use_SIS = TRUE, dblasso_SIS = FALSE, p_cutoff = 0.05 )TransHDM( target_data, source_data = NULL, Y, D, M, X, transfer = FALSE, verbose = TRUE, ncore = 1, topN = NULL, use_SIS = TRUE, dblasso_SIS = FALSE, p_cutoff = 0.05 )
target_data |
A data frame containing the target dataset. All variables must be numeric. |
source_data |
A list of data frames containing source datasets (optional, default: NULL). All variables must be numeric and have the same column names as target_data. |
Y |
Character string specifying the outcome variable name. |
D |
Character string specifying the exposure (treatment) variable name. |
M |
Character vector specifying mediator variable names. |
X |
Character vector specifying covariate variable names.. |
transfer |
A logical value (default: |
verbose |
A logical value (default: |
ncore |
An integer (default: 1) specifying the number of CPU cores to use for parallel computation when fitting mediator models. |
topN |
An integer (default: |
use_SIS |
A logical value (default: |
dblasso_SIS |
A logical value (default: |
p_cutoff |
A numeric value (default: 0.05) specifying the maximum p-value threshold for determining significant mediators. |
TransHDM implements a three-step workflow that can also be executed
step-by-step using the individual components:
Step 1 — Screening: SIS performs Sure
Independence Screening to reduce dimensionality by ranking mediators
based on their marginal associations.
Step 2 — De-biased estimation:
mediation_inference fits de-biased lasso models to
estimate exposure-mediator (alpha) and mediator-outcome (beta) effects.
Step 3 — Multiple testing: joint_test
applies joint multiple testing with FDR control to identify
significant mediators and computes effect summaries.
Set use_SIS = FALSE to skip Step 1 and use all mediators directly.
A list with the following components:
contributions: A data frame of identified mediators containing:
mediator: Mediator name
alpha: Estimated exposure mediator effect
alpha_pv: P-value for the exposure mediator effect
beta: Estimated mediator outcome effect
beta_pv: P-value for the mediator outcome effect
alpha_beta: Estimated indirect (mediation) effect
ab_pv: Joint p-value for the indirect effect
pa: Proportion of the total effect mediated
effects: A data frame summarizing the total indirect effect,
direct effect, total effect, and proportion mediated.
IDE_est: A numeric vector of indirect effect estimates for all
specified mediators, with non-selected mediators set to zero.
DE_est: The estimated direct effect of the exposure on the
outcome.
all_mediators: A data frame of all SIS-screened mediators
(including non-significant ones) with columns mediator,
alpha, alpha_pv, beta, beta_pv, and
significant (logical).
Pan L, Liu Y, Huang C, Lin R, Yu Y, Qin G. Transfer learning reveals the mediating mechanisms of cross-ethnic lipid metabolic pathways in the association between APOE gene and Alzheimer's disease. Brief Bioinform. 2025;26(5):bbaf460. doi:10.1093/bib/bbaf460
SIS, mediation_inference,
joint_test
set.seed(123) # Target data target_data <- gen_simData_homo(n = 50, p_x = 3, p_m = 20, rho = 0.1)$data # Source data source_data <- gen_simData_homo(n = 100, p_x = 3, p_m = 20, rho = 0.1, source = TRUE, transferable = TRUE)$data # Run TransHDM result <- TransHDM( target_data = target_data, source_data = source_data, Y = "Y", D = "D", M = paste0("M", 1:20), X = paste0("X", 1:3), transfer = TRUE, ncore = 1, topN = 10 ) summary(result)set.seed(123) # Target data target_data <- gen_simData_homo(n = 50, p_x = 3, p_m = 20, rho = 0.1)$data # Source data source_data <- gen_simData_homo(n = 100, p_x = 3, p_m = 20, rho = 0.1, source = TRUE, transferable = TRUE)$data # Run TransHDM result <- TransHDM( target_data = target_data, source_data = source_data, Y = "Y", D = "D", M = paste0("M", 1:20), X = paste0("X", 1:3), transfer = TRUE, ncore = 1, topN = 10 ) summary(result)