Skip to main content

Example: Derived PK/PD quantities

This example uses [derived] to compute pharmacodynamic metrics from PK predictions after the fit: an Emax response, a TAD-gated Cmax, and time-above-MEC per dosing interval.

The PD parameters (MEC, EMAX, EC50) are fixed at assumed values — they do not enter the PK likelihood and cannot be estimated from PK-only data. Only TVCL, TVV, TVKA, and the random effects are estimated.

For a model where PD observations are also fitted jointly, see Example: simultaneous PK/PD (Emax).

Model

library(ferx)

ex  <- ferx_example("warfarin_derived_pkpd")
ferx_model_show(ex$model)
# model: warfarin_derived_pkpd.ferx 
# Warfarin with PD effect and time-above-MEC derived quantities

[parameters]
  theta TVCL(0.2, 0.001, 10.0)
  theta TVV(10.0, 0.1, 500.0)
  theta TVKA(1.5, 0.01, 50.0)
  theta MEC(0.5)    fix
  theta EMAX(80.0)  fix
  theta EC50(3.0)   fix

  omega ETA_CL ~ 0.09
  omega ETA_V  ~ 0.04
  omega ETA_KA ~ 0.30

  sigma PROP_ERR ~ 0.02 (sd)

[individual_parameters]
  CL = TVCL * exp(ETA_CL)
  V  = TVV  * exp(ETA_V)
  KA = TVKA * exp(ETA_KA)

[structural_model]
  pk one_cpt_oral(cl=CL, v=V, ka=KA)

[error_model]
  DV ~ proportional(PROP_ERR)

[derived]
  KE     = CL / V
  T_HALF = 0.6931472 / KE

  # Emax PD effect at current concentration
  EFF    = EMAX * IPRED / (EC50 + IPRED)

  # TAD-gated Cmax: peak within the current dosing interval
  CMAX_INTERVAL = max(IPRED, TAD < 24)

  # Time above MEC per dosing interval (hours)
  TAM_TAU = integral(1.0, IPRED > MEC, window=24, anchor=0, step=0.1)

  # Time above MEC on day 1 specifically
  TAM_D1  = integral(1.0, IPRED > MEC, from=0, to=24, step=0.1)

[output]
  CL V KA

[fit_options]
  method  = foce
  maxiter = 300

The fixed PD thetas appear with fix in the [parameters] block:

theta MEC(0.5)    fix
theta EMAX(80.0)  fix
theta EC50(3.0)   fix

The [derived] block then uses them to compute:

Column Expression Description
EFF EMAX * IPRED / (EC50 + IPRED) Emax response at each time point
CMAX_INTERVAL max(IPRED, TAD < 24) Peak in current dosing interval
TAM_TAU integral(1.0, IPRED > MEC, window=24, anchor=0, step=0.1) Hours above MEC per 24-h interval
TAM_D1 integral(1.0, IPRED > MEC, from=0, to=24, step=0.1) Hours above MEC on day 1

Fit

fit <- ferx_fit(ex$model, ex$data, verbose = FALSE)
print(fit)
============================================================
 NONLINEAR MIXED EFFECTS MODEL ESTIMATION
============================================================
 Model: warfarin_derived_pkpd    Dataset: warfarin
 Method: FOCE | Gradient: ANALYTIC | Subjects: 10 | Obs: 110

 STATUS: CONVERGED   48 iterations   1.8s
 OFV: -280.3595    AIC: -266.3595    BIC: -247.4561

MODEL STRUCTURE (auto-derived)
------------------------------------------------------------
  Structural:  1-cpt oral  (TVCL, TVV, TVKA, MEC, EMAX, EC50)
  IIV:         ETA_CL, ETA_V, ETA_KA
  IOV:         none
  Residual:    proportional

THETA
------------------------------------------------------------
Parameter            Estimate           SE       %RSE
----------------------------------------------------
TVCL                 0.132974     0.006628        5.0
TVV                  7.730568     0.234046        3.0
TVKA                 0.725259     0.124477       17.2
MEC [FIX]            0.500000          ---        ---
EMAX [FIX]          80.000000          ---        ---
EC50 [FIX]           3.000000          ---        ---

OMEGA  (between-subject variability)
------------------------------------------------------------
  ETA_CL               [log-normal] = 0.028597  (CV% = 17.0)  SE = 0.012799
  ETA_V                [log-normal] = 0.009578  (CV% = 9.8)  SE = 0.004298
  ETA_KA               [log-normal] = 0.348920  (CV% = 64.6)  SE = 0.160785

SIGMA  (residual error)
------------------------------------------------------------
  PROP_ERR         [proportional] = 0.010748  (var = 0.000116, CV% = 1.1)  SE = 0.000942  [initial specified as SD]

SHRINKAGE
------------------------------------------------------------
 ETA_CL: 0.0%   ETA_V: 0.2%   ETA_KA: 0.0%   EPS: 16.0%

