Writes a single, self-describing zip archive that any language with stdlib JSON + CSV + zip readers can open (R, Python, Julia, Rust). The archive includes parameter estimates, per-subject EBEs, per-observation predictions, and the verbatim .ferx model source.

ferx_save_fit(fit, output, include_data = FALSE)

Arguments

fit

A ferx_fit object returned by ferx_fit.

output

Path to write. By convention the file extension is .fitrx; the function does not enforce this.

include_data

Logical. When TRUE, the input NONMEM CSV used to fit the model is embedded verbatim inside the archive (as data.csv). Requires that the file is still accessible at the path captured at fit time (fit$data_path). Default FALSE.

Value

Invisibly returns output.

Details

The schema is shared with the ferx-core Rust crate; see its docs/src/file-formats/fitrx.md for the full field reference.

See also

ferx_load_fit, ferx_fit (and its output argument for save-during-fit).

Examples

ex  <- ferx_example("warfarin")
fit <- ferx_fit(ex$model, ex$data, method = "gn", covariance = FALSE)
#> 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.
tmp <- tempfile(fileext = ".rds")
ferx_save_fit(fit, tmp)
fit2 <- ferx_load_fit(tmp)
identical(fit$theta, fit2$theta)
#> [1] FALSE