[R] Tools to transform/expand expressions (e.g. for ODE models)?
Leonard Mada
|eo@m@d@ @end|ng |rom @yon|c@eu
Wed Apr 13 00:32:32 CEST 2022
Dear R-Users,
I would like to generate automatically the mathematical expressions for
some more advanced SIR-models.
The models should be specified using a simpler syntax. The R parser can
parse various types of formulas/expressions. And I am wondering if there
are tools available to help with the expansion and transformation of the
intermediary expressions to the exact ODE expressions.
Example:
# Stratification: Y = Young adults; O = Old;
model = "S ~ Y + O; I ~ .; H ~ .; S %*% I -> I; S %*% H -> I;
I -> H + R + D; H -> R + D; V ~ .; (time >= t0) & S^0 -> V;"
model = strsplit(model, ";")[[1]];
for(sM in model) {
eq = parse(text = sM); # works nicely up to here
# beyond: tools would be helpful;
}
### Model Description
1.) Stratification:
- stratified compartment: S ~ Y + O; [Young & Old]
- stratified compartment inheriting strata from parent compartment: I ~ .;
2.) Evolution
- simple: H -> R + D;
=> dH[Y] = - H[Y] * (k[Hy, Ry] + k[Hy, Dy]);
# Note: R & D are not stratified;
=> dR = H[Y] * k[Hy, Ry] + H[O] * k[Ho, Ro];
- simple interaction: S * I -> I;
=> dS[Y] = - k[Sy, Iy] * S[Y] * I[Y];
- full interaction: S %*% I -> I;
=> dS[Y] = - S[Y] * (k[Sy, Iy] * I[y] + k[Sy, Io] * I[O]);
# Note: all components of I interact (as if it was not-stratified);
1.) Tools
I would like to avoid to reinvent the wheel. Maybe there are some useful
tools.
The current model description syntax is not final/fixed: changes are
possible.
The model definition used by package dMod is useful for chemical
reactions, but is not quit what I have in mind:
https://cran.r-project.org/web/packages/dMod/vignettes/dMod.html
2.) Explicit Models on Github
Various models with explicit mathematical formulas are available on
GitHub and will be part of a BSc thesis:
https://github.com/BicaAnamaria/EpidemicSimulator
3.) Model Description
The description of the model syntax is available as an issue on GitHub
as well:
https://github.com/BicaAnamaria/EpidemicSimulator/issues/35
Although I did not find tools that could help to easily convert the
expressions, I might have missed them. There might be such tools - even
outside the scope of ODE expressions - and I would be grateful for any
hints.
Sincerely,
Leonard
More information about the R-help
mailing list