D53: landmark on baseline covariates (month-5 version as landmark_m5), NCO-1 depends on PVI-free severity, physician-cluster bootstrap script

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-28 07:20:32 -04:00
co-authored by Claude Opus 5.5
parent fbc417662c
commit 5304c89316
10 changed files with 86 additions and 18 deletions
+21
View File
@@ -68,3 +68,24 @@ replicate_seed <- function(world, scenario, rep) {
h <- sum(utf8ToInt(key) * seq_along(utf8ToInt(key))^2)
as.integer((h * 2654435761) %% 2147483647)
}
#' Physician-cluster bootstrap resample of a replicate's records (D28): physicians are
#' drawn with replacement and each draw brings all of its patients, with new patient and
#' physician ids so repeated physicians count as separate clusters.
bootstrap_records <- function(rec, seed) {
set.seed(seed)
phys <- unique(rec$patients$phys_id)
draw <- data.table(phys_id = sample(phys, length(phys), replace = TRUE), new_phys = seq_along(phys))
map <- rec$patients[, .(id, phys_id)][draw, on = "phys_id", allow.cartesian = TRUE]
map[, new_id := seq_len(.N)]
remap <- function(x) {
x <- x[map[, .(id, new_id)], on = "id", allow.cartesian = TRUE]
x[, id := new_id][, new_id := NULL][]
}
out <- rec
out$patients <- remap(rec$patients)[map[, .(new_id, new_phys)], on = c(id = "new_id"), phys_id := i.new_phys]
out$pm <- setkey(remap(rec$pm), id, t)
out$hidden <- remap(rec$hidden)
out$hidden_pm <- remap(rec$hidden_pm)
out
}