Control for n1qn1 estimation method in nlmixr2
Usage
n1qn1Control(
epsilon = NULL,
max_iterations = 10000,
nsim = 10000,
imp = 0,
print.functions = FALSE,
returnN1qn1 = FALSE,
stopFile = NULL,
maxTime = NULL,
stickyRecalcN = 4,
maxOdeRecalc = 5,
odeRecalcFactor = 10^(0.5),
indTolRelax = TRUE,
useColor = NULL,
printNcol = NULL,
print = 1L,
normType = c("rescale2", "mean", "rescale", "std", "len", "constant"),
scaleType = c("nlmixr2", "norm", "mult", "multAdd"),
scaleCmax = 1e+05,
scaleCmin = 1e-05,
scaleC = NULL,
scaleTo = 1,
gradTo = 1,
rxControl = NULL,
optExpression = TRUE,
sumProd = FALSE,
literalFix = TRUE,
literalFixRes = TRUE,
addProp = c("combined2", "combined1"),
eventSens = c("jump", "fd"),
sensMethod = c("default", "forward"),
calcTables = TRUE,
compress = FALSE,
covMethod = c("r", "n1qn1", ""),
adjObf = TRUE,
aboveStartTol = 0.01,
ci = 0.95,
sigdig = 3,
sigdigTable = NULL,
boundedTransform = TRUE,
thetaBoundWarn = 1e-04,
...,
condWarn = 1000
)Arguments
- epsilon
Precision of estimate for n1qn1 optimization.
- max_iterations
Number of iterations
- nsim
Number of function evaluations
- imp
Verbosity of messages.
- print.functions
Boolean to control if the function value and parameter estimates are echoed every time a function is called.
- returnN1qn1
return the n1qn1 output instead of the nlmixr2 fit
- stopFile
Path of a file that, once created, stops the estimation gracefully: the run ends at its current state (for FOCEi, the lowest objective evaluated so far), removes the file, notes the stop in `$runInfo` and returns the fit. `NULL` (default) does not poll.
- maxTime
Wall-clock limit in seconds, counted from the start of the estimation. Once it is reached the optimization ends as for `stopFile` and the fit is finalized from its current state; the covariance step and tables are not limited. `NULL` (default) sets no limit.
- stickyRecalcN
The number of bad ODE solves before reducing the atol/rtol for the rest of the problem.
- maxOdeRecalc
Maximum number of times to reduce the ODE tolerances and try to resolve the system if there was a bad ODE solve.
- odeRecalcFactor
The ODE recalculation factor when ODE solving goes bad, this is the factor the rtol/atol is reduced
- indTolRelax
When `TRUE` (default), only subjects whose ODE solve produced NaN/Inf have their tolerances relaxed, and the relaxed tolerance persists across optimizer calls (sticky). When `FALSE`, all subjects have their tolerances relaxed on each retry and tolerances are reset afterward.
- useColor
Logical (or `NULL`) emit ANSI bold/color escapes in the iteration print. `NULL` (default) defers to [crayon::has_color()].
- printNcol
Integer (or `NULL`) parameter columns per row before wrapping. `NULL` (default) uses `floor((getOption("width") - 23) / 12)`.
Either a scalar print-frequency (`0` = suppress, `1` (default) = every evaluation, `N` = every Nth), OR a pre-built [iterPrintControl()] object. Equivalent to `iterPrintControl(every = print, ncol = printNcol, useColor = useColor)`.
- normType
Parameter normalization/scaling used to get scaled initial values for
scaleType, of the formVscaled = (Vunscaled-C1)/C2(see Feature Scaling;rescale2follows the OptdesX manual):"rescale2"scales all parameters to (-1, 1);"rescale"(min-max) scales to (0, 1);"mean"centers on the mean with range (0, 1);"std"standardizes by mean/sd;"len"scales to unit (Euclidean) length;"constant"performs no normalization (C1=0,C2=1).- scaleType
The scaling scheme for nlmixr2:
"nlmixr2"(default) scales as(current-init)*scaleC[i] + scaleTo, withscaleTofromnormTypeand scales fromscaleC;"norm"uses the simple scaling fromnormType;"mult"scales multiplicatively ascurrent/init*scaleTo;"multAdd"scales linearly ((current-init)+scaleTo) for parameters in an exponential block (e.g.exp(theta)) and multiplicatively otherwise.- scaleCmax
Maximum value of the scaleC to prevent overflow.
- scaleCmin
Minimum value of the scaleC to prevent underflow.
- scaleC
Scaling constant used with
scaleType="nlmixr2"; when not specified, chosen by parameter type to keep gradient sizes similar on a log scale: `1` for exp()-transformed/power/boxCox/ yeoJohnson parameters, `0.5*abs(est)` for additive/proportional/ lognormal error parameters, `abs(1/digamma(est+1))` for factorials, and `log(abs(est))*abs(est)` for log-scale parameters. May be set explicitly per parameter if these defaults don't apply well.- scaleTo
Scale the initial parameter estimate to this value. By default this is 1. When zero or below, no scaling is performed.
- gradTo
this is the factor that the gradient is scaled to before optimizing. This only works with scaleType="nlmixr2".
- rxControl
`rxode2` ODE solving options during fitting, created with `rxControl()`. The solver's adaptive steps set the objective's noise floor, which grows with `rtol` and the number of observations. For a non-stiff model, `rxControl(method = "dop853")` gives a much smoother objective than the default `"liblsoda"` at the same `rtol`.
- optExpression
Optimize the rxode2 expression to speed up calculation. By default this is turned on.
- sumProd
Is a boolean indicating if the model should change multiplication to high precision multiplication and sums to high precision sums using the PreciseSums package. By default this is
FALSE.- literalFix
boolean, substitute fixed population values as literals and re-adjust ui and parameter estimates after optimization; Default is `TRUE`.
- literalFixRes
boolean, substitute fixed population values as literals and re-adjust ui and parameter estimates after optimization; Default is `TRUE`.
- addProp
Type of additive-plus-proportional error: `"combined1"`, where standard deviations add: $$y = f + (a + b\times f^c) \times \varepsilon$$; or `"combined2"`, where variances add: $$y = f + \sqrt{a^2 + b^2\times f^{2\times c}} \times \varepsilon$$. Here y = observed, f = predicted, a = additive sd, b = proportional/power sd, c = power exponent (1 in the proportional case).
- eventSens
Controls how dosing/event-parameter (`alag`, `F`, `rate`, `dur`) sensitivities are computed for THETA/ETA gradients: `"jump"` (default) uses rxode2's analytic event sensitivities; `"fd"` uses the legacy finite-difference behavior. Also gates the analytic moving-boundary correction for a modeled `alag()`/`f()` on a `linCmt()` compartment; set `"fd"` if that model infuses a dose into the lagged/scaled compartment (rxode2/rxode2#1236), or if the regimen also doses an *unlagged/unscaled* compartment alongside the lagged/scaled one – a common design for estimating `f()` from paired IV+oral data (rxode2/rxode2#1237).
- sensMethod
Method used to compute the ODE parameter sensitivities. `"forward"` uses the classic variational (forward) sensitivity ODEs; `"default"` is the same thing.
- calcTables
This boolean is to determine if the foceiFit will calculate tables. By default this is
TRUE- compress
Should the object have compressed items
- covMethod
Method for calculating the covariance.
"r"(the default) uses nlmixr2'snlmixr2Hess()Hessian;"n1qn1"uses the optimizer's own Hessian, the quasi-Newton approximation n1qn1 built along its path (H), not a finite-difference Hessian at the estimates;""skips the covariance step.- adjObf
is a boolean to indicate if the objective function should be adjusted to be closer to NONMEM's default objective function. By default this is
TRUE- aboveStartTol
Warn (in `$runInfo`) when the final objective is above the objective at the initial estimates by more than this fraction of its magnitude (at least 0.1 objective units). Use `NA` or `Inf` to disable.
- ci
Confidence level for some tables. By default this is 0.95 or 95% confidence.
- sigdig
Optimization significant digits. One value drives, with a single consistent formula, the inner/outer optimizer convergence tolerance (
10^-sigdig), the boundary check tolerance (5*10^(-sigdig+1)), and the ODE solver tolerancesrtol = max(10^(-2*sigdig), 1e-12),atol = rtol/100for every solver. An objective solved to relative errorrtollocates its minimum only to aboutsqrt(rtol), so this is the solve a10^-sigdigoptimizer needs. The sensitivity (atolSens/rtolSens) tolerances match the main solve; the steady-state (ssAtol/ssRtol) tolerances run one order looser. At the defaultsigdig = 3this isatol = 1e-8,rtol = 1e-6.- sigdigTable
Significant digits in the final output table. If not specified (`NULL`), it defaults to `sigdig`.
- boundedTransform
When `TRUE` (default), bounded parameters are transformed for unbounded optimization methods and back-transformed for final estimates. `FALSE` optimizes on the original scale with bounds passed to the optimizer. `NA` transforms for optimization but skips the final back-transform.
- thetaBoundWarn
Warn (in `$runInfo`) when an estimated theta ends within this tolerance of a finite `lower`/`upper` bound, relative to the bound range (or, for a one-sided bound, to the larger of the bound's size and the initial estimate's distance from it). Use `NA` or `0` to disable.
- ...
Ignored parameters
- condWarn
warn when the condition number of the covariance's correlation matrix exceeds this;
NAorInfturns the warning off.
Examples
# \donttest{
# A logit regression example with emax model
dsn <- data.frame(i=1:1000)
dsn$time <- exp(rnorm(1000))
dsn$DV=rbinom(1000,1,exp(-1+dsn$time)/(1+exp(-1+dsn$time)))
mod <- function() {
ini({
E0 <- 0.5
Em <- 0.5
E50 <- 2
g <- fix(2)
})
model({
v <- E0+Em*time^g/(E50^g+time^g)
ll(bin) ~ DV * v - log(1 + exp(v))
})
}
fit2 <- nlmixr(mod, dsn, est="n1qn1")
#>
#>
#>
#>
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
#> ℹ Need to run with the source intact to parse comments
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of population log-likelihood model...
#> ✔ done
#> → calculate ∂(f)/∂(θ)
#> → finding duplicate expressions in nlm llik gradient...
#> → finding duplicate expressions in nlm pred-only...
#>
#>
#>
#>
#> → calculating covariance
#> ✔ done
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of full model...
#> ✔ done
#> → finding duplicate expressions in EBE model...
#> → compiling EBE model...
#>
#>
#> ✔ done
#> → Calculating residuals/tables
#> ✔ done
print(fit2)
#> ── nlmixr² log-likelihood n1qn1 ──
#>
#> OBJF AIC BIC Log-likelihood Condition#(Cov) Condition#(Cor)
#> lPop -700.7994 1143.078 1157.801 -568.5388 1026.07 110.139
#>
#> ── Time (sec $time): ──
#>
#> setup optimize covariance preprocess postprocess table compress
#> elapsed 0.1268686 0.1918982 1.3626e-05 0.066 0.008 0.024 0.001
#> other
#> elapsed 0.09121953
#>
#> ── ($parFixed or $parFixedDf): ──
#>
#> Est. SE %RSE Back-transformed(95%CI)
#> E0 -0.755 0.121 16.1 -0.755 (-0.993, -0.517)
#> Em 6.67 1.98 29.8 6.67 (2.78, 10.6)
#> E50 3.45 0.900 26.1 3.45 (1.69, 5.21)
#> g 2.00 FIXED FIXED 2.00
#>
#> Covariance Type ($covMethod): r
#> Some strong fixed parameter correlations exist ($cor) :
#> cor:Em,E0 cor:E50,E0 cor:E50,Em
#> 0.451 0.631 0.954
#>
#>
#> Information about run found ($runInfo):
#> • highly correlated estimates: Em/E50 (0.95)
#> Censoring ($censInformation): No censoring
#>
#> ── Fit Data (object is a modified tibble): ──
#> # A tibble: 1,000 × 5
#> ID TIME DV IPRED v
#> <fct> <dbl> <dbl> <dbl> <dbl>
#> 1 1 0.0591 0 -0.386 -0.753
#> 2 1 0.0591 0 -0.386 -0.753
#> 3 1 0.0628 0 -0.386 -0.753
#> # ℹ 997 more rows
# you can also get the nlm output with fit2$n1qn1
fit2$n1qn1
#> $value
#> [1] 568.5388
#>
#> $par
#> E0 Em E50
#> -0.7550033 6.6658992 3.4507626
#>
#> $H
#> [,1] [,2] [,3]
#> [1,] 738.71994 78.31006 -56.403355
#> [2,] 78.31006 20.39595 -12.245188
#> [3,] -56.40335 -12.24519 7.872638
#>
#> $c.hess
#> [1] 738.719940 78.310062 -56.403355 20.395947 -12.245188 7.872638
#> [7] 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
#> [13] 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
#> [19] 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
#>
#> $n.fn
#> [1] 20
#>
#> $n.gr
#> [1] 20
#>
#> $scaleC
#> [1] 2.0 2.0 0.5
#>
#> $par.scaled
#> E0 Em E50
#> -1.627502 2.082950 3.901525
#>
#> $hessian
#> E0 Em E50
#> E0 787.84272 81.81411 -59.819605
#> Em 81.81411 19.88000 -12.201985
#> E50 -59.81961 -12.20198 8.002765
#>
#> $cov.scaled
#> E0 Em E50
#> E0 0.003683185 0.02712951 0.06889626
#> Em 0.027129510 0.98391394 1.70298393
#> E50 0.068896257 1.70298393 3.23652290
#>
#> $r
#> E0 Em E50
#> E0 787.84272 81.81411 -59.819605
#> Em 81.81411 19.88000 -12.201985
#> E50 -59.81961 -12.20198 8.002765
#>
# The nlm control has been modified slightly to include
# extra components and name the parameters
# }
