Double shrinkage transfer causal learning: An application to alzheimer's disease.
3 blocks of code here have a permanent identifier (oscr:b:…), listed with the matches below: citable for good, with a page of its own. Select a match and press Cite to copy it. What a block identifier is.
The 5 matches · 2 of them tie a paragraph to a whole file without given lines: weak matches, whose lines are not tinted
- [1] § 2. Materials and methods › 2.3. Proposed method › 2.3.3 Estimation of causal effect. ↔ simulate_dstcl_main.R, lines 156 to 206 · score 0.70 · l1 regularized, lambda.min, lambda.1se, error, alpha, glmnet · block
oscr:b:GH9QNQBMSSG9G-Y· Report a mismatch - [2] § 2. Materials and methods › 2.3. Proposed method › 2.3.3 Estimation of causal effect. ↔ real_data_analysis_template.R, lines 334 to 393 · score 0.64 · lambda.min, lambda.1se, deviance, fold, binomial, alpha · block
oscr:b:WM4P69WTM3KPZ-1· Report a mismatch - [3] § 3. Simulation › 3.3. Simulation results ↔ glmtrans.R, the whole file · a weak match · score 0.54 · lambda.min, lambda.1se, penalty, bias, fit · block
oscr:b:MAT9FQPDWSWV3-6· Report a mismatch - [4] § 3. Simulation › 3.3. Simulation results ↔ simulate_dstcl_main.R, lines 156 to 206 · score 0.53 · lambda.min, lambda.1se, penalty, fit, DSTCL, Simulation · block
oscr:b:GH9QNQBMSSG9G-Y· Report a mismatch - [5] § 3. Simulation › 3.2. Simulation scenarios ↔ glmtrans.R, the whole file · a weak match · score 0.50 · lambda.min, lambda.1se, penalty · block
oscr:b:MAT9FQPDWSWV3-6· Report a mismatch
Paper
Loaded from Europe PMC by your browser; OSCR does not store it: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
R · 685 lines · 24 KB · no license · 2 matches
- required_pkgs <- c(
- "MASS", "glmnet", "Matrix", "parallel",
- "DoubleML", "mlr3", "mlr3learners", "tmle",
- "ranger", "e1071", "SuperLearner"
- )
- missing_pkgs <- required_pkgs[!sapply(required_pkgs, requireNamespace, quietly = TRUE)]
- if (length(missing_pkgs) > 0) {
- stop("Missing packages: ", paste(missing_pkgs, collapse = ", "),
- "\nPlease install them before running this simulation script.")
- }
- suppressPackageStartupMessages({
- library(MASS)
- library(glmnet)
- library(Matrix)
- library(parallel)
- library(DoubleML)
- library(mlr3)
- library(mlr3learners)
- library(tmle)
- library(ranger)
- library(e1071)
- library(SuperLearner)
- })
- if (requireNamespace("lgr", quietly = TRUE)) {
- lgr::get_logger("mlr3")$set_threshold("warn")
- }
- get_script_dir <- function() {
- cmd.args <- commandArgs(FALSE)
- file.arg <- cmd.args[grep("^--file=", cmd.args)]
- if (length(file.arg) > 0) dirname(normalizePath(sub("^--file=", "", file.arg[1]))) else getwd()
- }
- CODE_DIR <- get_script_dir()
- PROJECT_DIR <- normalizePath(file.path(CODE_DIR, ".."), mustWork = FALSE)
- output_dir <- file.path(PROJECT_DIR, "results")
- dir.create(output_dir, recursive = TRUE, showWarnings = FALSE)
- source(file.path(CODE_DIR, "gen_latest.R"))
- source(file.path(CODE_DIR, "glmtrans.R"))
- set.seed(321)
- #E(z=1)=0.5, link = 'logit'
- n=50 # 50,200,1000,2000
- m=1000
- p=100
- nsim=200 #模拟次数
- B=500#重抽样次数
- BOOT_CORES <- max(1, min(15, parallel::detectCores() - 1))
- BOOT_CLUSTER <- NULL
- ######################################
- ## setting
- alpha1 <- c(0.2, rep(0.3,5),rep(0.6,45),rep(0,50)) #source. ps
- alpha2 <- c(-0.2, rep(-0.3,5),rep(0.6,45),rep(0,50)) #target. ps
- beta1.t <- c(1, rep(0.3,3),rep(-0.3,2),rep(0.8,25),rep(-0.8,20),rep(0,50))
- beta1.c <- c(-1, rep(0.3,3),rep(-0.3,2),rep(0.8,25),rep(-0.8,20),rep(0,50))
- beta2.t <- c(-1, rep(-0.3,3),rep(0.3,2),rep(0.8,25),rep(-0.8,20),rep(0,50))
- beta2.c <- c(1, rep(-0.3,3),rep(0.3,2),rep(0.8,25),rep(-0.8,20),rep(0,50))
- sigmoid <- function(x) 1 / (1 + exp(-x))
- ######################################
- ## 最小诊断记录对象
- ######################################
- REG_DIAG <- data.frame()
- RUN_STATUS <- data.frame()
- ESTIMATOR_TIME <- rep(NA, nsim)
- BOOTSTRAP_TIME <- rep(NA, nsim)
- TOTAL_TIME <- rep(NA, nsim)
- CURRENT_SIM <- NA
- CURRENT_STAGE <- "main"
- SAVE_REG_DIAG <- TRUE
- METHOD_NAMES <- c(
- "naive_diff",
- "oracle_dr",
- "target_lasso_dr",
- "doubleml_glmnet_ranger",
- "doubleml_svm_ranger",
- "tmle_glmnet",
- "glmtrans2old",
- "dstcl_transfer"
- )
- MAIN_METHOD_TIME_SUM <- matrix(0, nsim, length(METHOD_NAMES))
- MAIN_METHOD_TIME_COUNT <- matrix(0, nsim, length(METHOD_NAMES))
- BOOT_METHOD_TIME_SUM <- matrix(0, nsim, length(METHOD_NAMES))
- BOOT_METHOD_TIME_COUNT <- matrix(0, nsim, length(METHOD_NAMES))
- colnames(MAIN_METHOD_TIME_SUM) <- METHOD_NAMES
- colnames(MAIN_METHOD_TIME_COUNT) <- METHOD_NAMES
- colnames(BOOT_METHOD_TIME_SUM) <- METHOD_NAMES
- colnames(BOOT_METHOD_TIME_COUNT) <- METHOD_NAMES
- record_method_time <- function(method_index, elapsed_sec) {
- if (is.na(CURRENT_SIM)) return(invisible(NULL))
- if (is.character(method_index)) method_index <- match(method_index, METHOD_NAMES)
- if (is.na(method_index)) return(invisible(NULL))
- if (CURRENT_STAGE == "bootstrap") {
- BOOT_METHOD_TIME_SUM[CURRENT_SIM, method_index] <<-
- BOOT_METHOD_TIME_SUM[CURRENT_SIM, method_index] + elapsed_sec
- BOOT_METHOD_TIME_COUNT[CURRENT_SIM, method_index] <<-
- BOOT_METHOD_TIME_COUNT[CURRENT_SIM, method_index] + 1
- } else {
- MAIN_METHOD_TIME_SUM[CURRENT_SIM, method_index] <<-
- MAIN_METHOD_TIME_SUM[CURRENT_SIM, method_index] + elapsed_sec
- MAIN_METHOD_TIME_COUNT[CURRENT_SIM, method_index] <<-
- MAIN_METHOD_TIME_COUNT[CURRENT_SIM, method_index] + 1
- }
- invisible(NULL)
- }
- add_reg_diag <- function(fit, method, component) {
- d <- fit$diag
- d$sim <- CURRENT_SIM
- d$method <- method
- d$component <- component
- diag_cols <- c("sim", "method", "component",
- "nfolds_used", "lambda_rule",
- "source_lambda", "correction_lambda",
- "nonzero_source", "nonzero_delta", "nonzero_final",
- "prop_nonzero_source", "prop_nonzero_delta", "prop_nonzero_final",
- "l1_source", "l1_delta", "l1_final",
- "n_try_correction", "converged")
- missing_cols <- setdiff(diag_cols, names(d))
- for (col in missing_cols) {
- d[[col]] <- NA
- }
- d <- d[, diag_cols]
- return(d)
- }
- ######################################
- ## 估计函数(baseline + DR + transfer)
- or <- function(x,z,beta.t,beta.c){
- mean((as.matrix(x)%*%beta.t)-(as.matrix(x)%*%beta.c))
- }
- ipw <- function(y,z,x,alpha){
- p <- sigmoid(as.matrix(x)%*%alpha)
- p <- pmin(pmax(p,1e-4),1-1e-4)
- sum(y*z/p)/sum(z/p) - sum(y*(1-z)/(1-p))/sum((1-z)/(1-p))
- }
- dr <- function(y,z,x,alpha,beta.t,beta.c){
- ps <- sigmoid(as.matrix(x)%*%alpha)
- ps <- pmin(pmax(ps,1e-4),1-1e-4)
- mu1 <- as.matrix(x)%*%beta.t
- mu0 <- as.matrix(x)%*%beta.c
- mean((mu1-mu0)+(z*(y-mu1))/ps-((1-z)*(y-mu0))/(1-ps))
- }
- glmtrans2old <- function(target=target, source = source, family = "gaussian", lambda = lambda,
- type.measure=type.measure, alpha = 1, nfolds = nfolds,
- intercept=intercept, penalty.factor=penalty.factor) {
- ## Purpose:
- ## Reproduce the original l1-TCL comparison method. The source model is
- ## fitted by ordinary GLM, followed by an L1-regularized target correction.
- beta1 <- glm(y ~ ., family = family, data = source)$coefficients
- offset <- as.numeric(as.matrix(target[, -1]) %*% beta1[-1]) + beta1[1]
- n.try <- 0
- while (TRUE) {
- cv.fit.correct <- try(
- cv.glmnet(
- x = as.matrix(target[, -1]),
- y = as.matrix(target[, 1]),
- offset = offset,
- alpha = 1,
- nfolds = nfolds,
- intercept = intercept,
- type.measure = type.measure,
- family = family,
- grouped = FALSE,
- penalty.factor = penalty.factor
- ),
- silent = TRUE
- )
- if (!inherits(cv.fit.correct, "try-error")) break
- n.try <- n.try + 1
- if (n.try > 10) stop("Errors occur during the debiasing step!!!")
- }
- if (lambda == "lambda.min") {
- lambda.fit <- cv.fit.correct$lambda.min
- coef.correct <- coef(cv.fit.correct, s = cv.fit.correct$lambda.min)
- } else if (lambda == "lambda.1se") {
- lambda.fit <- cv.fit.correct$lambda.1se
- coef.correct <- coef(cv.fit.correct, s = cv.fit.correct$lambda.1se)
- } else {
- stop("lambda must be either 'lambda.min' or 'lambda.1se'")
- }
- beta <- beta1 + coef.correct
- obj <- list(
- beta = beta,
- family = family,
- fitting.list = list(beta1 = beta1, delta_a = coef.correct),
- lambda = lambda.fit
- )
- class(obj) <- "glmtrans"
- return(obj)
- }
- estimate_doubleml_glmnet_ranger <- function(y.t, z.t, x.t) {
- data_dml <- DoubleMLData$new(
- data = data.frame(y = y.t, d = z.t, x.t),
- y_col = "y",
- d_cols = "d"
- )
- ml_g <- lrn("regr.cv_glmnet")
- ml_m <- lrn("classif.ranger", predict_type = "prob")
- dml_irm <- DoubleMLIRM$new(data_dml, ml_g = ml_g, ml_m = ml_m, n_folds = 3)
- dml_irm$fit()
- as.numeric(dml_irm$coef)
- }
- estimate_doubleml_svm_ranger <- function(y.t, z.t, x.t) {
- data_dml <- DoubleMLData$new(
- data = data.frame(y = y.t, d = z.t, x.t),
- y_col = "y",
- d_cols = "d"
- )
- ml_g <- lrn("regr.svm")
- ml_m <- lrn("classif.ranger", predict_type = "prob")
- dml_irm <- DoubleMLIRM$new(data_dml, ml_g = ml_g, ml_m = ml_m, n_folds = 3)
- dml_irm$fit()
- as.numeric(dml_irm$coef)
- }
- estimate_tmle_glmnet <- function(y.t, z.t, x.t) {
- tmleresult <- tmle(
- y.t, z.t, x.t,
- family = "gaussian",
- Q.SL.library = "SL.glmnet",
- g.SL.library = "SL.glmnet"
- )
- as.numeric(tmleresult$estimates$ATE$psi)
- }
- run_safe_method <- function(method_name, expr) {
- method.start <- proc.time()[3]
- ans <- tryCatch(expr, error = function(e) NA_real_)
- record_method_time(method_name, proc.time()[3] - method.start)
- ans
- }
- init_boot_cluster <- function() {
- if (BOOT_CORES <= 1) return(NULL)
- cl <- parallel::makeCluster(BOOT_CORES)
- boot_wd <- getwd()
- parallel::clusterCall(cl, setwd, boot_wd)
- parallel::clusterEvalQ(cl, {
- suppressPackageStartupMessages({
- library(MASS)
- library(glmnet)
- library(Matrix)
- library(DoubleML)
- library(mlr3)
- library(mlr3learners)
- library(tmle)
- library(ranger)
- library(e1071)
- library(SuperLearner)
- })
- if (requireNamespace("lgr", quietly = TRUE)) {
- lgr::get_logger("mlr3")$set_threshold("warn")
- }
- NULL
- })
- parallel::clusterExport(
- cl,
- varlist = c(
- "m", "n", "p", "METHOD_NAMES",
- "alpha1", "alpha2", "beta1.t", "beta1.c", "beta2.t", "beta2.c",
- "sigmoid", "dr", "record_method_time", "add_reg_diag", "estimator",
- "bootstrap_one", "glmtrans2", "glmtrans2old",
- "estimate_doubleml_glmnet_ranger", "estimate_doubleml_svm_ranger",
- "estimate_tmle_glmnet", "run_safe_method"
- ),
- envir = .GlobalEnv
- )
- parallel::clusterSetRNGStream(cl, 321)
- cat("Initialized PSOCK cluster with", BOOT_CORES, "workers\n")
- flush.console()
- cl
- }
- ######################################
- ## estimator 主函数
- ######################################
- estimator <- function(data_s,data_t){
- ATE <- rep(NA, length(METHOD_NAMES))
- names(ATE) <- METHOD_NAMES
- y.s<-data_s[,1]; z.s<-data_s[,2]; x.s<-data_s[,c(-1,-2)]
- data_s<-data_s[,-3]; colnames(data_s)[1:2]<-c('y','z')
- y.t<-data_t[,1]; z.t<-data_t[,2]; x.t<-data_t[,c(-1,-2)]
- data_t<-data_t[,-3]; colnames(data_t)[1:2]<-c('y','z')
- ATE["naive_diff"] <- run_safe_method(
- "naive_diff",
- mean(y.t[z.t==1]) - mean(y.t[z.t==0])
- )
- ATE["oracle_dr"] <- run_safe_method(
- "oracle_dr",
- dr(y.t,z.t,x.t,alpha2,beta2.t,beta2.c)
- )
- if(sum(z.t)==n||sum(z.t)==0) stop("Target treatment has only one class")
- # target lasso, estimate alpha beta.t beta.c
- x.t1=x.t[z.t==1,]
- y.t1=y.t[z.t==1]
- x.t0=x.t[z.t==0,]
- y.t0=y.t[z.t==0]
- x.s1=x.s[z.s==1,]
- y.s1=y.s[z.s==1]
- x.s0=x.s[z.s==0,]
- y.s0=y.s[z.s==0]
- ATE["target_lasso_dr"] <- run_safe_method("target_lasso_dr", {
- lamda<-cv.glmnet(as.matrix(x.t), as.matrix(z.t), family = "binomial", alpha = 1,
- type.measure="deviance", nfolds = min(5, length(z.t)), intercept = T, grouped=F)
- target.ps <- glmnet(x.t, z.t, family = "binomial", alpha = 1, intercept = F, lambda = lamda$lambda.1se)
- lamda<-cv.glmnet(as.matrix(x.t0), as.matrix(y.t0), family = "gaussian", alpha = 1,
- type.measure = "mse", nfolds = min(5, length(y.t0)), grouped=F)
- target.or.c <- glmnet(x.t0, y.t0, family = "gaussian", alpha = 1, intercept = TRUE, lambda = lamda$lambda.1se)
- lamda<-cv.glmnet(as.matrix(x.t1), as.matrix(y.t1), family = "gaussian", alpha = 1,
- type.measure = "mse", nfolds = min(5, length(y.t1)), grouped=F)
- target.or.t <- glmnet(x.t1, y.t1, family = "gaussian", alpha = 1, intercept = TRUE, lambda = lamda$lambda.1se)
- dr(y.t,z.t,x.t,target.ps$beta,target.or.t$beta,target.or.c$beta)
- })
- penalty.factor = rep(1,p)
- ps.target<-data_t[,-1]
- colnames(ps.target)[1]<-"y"
- ps.source<-data_s[,-1]
- colnames(ps.source)[1]<-"y"
- ATE["doubleml_glmnet_ranger"] <- run_safe_method(
- "doubleml_glmnet_ranger",
- estimate_doubleml_glmnet_ranger(y.t, z.t, x.t)
- )
- ATE["doubleml_svm_ranger"] <- run_safe_method(
- "doubleml_svm_ranger",
- estimate_doubleml_svm_ranger(y.t, z.t, x.t)
- )
- ATE["tmle_glmnet"] <- run_safe_method(
- "tmle_glmnet",
- estimate_tmle_glmnet(y.t, z.t, x.t)
- )
- ATE["glmtrans2old"] <- run_safe_method("glmtrans2old", {
- old_alpha<-glmtrans2old(target=ps.target, source = ps.source, family = "binomial", lambda = "lambda.1se", type.measure="deviance",
- alpha = 1, nfolds = min(5,nrow(ps.target)), intercept=F, penalty.factor=penalty.factor)
- or.t.target<-data.frame(cbind(y.t1,x.t1[,-1]))
- names(or.t.target)[1]<-c("y")
- or.t.source<-data.frame(cbind(y.s1,x.s1[,-1]))
- names(or.t.source)[1]<-c("y")
- old_beta.t <- glmtrans2old(target = or.t.target, source = or.t.source, family = "gaussian", lambda = "lambda.1se", type.measure="mse",
- alpha = 1, nfolds = min(5,length(y.t1)), intercept=T, penalty.factor=penalty.factor)
- or.c.target<-data.frame(cbind(y.t0,x.t0[,-1]))
- names(or.c.target)[1]<-c("y")
- or.c.source<-data.frame(cbind(y.s0,x.s0[,-1]))
- names(or.c.source)[1]<-c("y")
- old_beta.c <- glmtrans2old(target = or.c.target, source = or.c.source, family = "gaussian", lambda = "lambda.1se", type.measure="mse",
- alpha = 1, nfolds = min(5,length(y.t0)), intercept=T, penalty.factor=penalty.factor)
- dr(y.t,z.t,x.t,old_alpha$beta,old_beta.t$beta,old_beta.c$beta)
- })
- method.start <- proc.time()[3]
- tran_alpha3<-glmtrans2(target=ps.target, source = ps.source, family = "binomial", lambda = "lambda.1se", type.measure="deviance",
- alpha = 1, nfolds = min(5,nrow(ps.target)), intercept=F, penalty.factor=penalty.factor)
- or.t.target<-data.frame(cbind(y.t1,x.t1[,-1]))
- names(or.t.target)[1]<-c("y")
- or.t.source<-data.frame(cbind(y.s1,x.s1[,-1]))
- names(or.t.source)[1]<-c("y")
- tran_beta3.t <- glmtrans2(target = or.t.target, source = or.t.source, family = "gaussian", lambda = "lambda.1se", type.measure="mse",
- alpha = 1, nfolds = min(5,length(y.t1)), intercept=T, penalty.factor=penalty.factor)
- or.c.target<-data.frame(cbind(y.t0,x.t0[,-1]))
- names(or.c.target)[1]<-c("y")
- or.c.source<-data.frame(cbind(y.s0,x.s0[,-1]))
- names(or.c.source)[1]<-c("y")
- tran_beta3.c <- glmtrans2(target = or.c.target, source = or.c.source, family = "gaussian", lambda = "lambda.1se", type.measure="mse",
- alpha = 1, nfolds = min(5,length(y.t0)), intercept=T, penalty.factor=penalty.factor)
- if (SAVE_REG_DIAG) {
- REG_DIAG <<- rbind(
- REG_DIAG,
- add_reg_diag(tran_alpha3, "DSTCL", "PS"),
- add_reg_diag(tran_beta3.t, "DSTCL", "OR_treated"),
- add_reg_diag(tran_beta3.c, "DSTCL", "OR_control")
- )
- }
- ATE["dstcl_transfer"] <- dr(y.t,z.t,x.t,tran_alpha3$beta,tran_beta3.t$beta,tran_beta3.c$beta)
- record_method_time("dstcl_transfer", proc.time()[3] - method.start)
- return(ATE)
- }
- bootstrap_one <- function(i) {
- SAVE_REG_DIAG <<- FALSE
- CURRENT_STAGE <<- "bootstrap"
- CURRENT_SIM <<- sim_id_boot
- MAIN_METHOD_TIME_SUM <<- matrix(0, 1, length(METHOD_NAMES))
- MAIN_METHOD_TIME_COUNT <<- matrix(0, 1, length(METHOD_NAMES))
- BOOT_METHOD_TIME_SUM <<- matrix(0, sim_id_boot, length(METHOD_NAMES))
- BOOT_METHOD_TIME_COUNT <<- matrix(0, sim_id_boot, length(METHOD_NAMES))
- colnames(BOOT_METHOD_TIME_SUM) <<- METHOD_NAMES
- colnames(BOOT_METHOD_TIME_COUNT) <<- METHOD_NAMES
- data_ss <- data_s_boot[sample(1:m,m,replace=TRUE),]
- data_tt <- data_t_boot[sample(1:n,n,replace=TRUE),]
- fit.i <- try(estimator(data_ss,data_tt), silent = TRUE)
- if (inherits(fit.i, "try-error")) {
- list(
- index = i,
- ate = rep(NA, length(METHOD_NAMES)),
- time_sum = rep(0, length(METHOD_NAMES)),
- time_count = rep(0, length(METHOD_NAMES)),
- error = as.character(fit.i)
- )
- } else {
- list(
- index = i,
- ate = fit.i,
- time_sum = as.numeric(BOOT_METHOD_TIME_SUM[sim_id_boot, ]),
- time_count = as.numeric(BOOT_METHOD_TIME_COUNT[sim_id_boot, ]),
- error = NA_character_
- )
- }
- }
- ######################################
- ## bootstrap 函数
- ######################################
- boo <- function(data_s,data_t,B){
- ATE_B <- matrix(NA,B,length(METHOD_NAMES))
- old.save <- SAVE_REG_DIAG
- old.stage <- CURRENT_STAGE
- SAVE_REG_DIAG <<- FALSE
- CURRENT_STAGE <<- "bootstrap"
- on.exit({
- SAVE_REG_DIAG <<- old.save
- CURRENT_STAGE <<- old.stage
- }, add = TRUE)
- sim_id <- CURRENT_SIM
- cat(" Bootstrap 1 to", B, "of", B,
- "in simulation", sim_id, "using", BOOT_CORES, "workers with load balancing\n")
- flush.console()
- if (is.null(BOOT_CLUSTER)) {
- data_s_boot <<- data_s
- data_t_boot <<- data_t
- sim_id_boot <<- sim_id
- boot_res <- lapply(seq_len(B), bootstrap_one)
- rm(data_s_boot, data_t_boot, sim_id_boot, envir = .GlobalEnv)
- } else {
- data_s_boot <- data_s
- data_t_boot <- data_t
- sim_id_boot <- sim_id
- parallel::clusterExport(
- BOOT_CLUSTER,
- varlist = c("data_s_boot", "data_t_boot", "sim_id_boot"),
- envir = environment()
- )
- boot_res <- parallel::parLapplyLB(BOOT_CLUSTER, seq_len(B), bootstrap_one)
- }
- for (res in boot_res) {
- ATE_B[res$index, ] <- res$ate
- BOOT_METHOD_TIME_SUM[sim_id, ] <<- BOOT_METHOD_TIME_SUM[sim_id, ] + res$time_sum
- BOOT_METHOD_TIME_COUNT[sim_id, ] <<- BOOT_METHOD_TIME_COUNT[sim_id, ] + res$time_count
- }
- return(ATE_B)
- }
- ######################################
- ## 主模拟循环
- ######################################
- EST <- matrix(NA,nsim,length(METHOD_NAMES))
- cover<- matrix(NA,nsim,length(METHOD_NAMES))
- colnames(EST) <- METHOD_NAMES
- colnames(cover) <- METHOD_NAMES
- True_ate<-rep(-2,length(METHOD_NAMES))
- BOOT_CLUSTER <- init_boot_cluster()
- on.exit({
- if (!is.null(BOOT_CLUSTER)) {
- parallel::stopCluster(BOOT_CLUSTER)
- }
- }, add = TRUE)
- for(k in 1:nsim){
- sim.start <- proc.time()[3]
- cat("Starting simulation", k, "of", nsim, "\n")
- flush.console()
- data<-gen.transfer.train(m,n,p,alpha1,alpha2,beta1.t,beta1.c,beta2.t,beta2.c,scenario="ps_correct")
- data_s<-as.data.frame(data[["data.source"]])
- data_t<-as.data.frame(data[["data.target"]])
- CURRENT_SIM <<- k
- CURRENT_STAGE <<- "main"
- est.start <- proc.time()[3]
- fit.k <- try(estimator(data_s,data_t), silent = TRUE)
- ESTIMATOR_TIME[k] <- proc.time()[3] - est.start
- if (inherits(fit.k, "try-error")) {
- cat("Simulation", k, "main estimator failed:\n", as.character(fit.k), "\n")
- flush.console()
- EST[k,] <- NA
- RUN_STATUS <- rbind(
- RUN_STATUS,
- data.frame(sim = k, status = "failed", message = as.character(fit.k),
- estimator_runtime_sec = ESTIMATOR_TIME[k],
- bootstrap_runtime_sec = NA,
- total_runtime_sec = NA)
- )
- } else {
- EST[k,] <- fit.k
- RUN_STATUS <- rbind(
- RUN_STATUS,
- data.frame(sim = k, status = "ok", message = NA,
- estimator_runtime_sec = ESTIMATOR_TIME[k],
- bootstrap_runtime_sec = NA,
- total_runtime_sec = NA)
- )
- }
- boot.start <- proc.time()[3]
- ATE_B<-boo(data_s,data_t,B)
- BOOTSTRAP_TIME[k] <- proc.time()[3] - boot.start
- upper<-apply(ATE_B,2,function(x)quantile(x,0.975,na.rm=TRUE))
- lower<-apply(ATE_B,2,function(x)quantile(x,0.025,na.rm=TRUE))
- cover[k,]<-ifelse(((True_ate-lower)>-1e-06)&((True_ate-upper)<1e-06),1,0)
- TOTAL_TIME[k] <- proc.time()[3] - sim.start
- RUN_STATUS[RUN_STATUS$sim == k, "bootstrap_runtime_sec"] <- BOOTSTRAP_TIME[k]
- RUN_STATUS[RUN_STATUS$sim == k, "total_runtime_sec"] <- TOTAL_TIME[k]
- cat("Completed", k, "of", nsim,
- "simulations; estimator:", round(ESTIMATOR_TIME[k], 2), "sec;",
- "bootstrap:", round(BOOTSTRAP_TIME[k], 2), "sec;",
- "total:", round(TOTAL_TIME[k], 2), "sec\n")
- sim_method_total <- BOOT_METHOD_TIME_SUM[k, ]
- sim_method_count <- BOOT_METHOD_TIME_COUNT[k, ]
- sim_method_mean <- ifelse(sim_method_count > 0, sim_method_total / sim_method_count, NA)
- top_methods <- order(sim_method_total, decreasing = TRUE)[1:min(3, length(METHOD_NAMES))]
- cat(" Slowest bootstrap methods in simulation", k, ":\n")
- for (idx in top_methods) {
- if (sim_method_count[idx] > 0) {
- cat(" -", METHOD_NAMES[idx],
- "total:", round(sim_method_total[idx], 2), "sec;",
- "mean:", round(sim_method_mean[idx], 2), "sec;",
- "n:", sim_method_count[idx], "\n")
- }
- }
- flush.console()
- }
- ######################################
- ## 结果整理与保存
- ######################################
- True_ate <- -2
- BIAS<-colMeans(EST,na.rm=TRUE)-True_ate
- SD<-apply(EST,2,sd,na.rm=TRUE)
- MSE<-apply(EST,2,function(x)mean((x-True_ate)^2,na.rm=TRUE))
- Coverage<-colMeans(cover,na.rm=TRUE)
- result<-data.frame(
- "Method"=METHOD_NAMES,
- "Bias"=round(BIAS,2),
- "SD"=round(SD,2),
- "MSE"=round(MSE,2),
- "Coverage"=round(Coverage,2)
- )
- print(result)
- runtime_summary <- data.frame(
- mean_estimator_runtime_sec = mean(ESTIMATOR_TIME, na.rm = TRUE),
- median_estimator_runtime_sec = median(ESTIMATOR_TIME, na.rm = TRUE),
- mean_bootstrap_runtime_sec = mean(BOOTSTRAP_TIME, na.rm = TRUE),
- median_bootstrap_runtime_sec = median(BOOTSTRAP_TIME, na.rm = TRUE),
- mean_total_runtime_sec = mean(TOTAL_TIME, na.rm = TRUE),
- median_total_runtime_sec = median(TOTAL_TIME, na.rm = TRUE),
- sd_total_runtime_sec = sd(TOTAL_TIME, na.rm = TRUE),
- min_total_runtime_sec = min(TOTAL_TIME, na.rm = TRUE),
- max_total_runtime_sec = max(TOTAL_TIME, na.rm = TRUE),
- n_failed = sum(RUN_STATUS$status != "ok"),
- failure_rate = mean(RUN_STATUS$status != "ok")
- )
- main_method_total <- colSums(MAIN_METHOD_TIME_SUM, na.rm = TRUE)
- main_method_count <- colSums(MAIN_METHOD_TIME_COUNT, na.rm = TRUE)
- bootstrap_method_total <- colSums(BOOT_METHOD_TIME_SUM, na.rm = TRUE)
- bootstrap_method_count <- colSums(BOOT_METHOD_TIME_COUNT, na.rm = TRUE)
- method_time_summary <- data.frame(
- method_index = seq_along(METHOD_NAMES),
- method = METHOD_NAMES,
- main_total_sec = main_method_total,
- main_count = main_method_count,
- main_mean_sec = ifelse(main_method_count > 0, main_method_total / main_method_count, NA),
- bootstrap_total_sec = bootstrap_method_total,
- bootstrap_count = bootstrap_method_count,
- bootstrap_mean_sec = ifelse(bootstrap_method_count > 0, bootstrap_method_total / bootstrap_method_count, NA)
- )
- bootstrap_method_time_by_sim <- do.call(
- rbind,
- lapply(1:nsim, function(sim_id) {
- total <- BOOT_METHOD_TIME_SUM[sim_id, ]
- count <- BOOT_METHOD_TIME_COUNT[sim_id, ]
- data.frame(
- sim = sim_id,
- method_index = seq_along(METHOD_NAMES),
- method = METHOD_NAMES,
- bootstrap_total_sec = as.numeric(total),
- bootstrap_count = as.numeric(count),
- bootstrap_mean_sec = ifelse(count > 0, as.numeric(total) / as.numeric(count), NA)
- )
- })
- )
- if (nrow(REG_DIAG) > 0) {
- reg_summary <- aggregate(
- cbind(nfolds_used,
- nonzero_source, nonzero_delta, nonzero_final,
- prop_nonzero_source, prop_nonzero_delta, prop_nonzero_final,
- l1_source, l1_delta, l1_final,
- source_lambda, correction_lambda,
- n_try_correction) ~ method + component,
- data = REG_DIAG,
- FUN = function(x) mean(x, na.rm = TRUE),
- na.action = na.pass
- )
- reg_lambda_summary <- aggregate(
- lambda_rule ~ method + component,
- data = REG_DIAG,
- FUN = function(x) {
- x <- unique(na.omit(x))
- if (length(x) == 0) NA_character_ else paste(x, collapse = ";")
- },
- na.action = na.pass
- )
- reg_summary <- merge(
- reg_summary,
- reg_lambda_summary,
- by = c("method", "component"),
- all.x = TRUE
- )
- } else {
- reg_summary <- data.frame()
- }
- write.csv(result,file = file.path(output_dir, "result_main_ps_50_2000_200_6.csv"))
- write.csv(EST,file = file.path(output_dir, "EST_main_ps_50_2000_200_6.csv"))
- write.csv(cover,file = file.path(output_dir, "cover_main_ps_50_2000_200_6.csv"))
- write.csv(REG_DIAG, file = file.path(output_dir, "regularization_diagnostics_raw_main_ps_50_2000_200_6.csv"), row.names = FALSE)
- write.csv(reg_summary, file = file.path(output_dir, "regularization_diagnostics_summary_main_ps_50_2000_200_6.csv"), row.names = FALSE)
- write.csv(RUN_STATUS, file = file.path(output_dir, "run_status_main_ps_50_2000_200_6.csv"), row.names = FALSE)
- write.csv(runtime_summary, file = file.path(output_dir, "runtime_summary_main_ps_50_2000_200_6.csv"), row.names = FALSE)
- write.csv(method_time_summary, file = file.path(output_dir, "method_time_summary_main_ps_50_2000_200_6.csv"), row.names = FALSE)
- write.csv(bootstrap_method_time_by_sim, file = file.path(output_dir, "bootstrap_method_time_main_ps_50_2000_200_6.csv"), row.names = FALSE)
simulate_dstcl_main.R at commit cca9e24, no license · at the source
Overview
Abstract
Amyloid-Beta 42 (ABeta42) is a key biomarker of cerebral amyloidosis in Alzheimer’s disease, and estimating its causal effect on subsequent cognitive outcomes is important for understanding disease progression in racial minority populations, such as African Americans. However, causal effect analyses in such populations are often challenged by limited sample sizes, leading to biased or unstable estimates when only target-population data are used. Existing transfer causal learning methods borrow information from a larger related source domain, but may be unstable when source-domain estimation is high-dimensional or when irrelevant covariates introduce noise into transferred nuisance models. We propose a double shrinkage transfer causal learning (DSTCL) estimator that regularizes both the initial source domain estimation and the source-target parameter differences, and then estimates causal effects using a doubly robust framework. We evaluated DSTCL in simulations under varying source sample sizes, inter-domain similarities, covariate dimensions, and other settings, and then applied it to the Alzheimer’s Disease Neuroimaging Initiative dataset using African American participants as the target domain and non-Hispanic White participants as the source domain. In simulations, DSTCL achieved small bias, low mean squared error, and stable confidence interval coverage, generally outperforming competing methods. In the ADNI application, lower baseline ABeta42, reflecting greater amyloid burden, was associated with worse 12-month cognitive performance among African American participants, with DSTCL producing the narrowest confidence interval among the methods compared. These findings suggest that DSTCL provides a practical framework for transfer causal inference in biomedical studies with limited target population.
Reproduced under the paper's license (CC BY), from the paper cited above.
Repository
Its files are read in the Code ↔ Paper reader above, with 5 matches between paragraphs and lines of code.
LESWinnie/DSTCL
cca9e2446b942bf93aad7eeeecc96ec807bee1fc, 13 July 2026Availability: 1 check, the latest on 27 September 2026: the link answers
- 27 September 2026: the link answers
5 files
- gen_latest.R, R, 608 lines
- glmtrans.R, R, 68 lines, 2 matches
- real_data_analysis_templ
ate.R , R, 585 lines, 1 match - simulate_dstcl_main.R, R, 685 lines, 2 matches
- README.md, Text, 41 lines
The paper's code and data availability statement is in the Data section.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 4 scripts, each with its path and the digest of its content;
- 5 matches between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
No dataset and no data link were found in the paper.
Data Availability
The R code for implementing DSTCL, generating the simulated data, and reproducing the analyses is publicly available on GitHub at https://
Reproduced under the paper's license (CC BY), from the paper cited above.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 1, 27 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 5 authors, 9 MeSH terms, 4 funders, 23 references.
Cite
This paper
Shi, Y., Pan, L., Hu, Y., Yu, Y., & Qin, G. (2026). Double shrinkage transfer causal learning: An application to alzheimer's disease. PLoS computational biology, 22(8), e1014706. https://
BibTeX
@article{shi2026double,
author = {Shi, Yunxin and Pan, Lulu and Hu, Yu and Yu, Yongfu and Qin, Guoyou},
title = {{Double shrinkage transfer causal learning: An application to alzheimer's disease}},
journal = {PLoS computational biology},
year = {2026},
month = aug,
volume = {22},
number = {8},
pages = {e1014706},
publisher = {PLOS},
issn = {1553-734X},
doi = {10.1371/
url = {https://
pmid = {42636277},
pmcid = {PMC13533430}
}
RIS
TY - JOUR
AU - Shi, Yunxin
AU - Pan, Lulu
AU - Hu, Yu
AU - Yu, Yongfu
AU - Qin, Guoyou
TI - Double shrinkage transfer causal learning: An application to alzheimer's disease
T2 - PLoS computational biology
J2 - PLoS Comput Biol
PY - 2026
DA - 2026/
VL - 22
IS - 8
SP - e1014706
SN - 1553-734X
PB - PLOS
DO - 10.1371/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1371/
"type": "article-journal",
"title": "Double shrinkage transfer causal learning: An application to alzheimer's disease",
"container-title": "PLoS computational biology",
"author": [
{
"family": "Shi",
"given": "Yunxin"
},
{
"family": "Pan",
"given": "Lulu"
},
{
"family": "Hu",
"given": "Yu"
},
{
"family": "Yu",
"given": "Yongfu"
},
{
"family": "Qin",
"given": "Guoyou"
}
],
"container-title-short":
"volume": "22",
"issue": "8",
"page": "e1014706",
"DOI": "10.1371/
"PMID": "42636277",
"PMCID": "PMC13533430",
"ISSN": "1553-734X",
"publisher": "PLOS",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
8,
24
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1093/bib/bbaf460 [code]
- Transfer learning reveals the mediating mechanisms of cross-ethnic lipid metabolic pathways in the association between APOE gene and Alzheimer's disease.Journal: Briefings in bioinformaticsIn common: glmnet, tidyverse, Alzheimer's / dementia, 7 references, author Guoyou Qin
- [2] doi:10.1038/s41598-025-22004-3 [code]
- A multivariate approach to identify association between peripheral blood DNA methylation and cerebrospinal fluid biomarkers of Alzheimer disease.Journal: Scientific reportsIn common: glmnet, tidyverse, Alzheimer's / dementia, 3 references
- [3] doi:10.1093/bioinformatics/btaf282 [code]
- Debiased machine learning for ultra-high dimensional mediation analysis.Journal: Bioinformatics (Oxford, England)In common: Alzheimer's / dementia, 1 reference, author Guoyou Qin
- [4] doi:10.1016/j.neuroimage.2022.119296 [code]
- Accounting for motion in resting-state fMRI: What part of the spectrum are we characterizing in autism spectrum disorder?Journal: NeuroImageIn common: glmnet, tidyverse, 2 references
- [5] doi:10.1186/s13073-026-01698-8 [code]
- From aging to Alzheimer's disease: concordant brain DNA methylation changes in late life.Journal: Genome medicineIn common: tidyverse, Alzheimer's / dementia, 3 references
- [6] doi:10.1002/alz.14496 [code]
- Blood DNA methylation signature for incident dementia: Evidence from longitudinal cohorts.Journal: Alzheimer's & dementia : the journal of the Alzheimer's AssociationIn common: glmnet, tidyverse, Alzheimer's / dementia, 1 reference
- [7] doi:10.1002/hbm.70185 [code]
- Smooth Normative Brain Mapping of Three-Dimensional Morphometry Imaging Data Using Skew-Normal Regression.Journal: Human brain mappingIn common: glmnet, tidyverse, Alzheimer's / dementia, 1 reference
- [8] doi:10.1186/s13195-025-01903-7 [code]
- DNA methylation signatures of Life's Essential 8 and their implications for dementia.Journal: Alzheimer's research & therapyIn common: tidyverse, Alzheimer's / dementia, 2 references
- [9] doi:10.2196/57830
- Mapping Knowledge Landscapes and Emerging Trends in AI for Dementia Biomarkers: Bibliometric and Visualization Analysis.Journal: Journal of medical Internet researchIn common: Alzheimer's / dementia, 3 references
- [10] doi:10.1038/s41598-026-34997-6 [code]
- Uncovering the role of integrated stress in Alzheimer's disease through single-cell and transcriptomic analysis.Journal: Scientific reportsIn common: glmnet, tidyverse, Alzheimer's / dementia, 1 reference
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 4 scripts, and 5 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:ae235e2789dfd582…
Add the badge to the code's README
If you are an author or a maintainer of this paper's code, you can add this badge. It says what OSCR knows of the paper (its code, its validated tracing map) and links the code to this page. Paste one of these snippets under the README's title. Keep the two marks around it, so that the badge can be replaced in place and is never added twice. OSCR changes nothing in your repository.
Markdown
<!-- oscr-badge:start -->
[](https://openscicode.org/badge/doi/10.1371/journal.pcbi.1014706)
<!-- oscr-badge:end -->reStructuredText
.. oscr-badge:start
.. image:: https://openscicode.org/badge/doi/10.1371/journal.pcbi.1014706.svg
:target: https://openscicode.org/badge/doi/10.1371/journal.pcbi.1014706
:alt: OSCR
.. oscr-badge:endHTML
<!-- oscr-badge:start -->
<a href="https://openscicode.org/badge/doi/10.1371/journal.pcbi.1014706"><img src="https://openscicode.org/badge/doi/10.1371/journal.pcbi.1014706.svg" alt="OSCR"></a>
<!-- oscr-badge:end -->On GitHub, open the README, choose Edit (the pencil), paste the snippet under the title, then "Commit changes".
If you choose to, you can have the badge kept up to date for you, with oscr badge --write from the command line or with the GitHub Action in your repository's workflows. Every other form and option (a card, AsciiDoc, LaTeX, shields.io) is on the badge page.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: code errors and mismatches between the code and the paper about this paper and its code, from readers and its authors, beside the paper and its tracing map.
Report a mismatch between the code and the paper · Report a code error (signed in)
Reproductions: reports from readers who ran the authors' code and did not get the paper's result, what they ran, with which environment, commit and data.
Report a reproduction failure (signed in)
Versions of its code: the releases of its code tied to a version of this paper (the preprint, the accepted manuscript, the version of record…), each with the tracing map versioned with it.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
