TransHDM provides a framework for high-dimensional
mediation analysis using transfer learning. It integrates external
source datasets to improve the detection power of potential mediators in
small-sample target studies, addressing data heterogeneity via transfer
regularization and debiased estimation.
The package includes the simulated inflammatory mediation benchmark dataset with one target cohort and two external cohorts:
inflam_target — target cohort (n = 50)inflam_external1 — transferable external cohort
(n = 200)inflam_external2 — non-transferable external cohort
(n = 100)inflam_effect — ground-truth mediation effectsThe exposure is an inflammatory biomarker (IB) and the
outcome is a disease severity index (DSI); the 20 candidate
mediators are molecular markers across five functional groups. The
mediator columns were randomly permuted during generation, so the
identity of the truly active mediators is hidden.
library(TransHDM)
data(inflam_target)
data(inflam_external1)
data(inflam_external2)
data(inflam_effect)
target <- inflam_target
source <- inflam_external1
source_nt <- inflam_external2
outcome_var <- "DSI" # disease severity index (outcome)
exposure_var <- "IB" # inflammatory biomarker (exposure)
X_vars <- c("BIS", "PRS", "BRS")
M_vars <- setdiff(colnames(target),
c(outcome_var, exposure_var, X_vars))
## ground truth effect (target cohort)
inflam_effect
#> mediator alpha beta alpha_beta
#> 1 CYT_01 0.00 0.00 0.0000
#> 2 CYT_02 0.00 0.00 0.0000
#> 3 CYT_03 0.00 0.00 0.0000
#> 4 CYT_04 0.00 0.00 0.0000
#> 5 IMM_01 0.50 0.50 0.2500
#> 6 IMM_02 0.00 0.00 0.0000
#> 7 IMM_03 0.65 0.45 0.2925
#> 8 IMM_04 0.00 0.00 0.0000
#> 9 OXI_01 0.55 0.45 0.2475
#> 10 OXI_02 0.00 0.35 0.0000
#> 11 OXI_03 0.00 0.00 0.0000
#> 12 OXI_04 0.60 0.40 0.2400
#> 13 MET_01 0.35 0.00 0.0000
#> 14 MET_02 0.00 0.00 0.0000
#> 15 MET_03 0.00 0.00 0.0000
#> 16 MET_04 0.00 0.00 0.0000
#> 17 SIG_01 0.00 0.00 0.0000
#> 18 SIG_02 0.30 0.00 0.0000
#> 19 SIG_03 0.00 0.25 0.0000
#> 20 SIG_04 0.00 0.00 0.0000Identify which source datasets are transferable to the target
population. print() gives a concise one-line summary, while
summary() provides the detailed decision table:
set.seed(123)
detect <- source_detection(target_data = target,
source_data = list(source, source_nt),
Y = outcome_var, D = exposure_var, M = M_vars, X = X_vars)
#> Transfer candidate sources: 1
print(detect)
#> Source detection: 1/2 sources transferable
summary(detect)
#> Source detection summary
#> ------------------------
#> Number of sources: 2
#> Number of transferable sources: 1
#>
#> Target validation loss:
#> mean = 17.3819
#>
#> Threshold:
#> 0.3476
#>
#> Source-wise comparison:
#> Source SourceLoss T_index Transferable
#> 1 15.1041 -2.2779 YES
#> 2 18.7355 1.3536 NOVisualization of the source detection results can be done using the
plot() function:
TransHDM()The TransHDM() function provides an end-to-end analysis
in one call:
# With transfer learning
set.seed(123)
result_tl <- TransHDM(
target_data = target,
source_data = source,
Y = outcome_var, D = exposure_var,
M = M_vars, X = X_vars,
transfer = TRUE,
topN = 10, p_cutoff = 0.01
)
#> Step 1: Sure Independence Screening ... (11:29:26)
#> Top 10 mediators selected: IMM_03, OXI_04, IMM_01, OXI_01, MET_01, SIG_02, CYT_01, CYT_02, CYT_03, CYT_04 (11:29:27)
#> After SIS, 10 / 20 mediators are retained.
#> Step 2: De-biased Lasso Estimates ... (11:29:27)
#> Estimation of mediator-outcome effects in the outcome model completed.
#> Estimation of exposure-mediator effects in the mediator model completed.
#> Step 3: Multiple-testing procedure ... (11:29:28)
#> Identified mediator(s): IMM_01, IMM_03, OXI_01, OXI_04
print(result_tl)
#> TransHDM: 4 mediator(s) | TE=2.0067 | IDE=1.0558 | DE=0.9509 | PE=52.61%
# summary(result_tl)# Without transfer learning (target only)
set.seed(123)
result_nt <- TransHDM(
target_data = target,
Y = outcome_var, D = exposure_var,
M = M_vars, X = X_vars,
transfer = FALSE,
topN = 10, p_cutoff = 0.01
)
#> Step 1: Sure Independence Screening ... (11:29:28)
#> Top 10 mediators selected: OXI_01, IMM_01, OXI_04, IMM_03, MET_01, CYT_01, CYT_02, CYT_03, CYT_04, IMM_02 (11:29:29)
#> After SIS, 10 / 20 mediators are retained.
#> Step 2: De-biased Lasso Estimates ... (11:29:29)
#> Estimation of mediator-outcome effects in the outcome model completed.
#> Estimation of exposure-mediator effects in the mediator model completed.
#> Step 3: Multiple-testing procedure ... (11:29:29)
#> Identified mediator(s): IMM_01, IMM_03, OXI_01, OXI_04, MET_01
print(result_nt)
#> TransHDM: 5 mediator(s) | TE=2.9371 | IDE=1.7442 | DE=1.1929 | PE=59.39%
summary(result_nt)
#> ====================================================
#> Summary of TransHDM Mediation Analysis
#> ====================================================
#>
#> Overall Effects:
#> effect estimate
#> indirect 1.7442
#> direct 1.1929
#> total 2.9371
#> pe 0.5939
#>
#> Identified Mediators:
#> Number of selected mediators: 5
#>
#> Top 5 mediators by |alpha * beta|:
#>
#> mediator alpha alpha_pv beta beta_pv alpha_beta ab_pv pa
#> IMM_01 0.6709 2.8265e-08 0.6836 4.3975e-12 0.4586 2.8265e-08 0.1562
#> OXI_04 0.6473 1.0569e-07 0.6086 1.1208e-07 0.3939 1.1208e-07 0.1341
#> IMM_03 0.7014 1.5277e-08 0.5468 8.5240e-10 0.3835 1.5277e-08 0.1306
#> OXI_01 0.6797 1.8581e-08 0.5511 5.6821e-08 0.3746 5.6821e-08 0.1275
#> MET_01 0.5199 2.2920e-05 0.2570 1.1885e-02 0.1336 1.1885e-02 0.0455
#>
#> Note:
#> alpha: exposure-mediator effect
#> beta : mediator-outcome effect
#> pa : proportion of total effect explained
#> P-values are shown in scientific notation
#>
#> ====================================================Reduce dimensionality by filtering candidate mediators:
set.seed(123)
sis <- SIS(
target_data = target, source_data = source,
Y = outcome_var, D = exposure_var, M = M_vars, X = X_vars,
transfer = TRUE, topN = 10, ncore = 1
)
#> Step 1: Sure Independence Screening ... (11:29:30)
#> Top 10 mediators selected: IMM_03, OXI_04, IMM_01, OXI_01, MET_01, SIG_02, CYT_01, CYT_02, CYT_03, CYT_04 (11:29:31)
print(sis)
#> SIS: 10/20 mediators retained (transfer)
summary(sis)
#>
#> Sure Independence Screening (SIS) summary
#> ----------------------------------------
#> Selected mediators:
#> Number selected: 10
#> Names: IMM_03, OXI_04, IMM_01, OXI_01, MET_01, SIG_02, CYT_01, CYT_02, CYT_03,
#> CYT_04
#>
#> Target data after SIS:
#> Sample size (n): 50
#>
#> Source data after SIS:
#> Sample size (n): 200
#>
#> Transfer learning: YES
#> ----------------------------------------Estimate exposure-mediator and mediator-outcome effects:
med_effect <- mediation_inference(
screen_result = sis,
transfer = TRUE
)
#> After screening, 10 / 20 mediators are retained.
#> Step 2: De-biased Lasso Estimates ... (11:29:31)
#> Estimation of mediator-outcome effects in the outcome model completed.
#> Estimation of exposure-mediator effects in the mediator model completed.
print(med_effect)
#> Mediation inference: 10 mediators tested | DE = 0.9509
summary(med_effect, top = 10)
#> ====================================================
#> Summary of Mediation Estimation and Testing
#> ====================================================
#>
#> Mediators:
#> Total specified: 20
#> Retained after screening: 10
#>
#> Direct Effect (DE):
#> DE_est = 0.9509
#>
#> Top 10 mediators by |alpha * beta|:
#>
#> mediator alpha alpha_pv beta beta_pv alpha_beta
#> IMM_01 0.5387 7.2396e-06 0.5770 6.3782e-07 0.3109
#> IMM_03 0.6099 6.0300e-07 0.4523 9.4337e-06 0.2759
#> OXI_04 0.5264 1.1674e-05 0.4808 1.5559e-05 0.2531
#> OXI_01 0.5207 2.4115e-05 0.4147 1.3012e-04 0.2159
#> MET_01 0.4773 7.0472e-05 0.1779 1.2422e-01 0.0849
#> SIG_02 0.5475 6.1962e-06 0.1010 3.6243e-01 0.0553
#> CYT_01 -0.0990 4.1380e-01 0.1563 1.9403e-01 -0.0155
#> CYT_03 -0.0440 7.1891e-01 0.0855 4.9918e-01 -0.0038
#> CYT_04 0.0429 7.2547e-01 -0.0447 7.0832e-01 -0.0019
#> CYT_02 0.1208 3.2723e-01 0.0027 9.8387e-01 0.0003
#>
#> Note:
#> alpha : exposure-mediator effect
#> beta : mediator-outcome effect
#> P-values are shown in scientific notation
#>
#> ====================================================Do effect estimation and inference directly from the source and target data without SIS:
Identify significant mediators through joint multiple testing:
jt <- joint_test(
inference_result = med_effect,
p_cutoff = 0.05
)
#> Step 3: Multiple-testing procedure ... (11:29:32)
#> Identified mediator(s): IMM_01, IMM_03, OXI_01, OXI_04, MET_01
print(jt)
#> TransHDM: 5 mediator(s) | TE=2.0916 | IDE=1.1407 | DE=0.9509 | PE=54.54%
summary(jt)
#> ====================================================
#> Summary of TransHDM Mediation Analysis
#> ====================================================
#>
#> Overall Effects:
#> effect estimate
#> indirect 1.1407
#> direct 0.9509
#> total 2.0916
#> pe 0.5454
#>
#> Identified Mediators:
#> Number of selected mediators: 5
#>
#> Top 5 mediators by |alpha * beta|:
#>
#> mediator alpha alpha_pv beta beta_pv alpha_beta ab_pv pa
#> IMM_01 0.5387 7.2396e-06 0.5770 6.3782e-07 0.3109 7.2396e-06 0.1486
#> IMM_03 0.6099 6.0300e-07 0.4523 9.4337e-06 0.2759 9.4337e-06 0.1319
#> OXI_04 0.5264 1.1674e-05 0.4808 1.5559e-05 0.2531 1.5559e-05 0.1210
#> OXI_01 0.5207 2.4115e-05 0.4147 1.3012e-04 0.2159 1.3012e-04 0.1032
#> MET_01 0.4773 7.0472e-05 0.1779 1.2422e-01 0.0849 1.2422e-01 0.0406
#>
#> Note:
#> alpha: exposure-mediator effect
#> beta : mediator-outcome effect
#> pa : proportion of total effect explained
#> P-values are shown in scientific notation
#>
#> ====================================================