First import the campsismod
package. This step is not
required if you have already loaded the campsis
package.
library(campsismod)
Load 2-compartment PK model from built-in model library and show content.
<- model_suite$pk$`2cpt_fo`
model show(model)
## [MAIN]
## TVKA=THETA_KA
## TVVC=THETA_VC
## TVVP=THETA_VP
## TVQ=THETA_Q
## TVCL=THETA_CL
## TVPROP_RUV=THETA_PROP_RUV
##
## KA=TVKA * exp(ETA_KA)
## VC=TVVC * exp(ETA_VC)
## VP=TVVP * exp(ETA_VP)
## Q=TVQ * exp(ETA_Q)
## CL=TVCL * exp(ETA_CL)
## PROP_RUV=TVPROP_RUV
##
## [ODE]
## d/dt(A_ABS)=-KA*A_ABS
## d/dt(A_CENTRAL)=KA*A_ABS + Q/VP*A_PERIPHERAL - Q/VC*A_CENTRAL - CL/VC*A_CENTRAL
## d/dt(A_PERIPHERAL)=Q/VC*A_CENTRAL - Q/VP*A_PERIPHERAL
##
## [ERROR]
## CONC=A_CENTRAL/VC
## if (CONC <= 0.001) CONC=0.001
## IPRED=log(CONC)
## W=PROP_RUV
## Y=IPRED + W*EPS_RUV_FIX
##
##
## THETA's:
## name index value fix
## 1 KA 1 1.0 FALSE
## 2 VC 2 60.0 FALSE
## 3 VP 3 10.0 FALSE
## 4 Q 4 2.0 FALSE
## 5 CL 5 3.0 FALSE
## 6 PROP_RUV 6 0.1 FALSE
## OMEGA's:
## name index index2 value fix type same
## 1 KA 1 1 25 FALSE cv% NA
## 2 VC 2 2 25 FALSE cv% NA
## 3 VP 3 3 25 FALSE cv% NA
## 4 Q 4 4 25 FALSE cv% NA
## 5 CL 5 5 25 FALSE cv% NA
## SIGMA's:
## name index index2 value fix type
## 1 RUV_FIX 1 1 1 TRUE var
## No variance-covariance matrix
##
## Compartments:
## A_ABS (CMT=1)
## A_CENTRAL (CMT=2)
## A_PERIPHERAL (CMT=3)
A CAMPSIS model can be persisted on your local drive as follows:
%>% write(file="path_to_model_folder") model
## [1] TRUE
list.files("path_to_model_folder")
## [1] "model.campsis" "omega.csv" "sigma.csv" "theta.csv"
As shown, the output directory will contain the model (all code
records) and 1 csv
file per type of parameter (THETA, OMEGA
and SIGMA).
To read a CAMPSIS model from your local drive, use the
read.campsis
function. The exact same model should be
retrieved.
<- read.campsis(file="path_to_model_folder")
model show(model)
## [MAIN]
## TVKA=THETA_KA
## TVVC=THETA_VC
## TVVP=THETA_VP
## TVQ=THETA_Q
## TVCL=THETA_CL
## TVPROP_RUV=THETA_PROP_RUV
##
## KA=TVKA * exp(ETA_KA)
## VC=TVVC * exp(ETA_VC)
## VP=TVVP * exp(ETA_VP)
## Q=TVQ * exp(ETA_Q)
## CL=TVCL * exp(ETA_CL)
## PROP_RUV=TVPROP_RUV
##
## [ODE]
## d/dt(A_ABS)=-KA*A_ABS
## d/dt(A_CENTRAL)=KA*A_ABS + Q/VP*A_PERIPHERAL - Q/VC*A_CENTRAL - CL/VC*A_CENTRAL
## d/dt(A_PERIPHERAL)=Q/VC*A_CENTRAL - Q/VP*A_PERIPHERAL
##
## [ERROR]
## CONC=A_CENTRAL/VC
## if (CONC <= 0.001) CONC=0.001
## IPRED=log(CONC)
## W=PROP_RUV
## Y=IPRED + W*EPS_RUV_FIX
##
##
## THETA's:
## name index value fix
## 1 KA 1 1.0 FALSE
## 2 VC 2 60.0 FALSE
## 3 VP 3 10.0 FALSE
## 4 Q 4 2.0 FALSE
## 5 CL 5 3.0 FALSE
## 6 PROP_RUV 6 0.1 FALSE
## OMEGA's:
## name index index2 value fix type same
## 1 KA 1 1 25 FALSE cv% NA
## 2 VC 2 2 25 FALSE cv% NA
## 3 VP 3 3 25 FALSE cv% NA
## 4 Q 4 4 25 FALSE cv% NA
## 5 CL 5 5 25 FALSE cv% NA
## SIGMA's:
## name index index2 value fix type
## 1 RUV_FIX 1 1 1 TRUE var
## No variance-covariance matrix
##
## Compartments:
## A_ABS (CMT=1)
## A_CENTRAL (CMT=2)
## A_PERIPHERAL (CMT=3)
The MAIN
record is the part of the model where your
model parameters are defined. The ODE
record is where your
ordinary differential equations (ODE) go, as well as any equation
depending on the simulation time. The ERROR
record is the
place where the error model is defined. The model parameters are then
shown, followed by the all the compartments.
campsismod
has powerful export capabilities to
RxODE
and mrgsolve
, the 2 simulation engines
supported by campsis
. The following code exports the model
to RxODE
. Please note that this step is implicit in CAMPSIS
when you call the simulate
method with your preferred
simulation engine.
<- model %>% export(dest="RxODE")
rxmod rxmod
## An object of class "rxode_model"
## Slot "code":
## [1] "TVKA=THETA_KA"
## [2] "TVVC=THETA_VC"
## [3] "TVVP=THETA_VP"
## [4] "TVQ=THETA_Q"
## [5] "TVCL=THETA_CL"
## [6] "TVPROP_RUV=THETA_PROP_RUV"
## [7] ""
## [8] "KA=TVKA * exp(ETA_KA)"
## [9] "VC=TVVC * exp(ETA_VC)"
## [10] "VP=TVVP * exp(ETA_VP)"
## [11] "Q=TVQ * exp(ETA_Q)"
## [12] "CL=TVCL * exp(ETA_CL)"
## [13] "PROP_RUV=TVPROP_RUV"
## [14] "d/dt(A_ABS)=-KA*A_ABS"
## [15] "d/dt(A_CENTRAL)=KA*A_ABS + Q/VP*A_PERIPHERAL - Q/VC*A_CENTRAL - CL/VC*A_CENTRAL"
## [16] "d/dt(A_PERIPHERAL)=Q/VC*A_CENTRAL - Q/VP*A_PERIPHERAL"
## [17] "CONC=A_CENTRAL/VC"
## [18] "if (CONC <= 0.001) CONC=0.001"
## [19] "IPRED=log(CONC)"
## [20] "W=PROP_RUV"
## [21] "Y=IPRED + W*EPS_RUV_FIX"
##
## Slot "theta":
## THETA_KA THETA_VC THETA_VP THETA_Q THETA_CL
## 1.0 60.0 10.0 2.0 3.0
## THETA_PROP_RUV
## 0.1
##
## Slot "omega":
## ETA_KA ETA_VC ETA_VP ETA_Q ETA_CL
## ETA_KA 0.06062462 0.00000000 0.00000000 0.00000000 0.00000000
## ETA_VC 0.00000000 0.06062462 0.00000000 0.00000000 0.00000000
## ETA_VP 0.00000000 0.00000000 0.06062462 0.00000000 0.00000000
## ETA_Q 0.00000000 0.00000000 0.00000000 0.06062462 0.00000000
## ETA_CL 0.00000000 0.00000000 0.00000000 0.00000000 0.06062462
##
## Slot "sigma":
## EPS_RUV_FIX
## EPS_RUV_FIX 1
The following code exports the model to mrgsolve
(text
form).
<- model %>% export(dest="mrgsolve")
mrgmod mrgmod
## An object of class "mrgsolve_model"
## Slot "param":
## [1] "[PARAM] @annotated"
## [2] "THETA_KA : 1 : THETA_KA"
## [3] "THETA_VC : 60 : THETA_VC"
## [4] "THETA_VP : 10 : THETA_VP"
## [5] "THETA_Q : 2 : THETA_Q"
## [6] "THETA_CL : 3 : THETA_CL"
## [7] "THETA_PROP_RUV : 0.1 : THETA_PROP_RUV"
##
## Slot "cmt":
## [1] "[CMT] @annotated" "A_ABS : ABS"
## [3] "A_CENTRAL : CENTRAL" "A_PERIPHERAL : PERIPHERAL"
##
## Slot "main":
## [1] "[MAIN]" "double TVKA=THETA_KA;"
## [3] "double TVVC=THETA_VC;" "double TVVP=THETA_VP;"
## [5] "double TVQ=THETA_Q;" "double TVCL=THETA_CL;"
## [7] "double TVPROP_RUV=THETA_PROP_RUV;" ""
## [9] "double KA=TVKA * exp(ETA_KA);" "double VC=TVVC * exp(ETA_VC);"
## [11] "double VP=TVVP * exp(ETA_VP);" "double Q=TVQ * exp(ETA_Q);"
## [13] "double CL=TVCL * exp(ETA_CL);" "double PROP_RUV=TVPROP_RUV;"
##
## Slot "ode":
## [1] "[ODE]"
## [2] "dxdt_A_ABS=-KA*A_ABS;"
## [3] "dxdt_A_CENTRAL=KA*A_ABS + Q/VP*A_PERIPHERAL - Q/VC*A_CENTRAL - CL/VC*A_CENTRAL;"
## [4] "dxdt_A_PERIPHERAL=Q/VC*A_CENTRAL - Q/VP*A_PERIPHERAL;"
##
## Slot "omega":
## [1] "[OMEGA] @annotated @block"
## [2] "ETA_KA : 0.0606246218164348 : ETA_KA"
## [3] "ETA_VC : 0 0.0606246218164348 : ETA_VC"
## [4] "ETA_VP : 0 0 0.0606246218164348 : ETA_VP"
## [5] "ETA_Q : 0 0 0 0.0606246218164348 : ETA_Q"
## [6] "ETA_CL : 0 0 0 0 0.0606246218164348 : ETA_CL"
##
## Slot "sigma":
## [1] "[SIGMA] @annotated @block" "EPS_RUV_FIX : 1 : EPS_RUV_FIX"
##
## Slot "table":
## [1] "[TABLE]" "capture CONC=A_CENTRAL/VC;"
## [3] "if (CONC <= 0.001) CONC=0.001;" "capture IPRED=log(CONC);"
## [5] "capture W=PROP_RUV;" "capture Y=IPRED + W*EPS_RUV_FIX;"
##
## Slot "capture":
## character(0)