DIAGNOSTICS
------------------------------------------------------------
 Covariance: computed   Cond: 2.6   DW: 2.73 [negative autocorrelation]   IWRES lag-1 r: -0.365

RUN INFO
------------------------------------------------------------
 Gradient (requested): auto   (used: analytic)
 ferx v0.4.0.9000 (core v0.4.0)

SETTINGS  (model file / call-time override)
------------------------------------------------------------
  method                       foce  [model only]
  maxiter                      300  [model only]

------------------------------------------------------------
 4 warning  --  call ferx_get_warnings(fit) for details
============================================================

The PK thetas have proper SEs; MEC, EMAX, and EC50 show SE = 0 because they are fixed:

fit$estimates
            param    transform     estimate fixed          se   rse_pct
TVCL         TVCL     identity  0.132974266 FALSE 0.006627764  4.984245
TVV           TVV     identity  7.730567619 FALSE 0.234046431  3.027545
TVKA         TVKA     identity  0.725258574 FALSE 0.124477058 17.163128
MEC           MEC     identity  0.500000000  TRUE          NA        NA
EMAX         EMAX     identity 80.000000000  TRUE          NA        NA
EC50         EC50     identity  3.000000000  TRUE          NA        NA
ETA_CL     ETA_CL     variance  0.028597228 FALSE 0.012799151 44.756613
ETA_V       ETA_V     variance  0.009578216 FALSE 0.004297905 44.871665
ETA_KA     ETA_KA     variance  0.348919533 FALSE 0.160784992 46.080823
PROP_ERR PROP_ERR proportional  0.010748072 FALSE 0.000941583  8.760483
            lower_95   upper_95 estimate_natural lower_95_natural
TVCL     0.119983849 0.14596468               NA               NA
TVV      7.271836614 8.18929862               NA               NA
TVKA     0.481283541 0.96923361               NA               NA
MEC               NA         NA               NA               NA
EMAX              NA         NA               NA               NA
EC50              NA         NA               NA               NA
ETA_CL   0.003510892 0.05368356               NA               NA
ETA_V    0.001154322 0.01800211               NA               NA
ETA_KA   0.033780947 0.66405812               NA               NA
PROP_ERR 0.008902569 0.01259357               NA               NA
         upper_95_natural init_as_sd weight      scale level class
TVCL                   NA      FALSE   <NA>       <NA>  <NA>    NA
TVV                    NA      FALSE   <NA>       <NA>  <NA>    NA
TVKA                   NA      FALSE   <NA>       <NA>  <NA>    NA
MEC                    NA      FALSE   <NA>       <NA>  <NA>    NA
EMAX                   NA      FALSE   <NA>       <NA>  <NA>    NA
EC50                   NA      FALSE   <NA>       <NA>  <NA>    NA
ETA_CL                 NA      FALSE   <NA> log_normal  <NA>    NA
ETA_V                  NA      FALSE   <NA> log_normal  <NA>    NA
ETA_KA                 NA      FALSE   <NA> log_normal  <NA>    NA
PROP_ERR               NA       TRUE   <NA>       <NA>  <NA>    NA

PD derived columns

head(fit$sdtab[, c("ID", "TIME", "IPRED", "EFF", "TAM_TAU", "TAM_D1",
                   "CMAX_INTERVAL")], 12)
   ID  TIME     IPRED      EFF TAM_TAU TAM_D1 CMAX_INTERVAL
1   1   0.5  5.354089 51.27155      24     24      11.38196
2   1   1.0  8.285651 58.73406      24     24      11.38196
3   1   2.0 10.708975 62.49322      24     24      11.38196
4   1   4.0 11.381964 63.31243      24     24      11.38196
5   1   8.0 10.756208 62.55333      24     24      11.38196
6   1  12.0 10.067873 61.63435      24     24      11.38196
7   1  24.0  8.253757 58.67379      24     24      11.38196
8   1  48.0  5.547264 51.92084      24     24      11.38196
9   1  72.0  3.728258 44.32955      24     24      11.38196
10  1  96.0  2.505723 36.40899      24     24      11.38196
11  1 120.0  1.684070 28.76251      24     24      11.38196
12  2   0.5  3.230997 41.48289      24     24      12.10263

EFF varies per time point (it depends on IPRED). CMAX_INTERVAL, TAM_TAU, and TAM_D1 are aggregate quantities — constant per 24-h window or per subject.

Why step= for time-above-threshold

TAM_TAU uses step=0.1 to force grid evaluation at 0.1-hour intervals. Without step=, only observation time points are evaluated. If the observation design is sparse (large gaps between samples), the trapezoidal rule can miss brief periods above threshold between those times. The step= argument fills in the gaps:

# Without step= (observation-time only -- can miss threshold crossings):
TAM_approx = integral(1.0, IPRED > MEC, window=24, anchor=0)

# With step=0.1 (fine grid -- catches brief excursions):
TAM_TAU    = integral(1.0, IPRED > MEC, window=24, anchor=0, step=0.1)

See also