From 5e006b9021d18a66d1fe5884a8966ba02ca417f8 Mon Sep 17 00:00:00 2001 From: Daniel Sabanes Bove Date: Mon, 8 Apr 2024 11:26:14 +0200 Subject: [PATCH] add naive method --- simulations/naive.R | 34 ++++++++++++++++++++++++++++++++++ simulations/run.R | 1 + 2 files changed, 35 insertions(+) create mode 100644 simulations/naive.R diff --git a/simulations/naive.R b/simulations/naive.R new file mode 100644 index 00000000..39fca2f4 --- /dev/null +++ b/simulations/naive.R @@ -0,0 +1,34 @@ +# Method for a single data set. +naive_method <- function(df) { + df$arm <- factor(df$arm) + model <- naive( + resp = "tt_pfs", + trt = "arm", + subgr = c("x_1", "x_2", "x_3", "x_4", "x_5", "x_6", "x_7", "x_8", "x_9", "x_10"), + data = df, + resptype = "survival", + status = "ev_pfs" + ) + s <- summary(model) + s +} + +# Analysis of a single scenario. +naive_analysis <- function(scenario) { + assert_list(scenario) + results <- lapply(scenario, naive_method) +} + +# Results across all scenarios. +naive_file <- "results/naive.rds" +naive_results <- if (file.exists(naive_file)) { + readRDS(naive_file) +} else { + res <- lapply( + scenarios, + function(x) naive_analysis(x$scenario) + ) + saveRDS(res, file = naive_file) + res +} +# todo: modify results format once target is clear diff --git a/simulations/run.R b/simulations/run.R index dd1eb0b3..38f5cb8d 100644 --- a/simulations/run.R +++ b/simulations/run.R @@ -28,5 +28,6 @@ source("functions.R") # Run analyses ---- source("naivepop.R") # fast. +source("naive.R") source("ridge.R") # takes a few minutes. source("lasso.R") # takes a few minutes.