Introduction
While the PKPDsim R package does not include
functionality to perform population estimation within the package, it
does offer a convenient translator to be able to use the nlmixr2 R
package for parameter estimation. nlmixr2 allows
fitting of population PK-PD models using common algorithms applied in
pharmacometrics, such as FOCE and SAEM. For
installation and usage of nlmixr2, please refer to the
documentation in the nlmixr2 package and on the respective
website.
Translation
Under the hood, nlmixr2 uses the rxode2 R
package to perform PKPD model simulations, and which is very similar to
PKPDsim. The model syntax for both rxode2 and
nlmixr2 compared to PKPDsim are also very
similar, making translation fairly straightforward. A model translator
function has therefore been included in PKPDsim that allows
translation of a PKPDsim model to nlmixr2
syntax:
mod <- new_ode_model("pk_1cmt_iv")
f <- pkpdsim_to_nlmixr(
model = mod,
parameters = list(CL = 5, V = 50),
omega = c(0.1, 0.05, 0.1),
res_var = list(prop = 0.1, add = 0.1),
log_transform = TRUE
)The returned object f generated by
pkpdsim_to_nlmixr() is an object that defines the required
model and parameter definitions in nlmixr syntax:
f## function ()
## {
## ini({
## logCL <- log(5)
## logV <- log(50)
## err_prop <- c(0, 0.1, 1)
## err_add <- c(0, 1, 10)
## eta_CL + eta_V ~ c(0.1, 0.05, 0.1)
## })
## model({
## CL <- exp(logCL + eta_CL)
## V <- exp(logV + eta_V)
## d/dt(A1) = -(CL/V) * A1
## y = A1/V
## y ~ prop(err_prop) + add(err_add)
## })
## }
## <environment: 0x5606772d9a60>
A full code example is included below.
Note: both nlmixr and the nlmixr-translator in PKPDsim are still under active development. Syntax and results may therefore change.
Example
library(tidyverse)
library(nlmixr2)
## Define parameters
par <- list(CL = 5, V = 50)
ruv <- list(prop = 0.1, add = 1)
omega <- c(0.1,
0.05, 0.1)
## Simulate data
t_obs <- c(8, 23.5, 25, 71.5)
n <- 50
regimen <- new_regimen(
amt = 1500,
n = 4,
interval = 24
)
conc <- sim(
ode = mod,
regimen = regimen,
parameters = par,
omega = omega,
only_obs = TRUE,
t_obs = t_obs,
n = n,
res_var = ruv
) %>%
mutate(EVID = 0, AMT = 0, MDV = 0, CMT = 1) %>%
select(ID = id, TIME = t, CMT, DV = y, AMT, EVID, MDV)
doses <- regimen_to_nm(
regimen,
n_ind = n
)
## Combine observed data and dose data
simdat <- bind_rows(doses, conc) %>%
arrange(ID, TIME)
## Create nlmixr model object
f <- pkpdsim_to_nlmixr(
model = mod,
parameters = par,
omega = c(0.1, 0.05, 0.1),
res_var = list(prop = 0.1, add = 0.1),
log_transform = TRUE
)
## Perform fit using nlmixr (SAEM)
fit <- nlmixr(
object = f,
data = simdat,
est = "saem"
)
fit