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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user