- truths.R: interventional truths by common random numbers (A, B1, B2, sequential ITT) - estimators.R: weighted Aalen-Johansen with influence-function SEs (patient / physician cluster) - rct.R: realistic and ideal trials, ITT and as-treated; RCT ITT truths - scenario effects tuned in W0: harm +5.1 pp, benefit-then-harm -1.2 pp at 24 mo, +3.1 at 60 Co-Authored-By: Claude Opus 5.5 <[email protected]>
21 lines
1.1 KiB
R
21 lines
1.1 KiB
R
# Interventional truths for every world x scenario (plan section 5.5).
|
|
# Usage: Rscript simulations/02_truths.R [n] [cores]
|
|
# Writes simulations/truths/truths.csv and simulations/truths/risk_curves.csv.
|
|
|
|
pkgload::load_all("pvisim", quiet = TRUE)
|
|
suppressPackageStartupMessages(library(data.table))
|
|
args <- commandArgs(TRUE)
|
|
n <- if (length(args) >= 1) as.numeric(args[1]) else 1e6
|
|
cores <- if (length(args) >= 2) as.integer(args[2]) else 6L
|
|
|
|
raw <- yaml::read_yaml(default_params_path())
|
|
jobs <- CJ(world = names(raw$worlds), scenario = names(raw$scenarios), sorted = FALSE)
|
|
res <- parallel::mclapply(seq_len(nrow(jobs)), function(i)
|
|
compute_truths(jobs$world[i], jobs$scenario[i], n = n), mc.cores = cores)
|
|
bad <- vapply(res, inherits, TRUE, "try-error")
|
|
if (any(bad)) stop("failed: ", paste(jobs$world[bad], jobs$scenario[bad], collapse = "; "), "\n", res[bad][[1]])
|
|
dir.create("simulations/truths", showWarnings = FALSE)
|
|
fwrite(rbindlist(lapply(res, `[[`, "truths")), "simulations/truths/truths.csv")
|
|
fwrite(rbindlist(lapply(res, `[[`, "curves")), "simulations/truths/risk_curves.csv")
|
|
cat("wrote simulations/truths/truths.csv\n")
|