The examples below require the package campismod.
library(campsismod)The examples below are illustrated based on the reference 2-compartment PK model that you find in the built-in library. This model has 5 parameters. All these parameters have inter-individual variability defined.
model <- model_library$advan4_trans4
model## [MAIN]
## KA=THETA_KA*exp(ETA_KA)
## CL=THETA_CL*exp(ETA_CL)
## V2=THETA_V2*exp(ETA_V2)
## V3=THETA_V3*exp(ETA_V3)
## Q=THETA_Q*exp(ETA_Q)
## S2=V2
##
## [ODE]
## d/dt(A_DEPOT)=-KA*A_DEPOT
## d/dt(A_CENTRAL)=KA*A_DEPOT + Q*A_PERIPHERAL/V3 + (-CL/V2 - Q/V2)*A_CENTRAL
## d/dt(A_PERIPHERAL)=-Q*A_PERIPHERAL/V3 + Q*A_CENTRAL/V2
## d/dt(A_OUTPUT)=CL*A_CENTRAL/V2
## F=A_CENTRAL/S2
##
## [ERROR]
## CP=F
## OBS_CP=CP*(EPS_PROP + 1)
## Y=OBS_CP
##
##
## THETA's:
## name index value fix
## 1 KA 1 1 FALSE
## 2 CL 2 5 FALSE
## 3 V2 3 80 FALSE
## 4 V3 4 20 FALSE
## 5 Q 5 4 FALSE
## OMEGA's:
## name index index2 value fix type same
## 1 KA 1 1 0.025 FALSE var NA
## 2 CL 2 2 0.025 FALSE var NA
## 3 V2 3 3 0.025 FALSE var NA
## 4 V3 4 4 0.025 FALSE var NA
## 5 Q 5 5 0.025 FALSE var NA
## SIGMA's:
## name index index2 value fix type
## 1 PROP 1 1 0.025 FALSE var
## No variance-covariance matrix
##
## Compartments:
## A_DEPOT (CMT=1)
## A_CENTRAL (CMT=2)
## A_PERIPHERAL (CMT=3)
## A_OUTPUT (CMT=4)
To retrieve a parameter by its name, just call the method find as follows:
model %>% find(Theta("CL"))## name index value fix
## 1 CL 2 5 FALSE
model %>% find(Omega("KA"))## name index index2 value fix type same
## 1 KA 1 1 0.025 FALSE var NA
model %>% find(Sigma("PROP"))## name index index2 value fix type
## 1 PROP 1 1 0.025 FALSE var
These parameters can also alternatively be retrieved by their index(es). Use the specific method getByIndex created for that purpose:
model@parameters %>% getByIndex(Theta(index=2))## name index value fix
## 1 CL 2 5 FALSE
model@parameters %>% getByIndex(Omega(index=1, index2=1))## name index index2 value fix type same
## 1 KA 1 1 0.025 FALSE var NA
model@parameters %>% getByIndex(Sigma(index=1, index2=1))## name index index2 value fix type
## 1 PROP 1 1 0.025 FALSE var
Accessing parameter values is straightforward. Parameters have a slot value that may be accessed.
thetaCL <- model %>% find(Theta("CL"))
thetaCL@value## [1] 5
For OMEGA and SIGMA parameters, be careful; the interpretation of this value depends on the type of the parameter. It may be var (for a variance), covar (for a covariance), sd (for standard deviation), cv (value expressed as coefficient of variation), cv% (value expressed as coefficient of variation in percentage).
For a quick access to the value as variance or covariance, the method standardise can be called first on the parameter itself. This is especially useful for values expressed in CV or in standard deviation.
theta <- Omega(name="TEST", index=1, index2=1, value=15, type="cv%")
theta@value # 15 is returned## [1] 15
theta_standardised <- theta %>% standardise() # Conversion to variance
theta_standardised ## name index index2 value fix type same
## 1 TEST 1 1 0.02225061 FALSE var NA
theta_standardised@value## [1] 0.02225061
Parameters can be replaced easily. Here are a few examples:
model <- model %>% replace(Theta("KA", value=2)) # Previous value for KA was 1
model <- model %>% replace(Omega("CL", value=20, type="cv%")) # Previous value was a variance of 0.025
model## [MAIN]
## KA=THETA_KA*exp(ETA_KA)
## CL=THETA_CL*exp(ETA_CL)
## V2=THETA_V2*exp(ETA_V2)
## V3=THETA_V3*exp(ETA_V3)
## Q=THETA_Q*exp(ETA_Q)
## S2=V2
##
## [ODE]
## d/dt(A_DEPOT)=-KA*A_DEPOT
## d/dt(A_CENTRAL)=KA*A_DEPOT + Q*A_PERIPHERAL/V3 + (-CL/V2 - Q/V2)*A_CENTRAL
## d/dt(A_PERIPHERAL)=-Q*A_PERIPHERAL/V3 + Q*A_CENTRAL/V2
## d/dt(A_OUTPUT)=CL*A_CENTRAL/V2
## F=A_CENTRAL/S2
##
## [ERROR]
## CP=F
## OBS_CP=CP*(EPS_PROP + 1)
## Y=OBS_CP
##
##
## THETA's:
## name index value fix
## 1 KA 1 2 FALSE
## 2 CL 2 5 FALSE
## 3 V2 3 80 FALSE
## 4 V3 4 20 FALSE
## 5 Q 5 4 FALSE
## OMEGA's:
## name index index2 value fix type same
## 1 KA 1 1 0.025 FALSE var NA
## 2 CL 2 2 20.000 FALSE cv% NA
## 3 V2 3 3 0.025 FALSE var NA
## 4 V3 4 4 0.025 FALSE var NA
## 5 Q 5 5 0.025 FALSE var NA
## SIGMA's:
## name index index2 value fix type
## 1 PROP 1 1 0.025 FALSE var
## No variance-covariance matrix
##
## Compartments:
## A_DEPOT (CMT=1)
## A_CENTRAL (CMT=2)
## A_PERIPHERAL (CMT=3)
## A_OUTPUT (CMT=4)
Parameters can be deleted. Please note that it does not do anything to the equations. Also, the indexes won’t be re-adjusted. Here are a few examples:
model <- model %>% delete(Theta("KA"))
model <- model %>% delete(Omega("CL"))
model## [MAIN]
## KA=THETA_KA*exp(ETA_KA)
## CL=THETA_CL*exp(ETA_CL)
## V2=THETA_V2*exp(ETA_V2)
## V3=THETA_V3*exp(ETA_V3)
## Q=THETA_Q*exp(ETA_Q)
## S2=V2
##
## [ODE]
## d/dt(A_DEPOT)=-KA*A_DEPOT
## d/dt(A_CENTRAL)=KA*A_DEPOT + Q*A_PERIPHERAL/V3 + (-CL/V2 - Q/V2)*A_CENTRAL
## d/dt(A_PERIPHERAL)=-Q*A_PERIPHERAL/V3 + Q*A_CENTRAL/V2
## d/dt(A_OUTPUT)=CL*A_CENTRAL/V2
## F=A_CENTRAL/S2
##
## [ERROR]
## CP=F
## OBS_CP=CP*(EPS_PROP + 1)
## Y=OBS_CP
##
##
## THETA's:
## name index value fix
## 1 CL 2 5 FALSE
## 2 V2 3 80 FALSE
## 3 V3 4 20 FALSE
## 4 Q 5 4 FALSE
## OMEGA's:
## name index index2 value fix type same
## 1 KA 1 1 0.025 FALSE var NA
## 2 V2 3 3 0.025 FALSE var NA
## 3 V3 4 4 0.025 FALSE var NA
## 4 Q 5 5 0.025 FALSE var NA
## SIGMA's:
## name index index2 value fix type
## 1 PROP 1 1 0.025 FALSE var
## No variance-covariance matrix
##
## Compartments:
## A_DEPOT (CMT=1)
## A_CENTRAL (CMT=2)
## A_PERIPHERAL (CMT=3)
## A_OUTPUT (CMT=4)
As expected, this model will not be valid anymore:
tryCatch({validObject(model, complete=TRUE)}, error=function(msg) {
print(msg)
})## <simpleError in validObject(model, complete = TRUE): invalid class "campsis_model" object: 1: In slot "parameters" of class "parameters": First THETA index is different than 1
## invalid class "campsis_model" object: 2: In slot "parameters" of class "parameters": No OMEGA with index 2>