<!–html_preserve–>RxODE<!–/html_preserve–>

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):
KA CL V2 Q V3 Kin0 Kout EC50 Tz amp pi
0.294 18.6 40.2 10.5 297 1 1 200 8 0.1 3.141593
Covariates ($covs):
ctime
8.000000
8.484849
8.969697
9.454546
9.939394
10.424242
Initial Conditions ( $inits):
eff
1
First part of data (object):
time eff C2 Kin
0.0000000 1.000000 0.00000 1.099195
0.4848485 1.067175 27.76574 1.096795
0.9696970 1.144556 43.67518 1.092837
1.4545455 1.212373 51.75572 1.087385
1.9393939 1.263980 54.76289 1.080527
2.4242424 1.298023 54.57072 1.072373

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.

par(mfrow=c(1,2))
matplot(r1[,"C2"], type="l", ylab="Central Concentration")
matplot(r1[,"eff"], type="l", ylab = "Effect")

plot of chunk unnamed-chunk-4

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".

r2 <- solve(mod3, ev, covs=cov.df,covs_interpolation="constant")
rxHtml(r2)

Solved RxODE object
Parameters ($params):
KA CL V2 Q V3 Kin0 Kout EC50 Tz amp pi
0.294 18.6 40.2 10.5 297 1 1 200 8 0.1 3.141593
Covariates ($covs):
ctime
8.000000
8.484849
8.969697
9.454546
9.939394
10.424242
Initial Conditions ( $inits):
eff
1
First part of data (object):
time eff C2 Kin
0.0000000 1.000000 0.00000 1.099195
0.4848485 1.067628 27.76574 1.096795
0.9696970 1.145644 43.67518 1.092837
1.4545455 1.214226 51.75572 1.087385
1.9393939 1.266668 54.76289 1.080527
2.4242424 1.301567 54.57072 1.072373

which gives the following plots:

par(mfrow=c(1,2))
matplot(r2[,"C2"], type="l", ylab="Central Concentration")
matplot(r2[,"eff"], type="l", ylab = "Effect")

plot of chunk unnamed-chunk-6

In this case, the plots seem to be smoother.