ferx_simulate_with_uncertainty.RdFor each parameter set drawn from the uncertainty distribution, the
per-subject random-effect / residual-error simulator runs
n_sim_per_draw times. The result includes both individual
variability (etas, epsilons) and parameter uncertainty — useful for
uncertainty-aware VPCs, dose-recommendation intervals, and any analysis
where treating the ML estimates as fixed would understate variability.
ferx_simulate_with_uncertainty(
model,
data,
fit,
n_uncertainty_draws = 100L,
n_sim_per_draw = 1L,
method = c("asymptotic", "sir"),
seed = 42L
)Path to a .ferx model file
Path to a NONMEM-format CSV (provides population structure)
A ferx_fit result. Must carry either cov_matrix
(asymptotic) or sir_resamples (SIR) depending on method.
Number of parameter sets to draw from the uncertainty distribution
Number of eta/eps replicates per parameter draw
Either "asymptotic" (default) or "sir"
Random seed for reproducibility
A data.frame with columns: DRAW, SIM, ID, TIME, IPRED, DV_SIM.
Row count: n_uncertainty_draws * n_sim_per_draw * n_obs.
Two uncertainty sources are supported:
method = "asymptotic"Multivariate normal around the ML
estimate in the engine's packed (log-theta, Cholesky-omega, log-sigma)
parameter space, using fit$cov_matrix. Requires fit
to come from a ferx_fit() call with covariance = TRUE.
method = "sir"Sample with replacement from
fit$sir_resamples. Requires the fit to have been run with
sir = TRUE and sir_keep_samples = TRUE (passed via
settings).
if (FALSE) { # \dontrun{
ex <- ferx_example("warfarin")
fit <- ferx_fit(ex$model, ex$data, covariance = TRUE)
# Asymptotic (default): fast, MVN around the ML estimate
sims <- ferx_simulate_with_uncertainty(
ex$model, ex$data, fit,
n_uncertainty_draws = 200, n_sim_per_draw = 10
)
# SIR: requires sir = TRUE + sir_keep_samples = TRUE at fit time
fit_sir <- ferx_fit(ex$model, ex$data,
covariance = TRUE, sir = TRUE,
settings = list(sir_keep_samples = TRUE))
sims_sir <- ferx_simulate_with_uncertainty(
ex$model, ex$data, fit_sir,
n_uncertainty_draws = 200, n_sim_per_draw = 10,
method = "sir"
)
} # }