Example 4 — Emax PD Model

Model: 1-compartment IV PK + direct Hill Emax PD in $ERROR Script: examples/04_emax_pd_model.py

Demonstrates a combined PK/PD model where the pharmacodynamic relationship is coded inside the $ERROR block using the PK prediction F as the driving concentration.

$ERROR block

The Hill equation is implemented directly in $ERROR:

E0   = THETA(3)
EMAX = THETA(4)
EC50 = THETA(5)
GAMMA = THETA(6)
IPRED = E0 + EMAX * F**GAMMA / (EC50**GAMMA + F**GAMMA)
W     = THETA(7)
Y     = IPRED + W * EPS(1)
IRES  = DV - IPRED
IWRES = IRES / W

Full model

result = (
    ModelBuilder()
    .problem("1-cmt IV + Emax PD (Hill)")
    .data("emax_pd.csv")
    .subroutines(advan=1, trans=2)
    .pk("""
        K = THETA(1) * EXP(ETA(1))
        V  = THETA(2) * EXP(ETA(2))
    """)
    .error("""
        E0    = THETA(3)
        EMAX  = THETA(4)
        EC50  = THETA(5)
        GAMMA = THETA(6)
        IPRED = E0 + EMAX * F**GAMMA / (EC50**GAMMA + F**GAMMA)
        W     = THETA(7)
        Y     = IPRED + W * EPS(1)
        IRES  = DV - IPRED
        IWRES = IRES / W
    """)
    .theta([(0.01, 0.15, 5.0),
            (1.0, 10.0, 100.0),
            (0.0, 2.0, 20.0),
            (1.0, 15.0, 100.0),
            (0.1, 8.0, 100.0),
            (0.1, 1.2, 5.0),
            (0.1, 1.5, 20.0)])
    .omega([0.3, 0.3])
    .sigma(1.0, fixed=True)
    .estimation(method="FO", maxeval=600)
    .build()
    .fit()
)

Output

openpkpd/estimation/fo.py:114: UserWarning: ETA1 shrinkage is 100.0% (>30%). EBE-based analyses for this parameter may be unreliable.
  res.compute_shrinkage()
openpkpd/estimation/fo.py:114: UserWarning: ETA2 shrinkage is 100.0% (>30%). EBE-based analyses for this parameter may be unreliable.
  res.compute_shrinkage()
Running FO on Emax PD model...
Method: FO
OFV: 139.8735
AIC: 161.8735
BIC: inf   (n_obs = 0)
n_parameters: 11
Converged: True
THETA: [1.00070629e-02 2.69688122e+01 2.00000000e+00 1.50000000e+01
 8.00000000e+00 1.20000000e+00 1.50000000e+00]
OMEGA (diagonal): [0.86297922 0.27771628]
SIGMA (diagonal): [1.96857588]
ETA shrinkage: ['100.0%', '100.0%']
Shrinkage warnings:
  ETA1 shrinkage is 100.0% (>30%). EBE-based analyses for this parameter may be unreliable.
  ETA2 shrinkage is 100.0% (>30%). EBE-based analyses for this parameter may be unreliable.

K=0.010, V=26.97, E0=2.00, Emax=15.00, EC50=8.00, γ=1.20, W=1.50

Figures

Emax curve Effect vs time GOF panel

Notes

  • SIGMA is fixed to 1 and THETA(7) (W) absorbs the residual error scale — this is standard practice for models with custom W in $ERROR.

  • The Hill coefficient GAMMA is bounded (0.1, 1.2, 5.0) to keep the curve physiologically reasonable.

  • With a direct effect model, hysteresis in the C–E loop indicates the assumption of instantaneous equilibrium may be violated.