Reads the per-iteration trace CSV written when optimizer_trace = TRUE was passed to ferx_fit. Returns a tidy data frame with one row per optimizer iteration (or per OFV evaluation for NLopt-based methods).

ferx_trace(fit)

Arguments

fit

Optional. A ferx_fit object returned by ferx_fit, or a character string giving the path to a trace CSV file written by ferx. If omitted, uses the trace from the last ferx_fit() call in this session.

Value

A data frame with columns:

iter

Iteration / evaluation index (integer)

method

Estimation method: "foce", "focei", "gn", "gn_hybrid", "saem"

phase

Sub-phase label (empty string for single-phase methods)

ofv

Objective function value at this iteration

wall_ms

Wall-clock milliseconds elapsed since the start of the fit

grad_norm

L2 norm of the gradient (NA for gradient-free optimizers)

step_norm

L2 norm of the parameter step (NA when unavailable)

inner_iter_count

NA (reserved for future inner-loop counts)

optimizer

Optimizer name string, e.g. "slsqp", "bobyqa", "bfgs"

lm_lambda

Levenberg-Marquardt damping factor (Gauss-Newton only)

ofv_delta

OFV change from the previous accepted step (Gauss-Newton only)

step_accepted

1 if the GN step was accepted, 0 if rejected (NA otherwise)

cond_nll

Conditional negative log-likelihood (SAEM only)

gamma

SAEM step-size schedule gamma

mh_accept_rate

Metropolis-Hastings acceptance rate (SAEM only)

Details

Called with no argument, returns the trace from the most recent ferx_fit() call in the current R session and prints a one-line message indicating when that fit was started. Named ferx_trace() rather than trace() to avoid masking base::trace().

Examples

ex  <- ferx_example("warfarin")
fit <- ferx_fit(ex$model, ex$data, method = "gn", covariance = FALSE,
                optimizer_trace = TRUE)
#> Warning: Model file [fit_options] sets `method = foce` but ferx_fit() argument overrides it with `gn`. The call-time value will be used.
#> Warning: Model file [fit_options] sets `covariance = true` but ferx_fit() argument overrides it with `false`. The call-time value will be used.
#> Mu-referencing detected for: ETA_CL, ETA_KA, ETA_V
#> Negative IWRES autocorrelation detected (Durbin-Watson = 2.61, lag-1 r = -0.37).
#> Possible over-parameterisation or misspecified residual error model.
tr  <- ferx_trace(fit)
head(tr)
#>   iter method phase       ofv wall_ms grad_norm step_norm inner_iter_count
#> 1    1     gn    NA -275.8764       1        NA        NA               NA
#> 2    2     gn    NA -278.5205       2        NA        NA               NA
#> 3    3     gn    NA -279.3926       3        NA        NA               NA
#> 4    4     gn    NA -279.6479       4        NA        NA               NA
#> 5    5     gn    NA -279.8435       5        NA        NA               NA
#> 6    6     gn    NA -279.9383       6        NA        NA               NA
#>   optimizer lm_lambda ofv_delta step_accepted cond_nll gamma mh_accept_rate
#> 1        NA   3.0e-03 -5.952311             1       NA    NA             NA
#> 2        NA   9.0e-04 -2.644174             1       NA    NA             NA
#> 3        NA   2.7e-04 -0.872105             1       NA    NA             NA
#> 4        NA   8.1e-05 -0.255300             1       NA    NA             NA
#> 5        NA   2.4e-05 -0.195524             1       NA    NA             NA
#> 6        NA   7.0e-06 -0.094832             1       NA    NA             NA
#>   n_ebe_unconverged n_ebe_fallback
#> 1                NA             NA
#> 2                NA             NA
#> 3                NA             NA
#> 4                NA             NA
#> 5                NA             NA
#> 6                NA             NA