How to stack models using model piping #705
Answered
by
mattfidler
john-harrold
asked this question in
Q&A
-
I'm trying to combine two models below. What I'm doing clearly doesn't work :). Can someone show me an example of what does? library(rxode2)
PK =
function() {
description <- "One compartment PK model with linear clearance using differential equations"
dosing <- c("central", "depot")
ini({
lka <- 0.45
label("Absorption rate (Ka)")
lcl <- 1
label("Clearance (CL)")
lvc <- 3.45
label("Central volume of distribution (V)")
propSd <- c(0, 0.5)
label("Proportional residual error (fraction)")
})
model({
ka <- exp(lka)
cl <- exp(lcl)
vc <- exp(lvc)
kel <- cl/vc
d/dt(depot) <- -ka * depot
d/dt(central) <- ka * depot - kel * central
Cc <- central/vc
Cc ~ prop(propSd)
})
}
PD <- function() {
description <- "Signal transduction model for delayed concentration effects on cancer cell growth"
reference <- "Lobo ED, Balthasar JP. Pharmacodynamic modeling of chemotherapeutic effects: Application of a transit compartment model to characterize methotrexate effects in vitro. AAPS J. 2002;4(4):212-222. doi:10.1208/ps040442"
depends<-"Cc"
units<-list(time="hr")
# Values for lkng, ltau, lec50, and kmax are for methotrexate from Lobo 2002,
# Table 2. propErr and addErr are added as reasonable values though not from
# Lobo 2002 where no value is apparent in the paper.
ini({
lkng <- log(0.02) ; label("Cell net growth rate (growth minus death) (1/hr)")
ltau <- log(34.1) ; label("Mean transit time of each transit compartment (hr)")
lec50 <- log(0.1) ; label("Drug concentration reducing the cell growth by 50% (ug/mL)")
kmax <- 0.29 ; label("Maximum drug-related reduction in cell growth (1/hr)")
tumorVolpropSd <- c(0, 0.3) ; label("Proportional residual error (fraction)")
tumorVoladdSd <- c(0, 50, 1000) ; label("Additive residual error (tumor volume units)")
})
model({
# Cc is the drug concentration
kng <- exp(lkng)
tau <- exp(ltau)
ec50 <- exp(lec50)
drugEffectTumorVol <- kmax*Cc/(ec50 + Cc)
tumorVol(0) <- tumorVol0
d/dt(tumorVol) <- kng*tumorVol - transit4*tumorVol
d/dt(transit1) <- (drugEffectTumorVol - transit1)/tau
d/dt(transit2) <- (transit1 - transit2)/tau
d/dt(transit3) <- (transit2 - transit3)/tau
d/dt(transit4) <- (transit3 - transit4)/tau
tumorVol ~ prop(tumorVolpropSd) + add(tumorVoladdSd)
})
}
PKPD = PK |> PD() |
Beta Was this translation helpful? Give feedback.
Answered by
mattfidler
Jul 4, 2024
Replies: 1 comment 1 reply
-
Hi, You use https://nlmixr2.github.io/rxode2/articles/Modifying-Models.html#combine-different-models library(rxode2)
#> rxode2 2.1.3.9000 using 8 threads (see ?getRxThreads)
#> no cache: create with `rxCreateCache()` PK <-
function() {
description <- "One compartment PK model with linear clearance using differential equations"
dosing <- c("central", "depot")
ini({
lka <- 0.45
label("Absorption rate (Ka)")
lcl <- 1
label("Clearance (CL)")
lvc <- 3.45
label("Central volume of distribution (V)")
propSd <- c(0, 0.5)
label("Proportional residual error (fraction)")
})
model({
ka <- exp(lka)
cl <- exp(lcl)
vc <- exp(lvc)
kel <- cl/vc
d/dt(depot) <- -ka * depot
d/dt(central) <- ka * depot - kel * central
Cc <- central/vc
Cc ~ prop(propSd)
})
}
PD <- function() {
description <- "Signal transduction model for delayed concentration effects on cancer cell growth"
reference <- "Lobo ED, Balthasar JP. Pharmacodynamic modeling of chemotherapeutic effects: Application of a transit compartment model to characterize methotrexate effects in vitro. AAPS J. 2002;4(4):212-222. doi:10.1208/ps040442"
depends<-"Cc"
units<-list(time="hr")
# Values for lkng, ltau, lec50, and kmax are for methotrexate from Lobo 2002,
# Table 2. propErr and addErr are added as reasonable values though not from
# Lobo 2002 where no value is apparent in the paper.
ini({
lkng <- log(0.02) ; label("Cell net growth rate (growth minus death) (1/hr)")
ltau <- log(34.1) ; label("Mean transit time of each transit compartment (hr)")
lec50 <- log(0.1) ; label("Drug concentration reducing the cell growth by 50% (ug/mL)")
kmax <- 0.29 ; label("Maximum drug-related reduction in cell growth (1/hr)")
tumorVolpropSd <- c(0, 0.3) ; label("Proportional residual error (fraction)")
tumorVoladdSd <- c(0, 50, 1000) ; label("Additive residual error (tumor volume units)")
})
model({
# Cc is the drug concentration
kng <- exp(lkng)
tau <- exp(ltau)
ec50 <- exp(lec50)
drugEffectTumorVol <- kmax*Cc/(ec50 + Cc)
tumorVol(0) <- tumorVol0
d/dt(tumorVol) <- kng*tumorVol - transit4*tumorVol
d/dt(transit1) <- (drugEffectTumorVol - transit1)/tau
d/dt(transit2) <- (transit1 - transit2)/tau
d/dt(transit3) <- (transit2 - transit3)/tau
d/dt(transit4) <- (transit3 - transit4)/tau
tumorVol ~ prop(tumorVolpropSd) + add(tumorVoladdSd)
})
}
PKPD <- PK |> rxAppendModel(PD)
PKPD
#> ── rxode2-based free-form 7-cmt ODE model ──────────────────────────────────────
#> ── Initalization: ──
#> Fixed Effects ($theta):
#> lka lcl lvc propSd lkng
#> 0.450000 1.000000 3.450000 0.500000 -3.912023
#> ltau lec50 kmax tumorVolpropSd tumorVoladdSd
#> 3.529297 -2.302585 0.290000 0.300000 50.000000
#>
#> States ($state or $stateDf):
#> Compartment Number Compartment Name
#> 1 1 depot
#> 2 2 central
#> 3 3 tumorVol
#> 4 4 transit1
#> 5 5 transit2
#> 6 6 transit3
#> 7 7 transit4
#> ── Multiple Endpoint Model ($multipleEndpoint): ──
#> variable cmt dvid*
#> 1 Cc ~ … cmt='Cc' or cmt=8 dvid='Cc' or dvid=1
#> 2 tumorVol ~ … cmt='tumorVol' or cmt=3 dvid='tumorVol' or dvid=2
#> * If dvids are outside this range, all dvids are re-numered sequentially, ie 1,7, 10 becomes 1,2,3 etc
#>
#> ── Model (Normalized Syntax): ──
#> function() {
#> depends <- "Cc"
#> description <- "Signal transduction model for delayed concentration effects on cancer cell growth"
#> dosing <- c("central", "depot")
#> reference <- "Lobo ED, Balthasar JP. Pharmacodynamic modeling of chemotherapeutic effects: Application of a transit compartment model to characterize methotrexate effects in vitro. AAPS J. 2002;4(4):212-222. doi:10.1208/ps040442"
#> units <- list(time = "hr")
#> ini({
#> lka <- 0.45
#> label("Absorption rate (Ka)")
#> lcl <- 1
#> label("Clearance (CL)")
#> lvc <- 3.45
#> label("Central volume of distribution (V)")
#> propSd <- c(0, 0.5)
#> label("Proportional residual error (fraction)")
#> lkng <- -3.91202300542815
#> label("Cell net growth rate (growth minus death) (1/hr)")
#> ltau <- 3.52929738428947
#> label("Mean transit time of each transit compartment (hr)")
#> lec50 <- -2.30258509299405
#> label("Drug concentration reducing the cell growth by 50% (ug/mL)")
#> kmax <- 0.29
#> label("Maximum drug-related reduction in cell growth (1/hr)")
#> tumorVolpropSd <- c(0, 0.3)
#> label("Proportional residual error (fraction)")
#> tumorVoladdSd <- c(0, 50, 1000)
#> label("Additive residual error (tumor volume units)")
#> })
#> model({
#> ka <- exp(lka)
#> cl <- exp(lcl)
#> vc <- exp(lvc)
#> kel <- cl/vc
#> d/dt(depot) <- -ka * depot
#> d/dt(central) <- ka * depot - kel * central
#> Cc <- central/vc
#> Cc ~ prop(propSd)
#> kng <- exp(lkng)
#> tau <- exp(ltau)
#> ec50 <- exp(lec50)
#> drugEffectTumorVol <- kmax * Cc/(ec50 + Cc)
#> tumorVol(0) <- tumorVol0
#> d/dt(tumorVol) <- kng * tumorVol - transit4 * tumorVol
#> d/dt(transit1) <- (drugEffectTumorVol - transit1)/tau
#> d/dt(transit2) <- (transit1 - transit2)/tau
#> d/dt(transit3) <- (transit2 - transit3)/tau
#> d/dt(transit4) <- (transit3 - transit4)/tau
#> tumorVol ~ prop(tumorVolpropSd) + add(tumorVoladdSd)
#> })
#> } Created on 2024-07-04 with reprex v2.1.0 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
mattfidler
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
You use
rxAppendModel()
as described here:https://nlmixr2.github.io/rxode2/articles/Modifying-Models.html#combine-different-models