ferx_trace.RdReads 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)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.
A data frame with columns:
Iteration / evaluation index (integer)
Estimation method: "foce", "focei", "gn", "gn_hybrid", "saem"
Sub-phase label (empty string for single-phase methods)
Objective function value at this iteration
Wall-clock milliseconds elapsed since the start of the fit
L2 norm of the gradient (NA for gradient-free optimizers)
L2 norm of the parameter step (NA when unavailable)
NA (reserved for future inner-loop counts)
Optimizer name string, e.g. "slsqp", "bobyqa", "bfgs"
Levenberg-Marquardt damping factor (Gauss-Newton only)
OFV change from the previous accepted step (Gauss-Newton only)
1 if the GN step was accepted, 0 if rejected (NA otherwise)
Conditional negative log-likelihood (SAEM only)
SAEM step-size schedule gamma
Metropolis-Hastings acceptance rate (SAEM only)
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().
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