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
|
depot
|
centr
|
peri
|
eff
|
C2
|
C3
|
0
|
10000.000
|
0.000
|
0.0000
|
1.000000
|
0.00000
|
0.0000000
|
1
|
7452.765
|
1783.897
|
273.1895
|
1.084664
|
44.37555
|
0.9198298
|
2
|
5554.370
|
2206.295
|
793.8758
|
1.180825
|
54.88296
|
2.6729825
|
3
|
4139.542
|
2086.518
|
1323.5783
|
1.228914
|
51.90343
|
4.4564927
|
4
|
3085.103
|
1788.795
|
1776.2702
|
1.234610
|
44.49738
|
5.9807076
|
5
|
2299.255
|
1466.670
|
2131.7169
|
1.214742
|
36.48434
|
7.1774981
|
|
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
|
depot
|
centr
|
peri
|
eff
|
C2
|
C3
|
0
|
10000.000
|
0.000
|
0.0000
|
1.000000
|
0.00000
|
0.0000000
|
1
|
7452.765
|
1783.897
|
273.1895
|
1.084664
|
44.37555
|
0.9198298
|
2
|
5554.370
|
2206.295
|
793.8758
|
1.180825
|
54.88296
|
2.6729825
|
3
|
4139.542
|
2086.518
|
1323.5783
|
1.228914
|
51.90343
|
4.4564927
|
4
|
3085.103
|
1788.795
|
1776.2702
|
1.234610
|
44.49738
|
5.9807076
|
5
|
2299.255
|
1466.670
|
2131.7169
|
1.214742
|
36.48434
|
7.1774981
|
|
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
|
depot
|
centr
|
peri
|
eff
|
C2
|
C3
|
0
|
10000.000
|
0.000
|
0.0000
|
1.000000
|
0.00000
|
0.0000000
|
1
|
7452.765
|
1783.897
|
273.1895
|
1.084664
|
44.37555
|
0.9198298
|
2
|
5554.370
|
2206.295
|
793.8758
|
1.180825
|
54.88296
|
2.6729825
|
3
|
4139.542
|
2086.518
|
1323.5783
|
1.228914
|
51.90343
|
4.4564927
|
4
|
3085.103
|
1788.795
|
1776.2702
|
1.234610
|
44.49738
|
5.9807076
|
5
|
2299.255
|
1466.670
|
2131.7169
|
1.214742
|
36.48434
|
7.1774981
|
|
The solved object acts as a data.frame
or tbl
that can be filtered by dpylr
. For example you could filter it easily.
##
## 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 depot centr peri eff C2 C3
## 1 0 10000.000 0.000 0.0000 1.000000 0.00000 0.0000000
## 2 1 7452.765 1783.897 273.1895 1.084664 44.37555 0.9198298
## 3 2 5554.370 2206.295 793.8758 1.180825 54.88296 2.6729825
## 4 3 4139.542 2086.518 1323.5783 1.228914 51.90343 4.4564927
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:
## [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:
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
|
depot
|
centr
|
peri
|
eff
|
C2
|
C3
|
0
|
10000.000
|
0.000
|
0.0000
|
2.000000
|
0.00000
|
0.0000000
|
1
|
7452.765
|
1783.897
|
273.1895
|
1.496778
|
44.37555
|
0.9198299
|
2
|
5554.370
|
2206.295
|
793.8759
|
1.366782
|
54.88295
|
2.6729829
|
3
|
4139.542
|
2086.517
|
1323.5786
|
1.313536
|
51.90341
|
4.4564937
|
4
|
3085.103
|
1788.793
|
1776.2706
|
1.272430
|
44.49735
|
5.9807092
|
5
|
2299.255
|
1466.669
|
2131.7173
|
1.231204
|
36.48431
|
7.1774995
|
|
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
|
depot
|
centr
|
peri
|
eff
|
C2
|
C3
|
0.0000000
|
10000.000
|
0.0000
|
0.00000
|
2.000000
|
0.00000
|
0.0000000
|
0.2631579
|
9255.488
|
677.1371
|
24.26134
|
1.787179
|
16.84421
|
0.0816880
|
0.5263158
|
8566.406
|
1186.8059
|
88.67937
|
1.646825
|
29.52253
|
0.2985837
|
0.7894737
|
7928.627
|
1562.0986
|
182.59671
|
1.551517
|
38.85818
|
0.6148038
|
1.0526316
|
7338.331
|
1830.0078
|
297.50288
|
1.485338
|
45.52258
|
1.0016932
|
1.3157895
|
6791.983
|
2012.5211
|
426.63581
|
1.438438
|
50.06271
|
1.4364842
|
|
You can also access or change parameters by the $
operator. For example, accessing KA
can be done by:
## [1] 0.294
And you may change it by assigning it to a new value.
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
|
depot
|
centr
|
peri
|
eff
|
C2
|
C3
|
0.0000000
|
10000.000
|
0.000
|
0.00000
|
2.000000
|
0.00000
|
0.0000000
|
0.2631579
|
7686.205
|
2098.224
|
77.62338
|
1.822345
|
52.19463
|
0.2613582
|
0.5263158
|
5907.775
|
3348.269
|
267.29379
|
1.737850
|
83.29027
|
0.8999791
|
0.7894737
|
4540.837
|
4010.290
|
519.32777
|
1.692658
|
99.75845
|
1.7485784
|
1.0526316
|
3490.181
|
4272.980
|
799.73120
|
1.665007
|
106.29303
|
2.6926976
|
1.3157895
|
2682.625
|
4272.092
|
1085.82977
|
1.644283
|
106.27096
|
3.6559925
|
|
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.