| Title: | High-Dimensional Mediation Analysis via Transfer Learning |
| Version: | 1.1.3 |
| 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>. |
| License: | GPL (≥ 3) |
| URL: | https://github.com/Gaohuer/TransHDM |
| Encoding: | UTF-8 |
| Depends: | R (≥ 4.0.0) |
| Imports: | glmnet (≥ 4.1-10), caret (≥ 7.0-1), MASS (≥ 7.3-61), doParallel (≥ 1.0.17), foreach (≥ 1.5.2), HDMT (≥ 1.0.5), ggplot2 (≥ 3.4.0) |
| Suggests: | knitr (≥ 1.50), rmarkdown (≥ 2.30), spelling (≥ 2.3.2), dplyr (≥ 1.0.0), tidyr (≥ 1.0.0), ggrepel (≥ 0.9.0) |
| Language: | en-US |
| VignetteBuilder: | knitr |
| LazyData: | true |
| Config/roxygen2/version: | 8.0.0 |
| NeedsCompilation: | no |
| Packaged: | 2026-08-17 03:29:33 UTC; ceesuu |
| Author: | Huer Gao [aut, cre, cph], Lulu Pan [aut, cph], Yongfu Yu [ctb, cph], Guoyou Qin [ctb, cph] |
| Maintainer: | Huer Gao <26111020050@m.fudan.edu.cn> |
| Repository: | CRAN |
| Date/Publication: | 2026-08-20 22:52:14 UTC |
Sure Independence Screening for High-Dimensional Mediation Analysis
Description
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.
Usage
SIS(
target_data,
source_data = NULL,
Y,
D,
M,
X,
topN = NULL,
transfer = FALSE,
verbose = TRUE,
ncore = 1,
dblasso_method = FALSE
)
Arguments
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. |
Value
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 iftransfer = TRUE; otherwiseNULL. -
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.
See Also
TransHDM, mediation_inference,
joint_test
Examples
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_SIS
TransHDM: High-Dimensional Mediation Analysis with Transfer Learning
Description
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.
Usage
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
)
Arguments
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. |
Details
TransHDM implements a three-step workflow that can also be executed
step-by-step using the individual components:
-
Step 1 — Screening:
SISperforms Sure Independence Screening to reduce dimensionality by ranking mediators based on their marginal associations. -
Step 2 — De-biased estimation:
mediation_inferencefits de-biased lasso models to estimate exposure-mediator (alpha) and mediator-outcome (beta) effects. -
Step 3 — Multiple testing:
joint_testapplies 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.
Value
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 columnsmediator,alpha,alpha_pv,beta,beta_pv, andsignificant(logical).
References
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
See Also
SIS, mediation_inference,
joint_test
Examples
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)
Fit Debiased LASSO with Transfer Learning
Description
Fits a debiased LASSO regression model under transfer learning framework, supporting feature selection and coefficient estimation by combining target and source data.
Usage
dblasso(
target,
source = NULL,
transfer = FALSE,
level = 0.95,
lambda = "lambda.1se"
)
Arguments
target |
A list containing two elements:
Required. |
source |
A list (optional, default: NULL) containing two elements:
Used when transfer = TRUE. |
transfer |
A logical value (default: FALSE) indicating whether to enable transfer learning (combining source data with target data for estimation). |
level |
A numeric value (default: 0.95) specifying confidence level for confidence intervals. |
lambda |
A string specifying criterion for selecting regularization parameter:
|
Value
A list containing:
dbcoef.hat: Debiased LASSO coefficient vector (including intercept)
coef.hat: Original LASSO coefficient vector
CI: Data frame with confidence intervals (lb = lower bound, ub = upper bound)
var.est: Variance estimates for debiased coefficients
se.est: Standard errors for debiased coefficients
P.value: Vector of p-values for coefficients
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 dimensionn × (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
)
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 homogeneous settings for data generation.
Usage
gen_simData_homo(
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 dimensionn * (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_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
)
Inflammatory Mediation Benchmark Data: Ground Truth Effects
Description
Ground-truth mediation effects for the target cohort of the inflammatory
mediation benchmark dataset. Maps each candidate mediator to its true
exposure–mediator effect (\alpha), mediator–outcome effect
(\beta), and indirect effect (\alpha \times \beta).
Usage
data(inflam_effect)
Format
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.
Details
Four mediators have non-zero \alpha \times \beta 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.
See Also
inflam_target, inflam_external1,
inflam_external2 for the associated cohorts.
Examples
data(inflam_effect)
inflam_effect[inflam_effect$alpha_beta != 0, ]
Inflammatory Mediation Benchmark Data: Transferable External Cohort
Description
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.
Usage
data(inflam_external1)
Format
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.
Details
This large external cohort (n = 200) is generated under a transferable
setting: its exposure–mediator (\alpha) and mediator–outcome
(\beta) coefficients match those of the target for the active
mediators. It is intended as the source in TransHDM with
transfer = TRUE.
Note
Demonstration data only. Simulated for methodological demonstration of
the TransHDM workflow.
Source
Generated with gen_simData_homo (n = 200, p_x = 3, p_m = 20,
rho = 0.1, seed = 123, source = TRUE, transferable = TRUE).
See Also
inflam_target for the target cohort, inflam_external2
for the non-transferable external cohort.
Examples
data(inflam_external1)
str(inflam_external1)
Inflammatory Mediation Benchmark Data: Non-Transferable External Cohort
Description
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.
Usage
data(inflam_external2)
Format
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.
Details
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.
Note
Demonstration data only. Simulated for methodological demonstration of
the TransHDM workflow.
Source
Generated with gen_simData_hetero (n = 100, p_x = 3, p_m = 20,
rho = 0.1, seed = 999, source = TRUE, transferable = FALSE).
See Also
inflam_target for the target cohort, inflam_external1
for the transferable external cohort.
Examples
data(inflam_external2)
str(inflam_external2)
Inflammatory Mediation Benchmark Data: Target Cohort
Description
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.
Usage
data(inflam_target)
Format
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 (cytokinesCYT, immune markersIMM, oxidative stressOXI, metabolicMET, signallingSIG). -
BIS,PRS,BRS: 3 covariates (baseline inflammatory status, physiological reserve score, baseline risk score).
Details
Mediation model:
IB \rightarrow Molecular\ Mediators \rightarrow DSI
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.
Note
Demonstration data only. Simulated for methodological demonstration of
the TransHDM workflow, not for drawing biological conclusions.
Source
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.
See Also
inflam_external1, inflam_external2 for the
external cohorts, and inflam_effect for the ground truth.
Examples
data(inflam_target)
str(inflam_target)
Joint Multiple Testing for Mediation Analysis
Description
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.
Usage
joint_test(inference_result, p_cutoff = 0.05, verbose = TRUE)
Arguments
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: |
Value
An object of class "TransHDM" — a list with:
-
contributions: Data frame of identified mediators with columnsmediator,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 columnsmediator,alpha,alpha_pv,beta,beta_pv,significant(logical).
See Also
TransHDM, mediation_inference, SIS
Examples
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)
K-Fold Cross-Validation Data Splitting
Description
Splits input data into k folds for cross-validation, generating training and test sets for each fold. Particularly useful for mediator selection stability assessment in high-dimensional mediation analysis.
Usage
kfold_split(data, kfold = 3)
Arguments
data |
A data frame or matrix containing the dataset to be split. Rows represent observations, columns represent variables. |
kfold |
Integer (default: 3). Number of folds for cross-validation. Must be >= 2 and <= nrow(data). |
Value
A list containing two elements:
train_set: List of length kfold, each element is a training subset
test_set: List of length kfold, each element is the corresponding test subset
Fit LASSO Regression with Transfer Learning
Description
Fits a LASSO (Least Absolute Shrinkage and Selection Operator) regression model under a transfer learning framework. Supports feature selection and coefficient estimation by combining target data and source data.
Usage
lasso(target, source = NULL, transfer = FALSE, lambda = "lambda.1se")
Arguments
target |
A list containing two elements:
Required. |
source |
A list (optional, default: NULL) containing two elements:
Used when transfer = TRUE. |
transfer |
A logical value (default: FALSE) indicating whether to enable transfer learning mode (combine source data with target data). |
lambda |
A string (default: 'lambda.1se') specifying the criterion for selecting regularization parameter:
|
Value
A numeric vector coef containing LASSO coefficient estimates (including intercept).
Mediation Inference via De-biased Lasso
Description
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
Yon all retained mediators, the exposureD, and covariatesX. -
Step 2.2 — Mediator models (alpha): estimates exposure-mediator effects by regressing each mediator on
DandX.
Both steps support transfer learning. Results are passed to
joint_test (Step 3) for multiple testing.
Usage
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
)
Arguments
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. |
Value
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 inM. 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 inM. 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.
See Also
Examples
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)
Estimate Null Proportion in Joint Mediation Analysis
Description
Estimates the proportion of null hypotheses in dual-stage mediation analysis using empirical p-value distributions. This implements the statistical framework for estimating the proportion of non-mediating variables.
Usage
null_estimation(input_pvalues, lambda = 0.5)
Arguments
input_pvalues |
A numeric matrix with 2 columns:
|
lambda |
Threshold parameter (default: 0.5) for stable estimation of pi00 (proportion of double nulls). Should be in (0,1), typically 0.5 as recommended in literature. |
Value
A list containing estimated null proportions:
alpha00: Proportion of mediators with null effects in both exposure-mediator and mediator-outcome paths
alpha10: Proportion with non-null exposure-mediator but null mediator-outcome effects
alpha01: Proportion with null exposure-mediator but non-null mediator-outcome effects
alpha1: Marginal null proportion in exposure-mediator path
alpha2: Marginal null proportion in mediator-outcome path
Visualize TransHDM Mediation Analysis Results
Description
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.
Usage
## 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"),
...
)
Arguments
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). |
Value
A ggplot object. The plot is printed
automatically when called interactively.
Examples
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")
Visualize Source Detection Results
Description
S3 plot method for objects of class "source_detection".
Produces a bar chart of the T-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 T-index falls
on or below the threshold are considered transferable.
Usage
## 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",
...
)
Arguments
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). |
Value
A ggplot object.
See Also
Examples
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)
Print method for SIS objects
Description
Print method for SIS objects
Usage
## S3 method for class 'SIS'
print(x, ...)
Arguments
x |
An object of class |
... |
Further arguments (currently not used). |
Value
Invisibly returns x.
Print method for TransHDM objects
Description
Print method for TransHDM objects
Usage
## S3 method for class 'TransHDM'
print(x, ...)
Arguments
x |
An object of class |
... |
Further arguments (currently not used). |
Value
Invisibly returns x.
Print method for dblasso objects
Description
Print method for dblasso objects
Usage
## S3 method for class 'dblasso'
print(x, ...)
Arguments
x |
An object of class |
... |
Further arguments (currently not used). |
Value
Invisibly returns x.
Print method for lasso objects
Description
Print method for lasso objects
Usage
## S3 method for class 'lasso'
print(x, ...)
Arguments
x |
An object of class |
... |
Further arguments (currently not used). |
Value
Invisibly returns x.
Print method for mediation_inference objects
Description
Print method for mediation_inference objects
Usage
## S3 method for class 'mediation_inference'
print(x, ...)
Arguments
x |
An object of class |
... |
Further arguments (currently not used). |
Value
Invisibly returns x.
Print method for source_detection objects
Description
Print method for source_detection objects
Usage
## S3 method for class 'source_detection'
print(x, ...)
Arguments
x |
An object of class |
... |
Further arguments (currently not used). |
Value
Invisibly returns x.
Print method for summary.dblasso objects
Description
Displays the coefficient table from a debiased Lasso model summary. Supports fixed decimal places and scientific notation formatting.
Usage
## S3 method for class 'summary.dblasso'
print(x, digits = 3, fixed = FALSE, ...)
Arguments
x |
An object of class |
digits |
Number of digits to display (default is 3). |
fixed |
Logical. If |
... |
Further arguments (currently not used). |
Value
Invisibly returns x.
Detect Transferable Source Data via Cross-Validation
Description
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.
Usage
source_detection(
target_data,
source_data = NULL,
Y,
D,
M,
X,
kfold = 5,
t = 0.02,
verbose = TRUE
)
Arguments
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. |
Value
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
Examples
## 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 TransHDM Mediation Analysis
Description
Summary of TransHDM Mediation Analysis
Usage
## S3 method for class 'TransHDM'
summary(object, top = 10, digits = 4, ...)
Arguments
object |
An object of class |
top |
Integer, maximum number of mediators to display. |
digits |
Number of digits for rounding estimates. |
... |
Further arguments (unused). |
Value
An object of class "summary.TransHDM".
Summary of Debiased Lasso Inference
Description
Summary of Debiased Lasso Inference
Usage
## S3 method for class 'dblasso'
summary(object, ...)
Arguments
object |
An object of class |
... |
Further arguments (currently not used). |
Value
An object of class "summary.dblasso".
Summary of Lasso Regression
Description
Summary of Lasso Regression
Usage
## S3 method for class 'lasso'
summary(object, ...)
Arguments
object |
A numeric vector of lasso coefficients with names. |
... |
Further arguments (currently not used). |
Value
An object of class "summary.lasso".
Summary of Mediation Inference
Description
Summary of Mediation Inference
Usage
## S3 method for class 'mediation_inference'
summary(object, top = 10, digits = 4, ...)
Arguments
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). |
Value
An object of class "summary.mediation_inference".
Summary of Source Detection Results
Description
Summary of Source Detection Results
Usage
## S3 method for class 'source_detection'
summary(object, ...)
Arguments
object |
An object of class |
... |
Further arguments (unused). |
Value
An object of class "summary.source_detection".