# NOT RUN {
library(dplyr)
clinical_1 <- clinical %>% mutate(
indicator = case_when(
STRATUM == "strata_1" ~ 0,
STRATUM == "strata_2" ~ 1,
is.na(STRATUM) & ARM == "experimental" ~ 1,
TRUE ~ -1
),
ARM = factor(ARM, levels = c("control","experimental")),
BNLR = case_when(
is.na(BNLR) ~ median(BNLR, na.rm = TRUE),
TRUE ~ BNLR
)
)
ipw_res <- ipw_strata(
data.in = clinical_1, formula = indicator ~ BECOG + SEX + BNLR,
indicator.var = "indicator", tte = "OS_MONTH", event = "OS_EVENT", trt = "ARM",
class.of.int = list("strata_1" = 1, "strata_2" = 0)
)
boot_ipw <- bootstrap_propen(
data.in = clinical_1, formula = indicator ~ BECOG + SEX + BNLR,
indicator.var = "indicator", tte = "OS_MONTH", event = "OS_EVENT", trt = "ARM",
class.of.int = list("strata_1" = 1, "strata_2" = 0),
estimate.res = ipw_res, method = "ipw", n.boot = 5
)
ps_res <- ps_match_strata(
data.in = clinical_1, formula = indicator ~ BECOG + SEX + BNLR,
indicator.var = "indicator", tte = "OS_MONTH", event = "OS_EVENT", trt = "ARM",
class.of.int = list("strata_1" = 1, "strata_2" = 0)
)
boot_ps <- bootstrap_propen(
data.in = clinical_1, formula = indicator ~ BECOG + SEX + BNLR,
indicator.var = "indicator", tte = "OS_MONTH", event = "OS_EVENT", trt = "ARM",
class.of.int = list("strata_1" = 0, "strata_2" = 1),
estimate.res = ps_res, method = "ps", n.boot = 5
)
boot.out.ipw <- boot_ipw$boot.out.est
boot.out.ps <- boot_ps$boot.out.est
ipw.ci.mat <- boot_ipw$est.ci.mat
ps.ci.mat <- boot_ps$est.ci.mat
data.fp <- data.frame(
HR = round(exp(c(ipw.ci.mat[, 1], ps.ci.mat[, 1])), 2),
LOWER = round(exp(c(ipw.ci.mat[, 2], ps.ci.mat[, 2])), 2),
UPPER = round(exp(c(ipw.ci.mat[, 3], ps.ci.mat[, 3])), 2),
ADA_Group = rep(rownames(ipw.ci.mat), 2),
n = paste("n =", rep(table(clinical_1$indicator)[c("0", "1")], 2)),
Methods_ADA = paste(
rep(c("IPW", "PS"), each = 2), rep(rownames(ipw.ci.mat), 2)
),
Methods = rep(c("IPW", "PS"), each = 2),
bootstrapHR = c(
boot.out.ipw[grep("HR", rownames(boot.out.ipw)), "Median"],
boot.out.ps[grep("HR", rownames(boot.out.ps)), "Median"]
)
)
forest_bygroup(
data = data.fp, summarystat = "HR", upperci = "UPPER", lowerci = "LOWER",
population.name = "Methods_ADA", group.name = "Methods",
color.group.name = "ADA_Group", text.column.addition = "n",
stat.label = "Hazard Ratio", text.column = NULL,
stat.type.hr = TRUE, log.scale = FALSE, extra.stat = "bootstrapHR",
extra.stat.label = "bootstrap median",
endpoint.name = "OS", study.name = "Example Study", draw = TRUE
)
# }
Run the code above in your browser using DataLab