Skip to content

Commit

Permalink
WIP adapting to library updates
Browse files Browse the repository at this point in the history
  • Loading branch information
pearsonca committed Nov 8, 2024
1 parent 7a19942 commit e4620c5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion inst/analysis/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ allinputs: $(call dat,population.rds lex.rds disease_pars.rda $(patsubst %,param
# simulation time series, distillations, ylls - by various methods

${OUTDIR}/sim_%.rds: scripts/simulate.R $(call dat,population.rds param_%.rda) scripts/odin.R | ${OUTDIR}
$(call R,$(firstword $(subst _, ,$*)))
$(call R,$(firstword $(subst _, ,$*))) > $(subst rds,txt,$(subst sim,simlog,$@))

ALLSIM := $(patsubst %,${OUTDIR}/sim_%.rds,${ALLSCN})
allsim: ${ALLSIM}
Expand Down
20 changes: 14 additions & 6 deletions inst/analysis/scripts/distill.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ pop_dt <- pop_dt[
load(.args[2])

sim_dt <- readRDS(.args[3])[, .(
sim_method = method, intervention, time, model_from, value = deaths
)][, .(value = sum(value)), by = .(sim_method, intervention, model_from)]

dt <- sim_dt[,{
distill_summary(.SD, mapping_dt)
}, by = .(sim_method, intervention)]
sim_method = method, intervention, time, model_partition, value = deaths
)][, .(value = sum(value)), by = .(sim_method, intervention, model_partition)]

partial_dt <- sim_dt[sim_method != "full"]
full_dt <- setnames(
sim_dt[sim_method == "full"], "model_partition", "partition"
)[, method := "hrm"]

dt <- rbind(
partial_dt[,{
distill_summary(mapping_dt, .SD)
}, by = .(sim_method, intervention)],
full_dt
)

dt[, capita := pop_dt[, sum(weight*1000)] ]

Expand Down
2 changes: 1 addition & 1 deletion inst/analysis/scripts/param.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mapping_dt <- alembic(
# the naive alternatives
ifr_params <- parameter_summary(
f_param = f_ifr, f_pop = bound_pop_dt,
model_partition = model_agelimits
model_partition = model_agelimits, resolution = 102L
)

ifr_params[, model_partition := model_agelimits[model_category]]
Expand Down
12 changes: 6 additions & 6 deletions inst/analysis/scripts/simulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,24 @@ cat(
approx_time[3],
"full time",
full_time[3],
file = stderr(),
file = stdout(),
sep = "\n"
)

sim_dt[, model_from := model_agelimits[age_group]]
nonfull_params <- ifr_params[method != "f_val", .(model_from, method, value) ] |> unique()
sim_dt[, model_partition := model_agelimits[age_group]]
nonfull_params <- ifr_params[method != "f_val", .(model_partition, method, value) ] |> unique()

exp_sim_dt <- nonfull_params[, unique(method)] |> setNames(nm = _) |> lapply(\(m) sim_dt) |> rbindlist(idcol = "method")

exp_sim_dt[nonfull_params, on = .(model_from, method), deaths := value * i.value]
exp_sim_dt[nonfull_params, on = .(model_partition, method), deaths := value * i.value]

capita_dt <- data.table(age_group = seq_along(demog), capita = demog)

simfull_dt[, from := age_group - 1L]
simfull_dt[pop_dt, on = .(from), capita := weight * 1e3]
setnames(simfull_dt, "from", "model_from")
setnames(simfull_dt, "from", "model_partition")
simfull_dt[, method := "full"]
simfull_dt[ifr_params[method == "f_val"], on = .(model_from = x), deaths := value * i.value]
simfull_dt[ifr_params[method == "f_val"], on = .(model_partition = x), deaths := value * i.value]

exp_sim_dt[capita_dt, on = .(age_group), capita := capita]

Expand Down

0 comments on commit e4620c5

Please sign in to comment.