ready set go

This commit is contained in:
2026-06-03 11:28:14 -08:00
commit 097f88f85d
22 changed files with 8793 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
suppressPackageStartupMessages(library(dplyr))
simulate_icu_cohort <- function(n_patients = 1000, seed = 20260531) {
set.seed(seed)
tibble(
patient_id = seq_len(n_patients),
age = round(rnorm(n_patients, mean = 65, sd = 14)) |>
pmin(95) |>
pmax(18),
sex = sample(c("female", "male"), size = n_patients, replace = TRUE, prob = c(0.45, 0.55)),
sofa_score = rpois(n_patients, lambda = 7) |>
pmin(20),
lactate = round(rlnorm(n_patients, meanlog = log(3), sdlog = 0.5), 1) |>
pmin(15),
map = round(rnorm(n_patients, mean = 62, sd = 10)) |>
pmin(95) |>
pmax(35),
suspected_sepsis = rbinom(n_patients, size = 1, prob = 0.90)
) |>
mutate(
hypotension_at_baseline = as.integer(map < 65),
elevated_lactate_at_baseline = as.integer(lactate >= 2),
eligible = as.integer(
suspected_sepsis == 1 &
hypotension_at_baseline == 1 &
elevated_lactate_at_baseline == 1
),
severity_score = 0.04 * (age - 65) +
0.18 * (sofa_score - 7) +
0.25 * (lactate - 3) -
0.04 * (map - 62),
prob_early_vasopressor = plogis(-0.2 + severity_score),
early_vasopressor = rbinom(n(), size = 1, prob = prob_early_vasopressor),
time_to_vasopressor_hours = ifelse(
early_vasopressor == 1,
runif(n(), min = 0, max = 2),
runif(n(), min = 2, max = 24)
) |>
round(2),
mortality_linear_predictor = -1.4 +
0.03 * (age - 65) +
0.20 * (sofa_score - 7) +
0.28 * (lactate - 3) -
0.05 * (map - 62) -
0.25 * early_vasopressor,
prob_death_28d = plogis(mortality_linear_predictor),
death_28d = rbinom(n(), size = 1, prob = prob_death_28d)
) |>
select(
patient_id,
age,
sex,
sofa_score,
lactate,
map,
suspected_sepsis,
hypotension_at_baseline,
elevated_lactate_at_baseline,
eligible,
early_vasopressor,
time_to_vasopressor_hours,
death_28d
)
}