$$ \newcommand{\esp}[1]{\mathbb{E}\left(#1\right)} \newcommand{\var}[1]{\mbox{Var}\left(#1\right)} \newcommand{\deriv}[1]{\dot{#1}(t)} \newcommand{\prob}[1]{ \mathbb{P}\!(#1)} \newcommand{\eqdef}{\mathop{=}\limits^{\mathrm{def}}} \newcommand{\by}{\boldsymbol{y}} \newcommand{\bc}{\boldsymbol{c}} \newcommand{\bpsi}{\boldsymbol{\psi}} \def\pmacro{\texttt{p}} \def\like{{\cal L}} \def\llike{{\cal LL}} \def\logit{{\rm logit}} \def\probit{{\rm probit}} \def\one{{\rm 1\!I}} \def\iid{\mathop{\sim}_{\rm i.i.d.}} \def\simh0{\mathop{\sim}_{H_0}} \def\df{\texttt{df}} \def\res{e} \def\xomega{x} \newcommand{\argmin}[1]{{\rm arg}\min_{#1}} \newcommand{\argmax}[1]{{\rm arg}\max_{#1}} \newcommand{\Rset}{\mbox{$\mathbb{R}$}} \def\param{\theta} \def\setparam{\Theta} \def\xnew{x_{\rm new}} \def\fnew{f_{\rm new}} \def\ynew{y_{\rm new}} \def\nnew{n_{\rm new}} \def\enew{e_{\rm new}} \def\Xnew{X_{\rm new}} \def\hfnew{\widehat{\fnew}} \def\degree{m} \def\nbeta{d} \newcommand{\limite}[1]{\mathop{\longrightarrow}\limits_{#1}} \def\ka{k{\scriptstyle a}} \def\ska{k{\scriptscriptstyle a}} \def\kel{k{\scriptstyle e}} \def\skel{k{\scriptscriptstyle e}} \def\cl{C{\small l}} \def\Tlag{T\hspace{-0.1em}{\scriptstyle lag}} \def\sTlag{T\hspace{-0.07em}{\scriptscriptstyle lag}} \def\Tk{T\hspace{-0.1em}{\scriptstyle k0}} \def\sTk{T\hspace{-0.07em}{\scriptscriptstyle k0}} \def\thalf{t{\scriptstyle 1/2}} \newcommand{\Dphi}[1]{\partial_\pphi #1} \def\asigma{a} \def\pphi{\psi} \newcommand{\stheta}{{\theta^\star}} \newcommand{\htheta}{{\widehat{\theta}}}$$

Regular steps - version 1

In this first version, the value of the step function is defined by the amount of the input pulses. Tlag defines the length of the step. Using p=-1 is equivalent to define a negative amount

stepModel1 <- inlineModel("
[LONGITUDINAL] 
input = {tg}

PK:
depot(target=f)
depot(target=f, Tlag=tg, p=-1)

EQUATION:
ddt_f=0 
")


res <- simulx(model=stepModel1, 
              output=list(name='f', time=seq(0, 100, by=0.1)), 
              treatment=list(amount=10, time=seq(12,78,by=12)), 
              parameter=c(tg=6))

ggplot(res$f) + geom_line(aes(time,f))


Regular steps - version 2

In this second version, the value of the step function is defined as an input parameter A. The amount of the input pulse amtDose is ignored since it is multiplied by p=A/amtDose.

Remark that we define f_0=A as initial condition in this example while the signal is a sequence of negative and positive pulses.

stepModel2 <- inlineModel("
[LONGITUDINAL] 
input = {tg,A}

PK:
depot(target=f, p=-A/amtDose)
depot(target=f, Tlag=tg, p=A/amtDose)

EQUATION:
f_0 = A
ddt_f=0 
")


res <- simulx(model=stepModel2, 
              output=list(name='f', time=seq(0, 100, by=0.1)), 
              treatment=list(amount=1, time=seq(12,78,by=12)), 
              parameter=c(tg=6, A=10))

ggplot(res$f) + geom_line(aes(time,f))


Irregular steps

In this example, the signal is a sequence of steps with irregular heights and lengths.

stepModel3 <- inlineModel("
[LONGITUDINAL] 

PK:
depot(target=f, p=1,  type=1)
depot(target=f, p=-1, type=2)

EQUATION:
ddt_f=0 
")

adm1 <- list(amount=c(1, 2, 1, 0.5), time=c(10, 20, 40, 55), type=1)
adm2 <- list(amount=c(1, 2, 1, 0.5), time=c(15, 30, 43, 75), type=2)
res <- simulx(model=stepModel3, 
              output=list(name='f', time=seq(0, 100, by=0.1)), 
              treatment=list(adm1, adm2))

ggplot(res$f) + geom_line(aes(time,f))


Step function with continuous transitions

Using infusions with constant rates lead to replace the Heavyside functions (sudden jumps) with continuous transitions.

adm1 <- list(amount=c(1, 2, 1, 0.5), time=c(10, 20, 40, 55), rate=0.5, type=1)
adm2 <- list(amount=c(1, 2, 1, 0.5), time=c(15, 30, 43, 75), rate=0.25, type=2)
res <- simulx(model=stepModel3, 
              output=list(name='f', time=seq(0, 100, by=0.1)), 
              treatment=list(adm1, adm2))

ggplot(res$f) + geom_line(aes(time,f))