-
Notifications
You must be signed in to change notification settings - Fork 8
/
rxode2-syntax.Rmd
114 lines (80 loc) · 2.83 KB
/
rxode2-syntax.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---
title: "rxode2 ODE solving syntax"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{rxode2 ODE solving syntax}
%\VignetteEngine{knitr::rmarkdown_notangle}
%\VignetteEncoding{UTF-8}
---
```{r, echo=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>")
```
## Introduction
This briefly describes the syntax used to define models
that `rxode2` will translate into R-callable compiled code. It also
describes the communication of variables between `R` and the
`rxode2` modeling specification.
## Creating rxode2 models
```{r child='../man/rmdhunks/rxode2-create-models.Rmd'}
```
## Syntax
```{r child='../man/rmdhunks/rxode2-syntax-hunk.Rmd'}
```
## Bugs and/or deficiencies
- The modulo operator `%%` is currently unsupported.
## Note
The ODE specification mini-language is parsed with the help of the
open source tool \code{dparser}, Plevyak (2015).
## Example model
Below is a commented example to quickly show the capabilities of
`rxode2` syntax.
## Example
```{r}
f <- function() {
ini({
})
model({
# An rxode2 model specification (this line is a comment).
if(comed==0) { # concomitant medication (con-med)?
F <- 1.0 # full bioavailability w.o. con-med
} else {
F <- 0.80 # 20% reduced bioavailability
}
C2 <- centr/V2 # concentration in the central compartment
C3 <- peri/V3 # concentration in the peripheral compartment
# ODE describing the PK and PD
d/dt(depot) <- -KA*depot
d/dt(centr) <- F*KA*depot - CL*C2 - Q*C2 + Q*C3
d/dt(peri) <- Q*C2 - Q*C3
d/dt(eff) <- Kin - Kout*(1-C2/(EC50+C2))*eff
eff(0) <- 1
})
}
```
## Interface and data handling between R and the generated C code
Users specify which variables are the dynamic system's state variables
via the `d/dt(identifier)` operator as part of the model specification,
and which are model parameters via the `params=` argument in `rxode2`
`solve()` method:
```
m1 <- rxode2(model = ode, modName = "m1")
# model parameters -- a named vector is required
theta <-
c(KA=0.29, CL=18.6, V2=40.2, Q=10.5, V3=297, Kin=1, Kout=1, EC50=200)
# state variables and their amounts at time 0 (the use of names is
# encouraged, but not required)
inits <- c(depot=0, centr=0, peri=0, eff=1)
# qd1 is an eventTable specification with a set of dosing and sampling
# records (code not shown here)
solve(theta, event = qd1, inits = inits)
```
The values of these variables at pre-specified time points are saved
during model fitting/integration and returned as part of the fitted
values (see the function `et()`, to define a set of time points when
to capture the values of these variables) and returned as part of the
modeling output.
The ODE specification mini-language is parsed with the help of the
open source tool *DParser*, Plevyak (2015).