<!–html_preserve–>
<!–/html_preserve–>
Using RxODE data frames
RxODE supports returning a solved object that is a modified data-frame.
This is done by the predict()
, solve()
, or rxSolve()
methods.
library(RxODE)
## Setup example model
mod1 <-RxODE({
C2 = centr/V2;
C3 = peri/V3;
d/dt(depot) =-KA*depot;
d/dt(centr) = 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;
});
## Seup parameters and initial conditions
theta <-
c(KA=2.94E-01, CL=1.86E+01, V2=4.02E+01, # central
Q=1.05E+01, V3=2.97E+02, # peripheral
Kin=1, Kout=1, EC50=200) # effects
inits <- c(eff=1);
## Setup dosing event information
ev <- eventTable(amount.units="mg", time.units="hours") %>%
add.dosing(dose=10000, nbr.doses=10, dosing.interval=12) %>%
add.dosing(dose=20000, nbr.doses=5, start.time=120,dosing.interval=24) %>%
add.sampling(0:240);
## Now solve
x <- predict(mod1,theta, ev, inits)
rxHtml(x)
Solved RxODE object |
Parameters ($params): |
V2 |
V3 |
KA |
CL |
Q |
Kin |
Kout |
EC50 |
40.2 |
297 |
0.294 |
18.6 |
10.5 |
1 |
1 |
200 |
|
Initial Conditions ( $inits): |
depot |
centr |
peri |
eff |
0 |
0 |
0 |
1 |
First part of data (object):
time |
C2 |
C3 |
depot |
centr |
peri |
eff |
0 |
0.00000 |
0.0000000 |
10000.000 |
0.000 |
0.0000 |
1.000000 |
1 |
44.37555 |
0.9198298 |
7452.765 |
1783.897 |
273.1895 |
1.084664 |
2 |
54.88296 |
2.6729825 |
5554.370 |
2206.295 |
793.8758 |
1.180825 |
3 |
51.90343 |
4.4564927 |
4139.542 |
2086.518 |
1323.5783 |
1.228914 |
4 |
44.49738 |
5.9807076 |
3085.103 |
1788.795 |
1776.2702 |
1.234610 |
5 |
36.48434 |
7.1774981 |
2299.255 |
1466.670 |
2131.7169 |
1.214742 |
|
or
x <- solve(mod1,theta, ev, inits)
rxHtml(x)
Solved RxODE object |
Parameters ($params): |
V2 |
V3 |
KA |
CL |
Q |
Kin |
Kout |
EC50 |
40.2 |
297 |
0.294 |
18.6 |
10.5 |
1 |
1 |
200 |
|
Initial Conditions ( $inits): |
depot |
centr |
peri |
eff |
0 |
0 |
0 |
1 |
First part of data (object):
time |
C2 |
C3 |
depot |
centr |
peri |
eff |
0 |
0.00000 |
0.0000000 |
10000.000 |
0.000 |
0.0000 |
1.000000 |
1 |
44.37555 |
0.9198298 |
7452.765 |
1783.897 |
273.1895 |
1.084664 |
2 |
54.88296 |
2.6729825 |
5554.370 |
2206.295 |
793.8758 |
1.180825 |
3 |
51.90343 |
4.4564927 |
4139.542 |
2086.518 |
1323.5783 |
1.228914 |
4 |
44.49738 |
5.9807076 |
3085.103 |
1788.795 |
1776.2702 |
1.234610 |
5 |
36.48434 |
7.1774981 |
2299.255 |
1466.670 |
2131.7169 |
1.214742 |
|
Or with mattigr
x <- mod1 %>% solve(theta, ev, inits)
rxHtml(x)
Solved RxODE object |
Parameters ($params): |
V2 |
V3 |
KA |
CL |
Q |
Kin |
Kout |
EC50 |
40.2 |
297 |
0.294 |
18.6 |
10.5 |
1 |
1 |
200 |
|
Initial Conditions ( $inits): |
depot |
centr |
peri |
eff |
0 |
0 |
0 |
1 |
First part of data (object):
time |
C2 |
C3 |
depot |
centr |
peri |
eff |
0 |
0.00000 |
0.0000000 |
10000.000 |
0.000 |
0.0000 |
1.000000 |
1 |
44.37555 |
0.9198298 |
7452.765 |
1783.897 |
273.1895 |
1.084664 |
2 |
54.88296 |
2.6729825 |
5554.370 |
2206.295 |
793.8758 |
1.180825 |
3 |
51.90343 |
4.4564927 |
4139.542 |
2086.518 |
1323.5783 |
1.228914 |
4 |
44.49738 |
5.9807076 |
3085.103 |
1788.795 |
1776.2702 |
1.234610 |
5 |
36.48434 |
7.1774981 |
2299.255 |
1466.670 |
2131.7169 |
1.214742 |
|
The solved object acts as a data.frame
or tbl
that can be filtered
by dpylr
. For example you could filter it easily.
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
x <- mod1 %>% solve(theta,ev,inits) %>% filter(time <=3)
x
## time C2 C3 depot centr peri eff
## 1 0 0.00000 0.0000000 10000.000 0.000 0.0000 1.000000
## 2 1 44.37555 0.9198298 7452.765 1783.897 273.1895 1.084664
## 3 2 54.88296 2.6729825 5554.370 2206.295 793.8758 1.180825
## 4 3 51.90343 4.4564927 4139.542 2086.518 1323.5783 1.228914
However it isn't just a simple data object. You can use the solved
object to update paramters on the fly, or even change the sampling
time.
First we need to recreate the original solved system:
x <- mod1 %>% solve(theta,ev,inits);
To examine or change initial conditions, you can use the syntax
cmt.0
, cmt0
, or cmt_0
. In the case of the eff
compartment
defined by the model, this is:
x$eff0
## [1] 1
which shows the initial condition of the effect compartment. If you
wished to change this initial condition to 2, this can be done easily
by:
x$eff0 <- 2
rxHtml(x)
Solved RxODE object |
Parameters ($params): |
V2 |
V3 |
KA |
CL |
Q |
Kin |
Kout |
EC50 |
40.2 |
297 |
0.294 |
18.6 |
10.5 |
1 |
1 |
200 |
|
Initial Conditions ( $inits): |
depot |
centr |
peri |
eff |
0 |
0 |
0 |
2 |
First part of data (object):
time |
C2 |
C3 |
depot |
centr |
peri |
eff |
0 |
0.00000 |
0.0000000 |
10000.000 |
0.000 |
0.0000 |
2.000000 |
1 |
44.37555 |
0.9198299 |
7452.765 |
1783.897 |
273.1895 |
1.496778 |
2 |
54.88295 |
2.6729829 |
5554.370 |
2206.295 |
793.8759 |
1.366782 |
3 |
51.90341 |
4.4564937 |
4139.542 |
2086.517 |
1323.5786 |
1.313536 |
4 |
44.49735 |
5.9807092 |
3085.103 |
1788.793 |
1776.2706 |
1.272430 |
5 |
36.48431 |
7.1774995 |
2299.255 |
1466.669 |
2131.7173 |
1.231204 |
|
Notice that the inital effect is now 2
.
You can also change the sampling times easily by this method by
changing t
or time
. For example:
x$t <- seq(0,5,length.out=20)
rxHtml(x)
Solved RxODE object |
Parameters ($params): |
V2 |
V3 |
KA |
CL |
Q |
Kin |
Kout |
EC50 |
40.2 |
297 |
0.294 |
18.6 |
10.5 |
1 |
1 |
200 |
|
Initial Conditions ( $inits): |
depot |
centr |
peri |
eff |
0 |
0 |
0 |
2 |
First part of data (object):
time |
C2 |
C3 |
depot |
centr |
peri |
eff |
0.0000000 |
0.00000 |
0.0000000 |
10000.000 |
0.0000 |
0.00000 |
2.000000 |
0.2631579 |
16.84421 |
0.0816880 |
9255.488 |
677.1371 |
24.26134 |
1.787179 |
0.5263158 |
29.52253 |
0.2985837 |
8566.406 |
1186.8059 |
88.67937 |
1.646825 |
0.7894737 |
38.85818 |
0.6148038 |
7928.627 |
1562.0986 |
182.59671 |
1.551517 |
1.0526316 |
45.52258 |
1.0016932 |
7338.331 |
1830.0078 |
297.50288 |
1.485338 |
1.3157895 |
50.06271 |
1.4364842 |
6791.983 |
2012.5211 |
426.63581 |
1.438438 |
|
You can also access or change parameters by the $
operator. For
example, accessing KA
can be done by:
x$KA
## [1] 0.294
And you may change it by assigning it to a new value.
x$KA <- 1;
rxHtml(x)
Solved RxODE object |
Parameters ($params): |
V2 |
V3 |
KA |
CL |
Q |
Kin |
Kout |
EC50 |
40.2 |
297 |
1 |
18.6 |
10.5 |
1 |
1 |
200 |
|
Initial Conditions ( $inits): |
depot |
centr |
peri |
eff |
0 |
0 |
0 |
2 |
First part of data (object):
time |
C2 |
C3 |
depot |
centr |
peri |
eff |
0.0000000 |
0.00000 |
0.0000000 |
10000.000 |
0.000 |
0.00000 |
2.000000 |
0.2631579 |
52.19463 |
0.2613582 |
7686.205 |
2098.224 |
77.62338 |
1.822345 |
0.5263158 |
83.29027 |
0.8999791 |
5907.775 |
3348.269 |
267.29379 |
1.737850 |
0.7894737 |
99.75845 |
1.7485784 |
4540.837 |
4010.290 |
519.32777 |
1.692658 |
1.0526316 |
106.29303 |
2.6926976 |
3490.181 |
4272.980 |
799.73120 |
1.665007 |
1.3157895 |
106.27096 |
3.6559925 |
2682.625 |
4272.092 |
1085.82977 |
1.644283 |
|
You can access/change all the parametrs, initilizations or events with
the $params
, $inits
, $events
accessor syntax, similar to what is
used above.
This syntax makes it easy to update and explore the effect of various
parameters on the solved object.