Skip to contents

Applies the (cached) adjoint expansion, solves with the requested adjoint method, and drops the internal rx__adj* lhs, returning the full-trajectory rx__sens_<state>_BY_<param>__ columns. The stiff analytic Jacobian is emitted into the expansion automatically, inferred from method. For a model with delay(), the delayed-state term of the adjoint is first order in the step size whatever the method's order, and an adaptive method's error control does not limit it: cap the step with hmax (or use a fixed-step method with a small hmin) for accurate sensitivities.

Usage

rxSolveAdjointRk4(
  object,
  events,
  params = NULL,
  calcSens,
  method = "rk4s",
  ...
)

Arguments

object

model definition accepted by rxode2().

events

an rxode2 event table / data set.

params

optional named parameter vector or data frame (per subject).

calcSens

character vector of parameters to differentiate w.r.t.

method

adjoint solve method (default "rk4s"). May be a composite ("dop853s+ros4s").

...

passed to rxSolve().

Value

the solved data frame with rx__sens_<state>_BY_<param>__ columns.

Author

Matthew L. Fidler

Examples

# \donttest{
pk <- function() {
  model({
    d/dt(depot) <- -ka * depot
    d/dt(central) <- ka * depot - cl / v * central
  })
}
ev <- et(amt = 100, cmt = "depot") |> et(c(1, 2, 4, 8, 12))
rxSolveAdjointRk4(rxode2(pk), ev, params = c(ka = 1.2, cl = 3.5, v = 25),
                  calcSens = c("ka", "cl"))
#>  
#>  
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
#> ℹ Need to run with the source intact to parse comments
#>  
#>  
#>   time        depot  central rx__sens_depot_BY_ka__ rx__sens_depot_BY_cl__
#> 1    1 3.011942e+01 64.32046          -3.011942e+01                      0
#> 2    2 9.071795e+00 75.29047          -1.814359e+01                      0
#> 3    4 8.229747e-01 63.73351          -3.291899e+00                      0
#> 4    8 6.772874e-03 36.92967          -5.418299e-02                      0
#> 5   12 5.573904e-05 21.09888          -6.688684e-04                      0
#>   rx__sens_central_BY_ka__ rx__sens_central_BY_cl__
#> 1                27.018163                -1.509530
#> 2                12.253227                -4.003684
#> 3                -3.288016                -7.941390
#> 4                -4.003247               -10.426375
#> 5                -2.321446                -9.331307
# }