Covariates are easy to specify in RxODE, you can specify them as a variable. Time-varying covariates, like clock time in a circadian rhythm model, can also be used. Extending the indirect response model already discussed, we have:
library(RxODE)
mod3 <- RxODE({
KA=2.94E-01;
CL=1.86E+01;
V2=4.02E+01;
Q=1.05E+01;
V3=2.97E+02;
Kin0=1;
Kout=1;
EC50=200;
## The linCmt() picks up the variables from above
C2 = linCmt();
Tz= 8
amp=0.1
eff(0) = 1 ## This specifies that the effect compartment starts at 1.
## Kin changes based on time of day (like cortosol)
Kin = Kin0 +amp *cos(2*pi*(ctime-Tz)/24)
d/dt(eff) = Kin - Kout*(1-C2/(EC50+C2))*eff;
})
ev <- eventTable(amount.units="mg", time.units="hours") %>%
add.dosing(dose=10000, nbr.doses=1, dosing.to=2) %>%
add.sampling(seq(0,48,length.out=100));
## Create data frame of 8 am dosing for the first dose
cov.df <- data.frame(ctime =(seq(0,48,length.out=100)+8) %% 24);
Now there is a covariate present, the system can be solved using the cov option
r1 <- solve(mod3, ev, covs=cov.df,covs_interpolation="linear")
rxHtml(r1)
Solved RxODE object | ||||||||||||||||||||||||||||||
Parameters ($params): | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
Covariates ($covs):
|
||||||||||||||||||||||||||||||
Initial Conditions ( $inits): | ||||||||||||||||||||||||||||||
|
When solving ODE equations, the solver may sample times outside of the data. When this happens, this ODE solver uses linear interpolation between the covariate values. This is the default value. It is equivalent to R’s approxfun
with method="linear"
, which is the default approxfun
.
library(ggplot2)
ggplot(r1,aes(time,C2)) + geom_line() + ylab("Central Concentration") + xlab("Time");
ggplot(r1,aes(time,eff)) + geom_line() + ylab("Effect") + xlab("Time");
Note that the linear approximation in this case leads to some kinks in the solved system at 24-hours where the covariate has a linear interpolation between near 24 and near 0.
In RxODE, covariate interpolation can also be the last observation carried forward, or constant approximation. This is equivalent to R’s approxfun
with method="constant"
.
r{r,results="asis"} r2 <- solve(mod3, ev, covs=cov.df,covs_interpolation="constant") rxHtml(r2)
which gives the following plots:
ggplot(r1,aes(time,C2)) + geom_line() + ylab("Central Concentration") + xlab("Time");
ggplot(r1,aes(time,eff)) + geom_line() + ylab("Effect") + xlab("Time");
In this case, the plots seem to be smoother.
You can also use NONMEM’s preferred interpolation style of next observation carried backward (NOCB): eeee
r2 <- solve(mod3, ev, covs=cov.df,covs_interpolation="nocb")
rxHtml(r2)
Solved RxODE object | ||||||||||||||||||||||||||||||
Parameters ($params): | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
Covariates ($covs):
|
||||||||||||||||||||||||||||||
Initial Conditions ( $inits): | ||||||||||||||||||||||||||||||
|
which gives the following plots:
ggplot(r1,aes(time,C2)) + geom_line() + ylab("Central Concentration") + xlab("Time");
ggplot(r1,aes(time,eff)) + geom_line() + ylab("Effect") + xlab("Time");