Skip to content

Commit

Permalink
expression lists for remaining unstructured models
Browse files Browse the repository at this point in the history
  • Loading branch information
jfree-man committed Dec 14, 2023
1 parent b570138 commit 1d22b2c
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 0 deletions.
52 changes: 52 additions & 0 deletions inst/starter_models/macpan_base/model.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
library(macpan2)

## expression lists
###################################################

## free form computations for convenience
computations = list(
N ~ sum(S, E, Ia, Ip, Im, Is, R, H, ICUs, ICUd, H2, D)
)

## absolute flow rates (per time only)
flow_rates = list(
SE ~ S * (beta0 / N) * (Ia * Ca + Ip * Cp + Im * Cm * (1 - iso_m) + Is * Cs *(1 - iso_s))
, EIa ~ E * alpha * sigma
, EIp ~ E * (1 - alpha)* sigma
, IaR ~ Ia * gamma_a
, IpIm ~ Ip * mu * gamma_p
, ImR ~ Im * gamma_m
, IpIs ~ Ip * (1 - mu) * gamma_p
, IsICUs ~ Is * (1 - nonhosp_mort) * (1 - phi1) * (1 - phi2) * gamma_s
, ICUsH2 ~ ICUs * psi1
, H2R ~ H2 * psi3
, IsH ~ Is * (1 - nonhosp_mort) * phi1 * gamma_s
, IsICUd ~ Is * (1 - nonhosp_mort) * (1 - phi1) * phi2 * gamma_s
, ICUdD ~ ICUd * psi2
, HR ~ H * rho
)

## state updates
state_updates = list(
S ~ S - SE
, E ~ E + SE - EIa - EIp
, Ia ~ Ia + EIa - IaR
, Ip ~ Ip + EIp - IpIm - IpIs
, Im ~ Im + IpIm
, Is ~ Is + IpIs - IsICUs - IsH - IsICUd
, R ~ R + IaR + H2R + HR
, H ~ H + IsH - HR
, ICUs ~ ICUs + IsICUs - ICUsH2
, ICUd ~ ICUd + IsICUd - ICUdD
, H2 ~ H2 + ICUsH2 - H2R
, D ~ D + ICUdD
)

## simple unstructured scalar expression
expr_list = ExprList(
before = computations
, during = c(
flow_rates
, state_updates
)
)
33 changes: 33 additions & 0 deletions inst/starter_models/seir/model.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
library(macpan2)

## expression lists
###################################################

## free form computations for convenience
computations = list(
N ~ sum(S, E, I, R)
)

## absolute flow rates (per time only)
flow_rates = list(
infection ~ S * I * beta / N
, exposure ~ alpha * E
, recovery ~ gamma * I
)

## state updates
state_updates = list(
S ~ S - exposure
, E ~ E + exposure - infection
, I ~ I + infection - recovery
, R ~ R + recovery
)

## simple unstructured scalar expression
expr_list = ExprList(
before = computations
, during = c(
flow_rates
, state_updates
)
)
36 changes: 36 additions & 0 deletions inst/starter_models/sir_demo/model.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
library(macpan2)

## expression lists
###################################################

## free form computations for convenience
computations = list(
N ~ sum(S, I, R)
)

## absolute flow rates (per time only)
flow_rates = list(
birth ~ birth_rate * N
, infection ~ S * I * beta / N
, recovery ~ gamma * I
)

## state updates
state_updates = list(
S ~ S - infection + birth - death_rate * S
, I ~ I + infection - recovery - death_rate * I
, R ~ R + recovery - death_rate * R
)

## simple unstructured scalar expression
## in the general case,
## birth rate and death rate can differ, N might not be constant
## nothing can be computed before simulation loop
expr_list = ExprList(
during = c(
computations
, flow_rates
, state_updates
)
)

32 changes: 32 additions & 0 deletions inst/starter_models/sir_waning/model.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
library(macpan2)

## expression lists
###################################################

## free form computations for convenience
computations = list(
N ~ sum(S, I, R)
)

## absolute flow rates (per time only)
flow_rates = list(
infection ~ S * I * beta / N
, recovery ~ gamma * I
, waning_immunity ~ wane * R
)

## state updates
state_updates = list(
S ~ S - infection + waning_immunity
, I ~ I + infection - recovery
, R ~ R + recovery - waning_immunity
)

## simple unstructured scalar expression
expr_list = ExprList(
before = computations
, during = c(
flow_rates
, state_updates
)
)
59 changes: 59 additions & 0 deletions inst/starter_models/ww/model.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
library(macpan2)

## expression lists
###################################################

## free form computations for convenience
computations = list(
N ~ sum(S, E, Ia, Ip, Im, Is, R, H, ICUs, ICUd, H2, D, W, A)
)

## absolute flow rates (per time only)
flow_rates = list(
SE ~ S * (beta0 / N) * (Ia * Ca + Ip * Cp + Im * Cm * (1 - iso_m) + Is * Cs *(1 - iso_s))
, EIa ~ E * alpha * sigma
, EIp ~ E * (1 - alpha)* sigma
, IaR ~ Ia * gamma_a
, IpIm ~ Ip * mu * gamma_p
, ImR ~ Im * gamma_m
, IpIs ~ Ip * (1 - mu) * gamma_p
, IsICUs ~ Is * (1 - nonhosp_mort) * (1 - phi1) * (1 - phi2) * gamma_s
, ICUsH2 ~ ICUs * psi1
, H2R ~ H2 * psi3
, IsH ~ Is * (1 - nonhosp_mort) * phi1 * gamma_s
, IsICUd ~ Is * (1 - nonhosp_mort) * (1 - phi1) * phi2 * gamma_s
, ICUdD ~ ICUd * psi2
, HR ~ H * rho
, IaW ~ Ia * nu # or * or N?
, IpW ~ Ip * nu
, ImW ~ Im * nu
, IsW ~ Is * nu
, WA ~ W * xi
)

## state updates
state_updates = list(
S ~ S - SE
, E ~ E + SE - EIa - EIp
, Ia ~ Ia + EIa - IaR
, Ip ~ Ip + EIp - IpIm - IpIs
, Im ~ Im + IpIm
, Is ~ Is + IpIs - IsICUs - IsH - IsICUd
, R ~ R + IaR + H2R + HR
, H ~ H + IsH - HR
, ICUs ~ ICUs + IsICUs - ICUsH2
, ICUd ~ ICUd + IsICUd - ICUdD
, H2 ~ H2 + ICUsH2 - H2R
, D ~ D + ICUdD
, W ~ W + IaW + IpW + ImW + IsW - WA
, A ~ A + WA
)

## simple unstructured scalar expression
expr_list = ExprList(
before = computations
, during = c(
flow_rates
, state_updates
)
)

0 comments on commit 1d22b2c

Please sign in to comment.