Fit PK model(s) for a `pk` object
# S3 method for pk
do_fit(obj, rate_names = NULL, ...)
The same [pk] object, with element `fit` containing the fitted results for each model in `stat_model`.
A `pk` object
The names of the rate units. Leave NULL to utilize default 1/hour.
Additional arguments. Not in use currently.
Please set [mirai::daemons()] if you intend to take advantage of parallel processing. If [mirai::daemons()] are set, this function will use [mirai::mirai_map()] if none are set, then sequential iteration will occur. Distinct progress bars are displayed depending on whether parallel processing is used. Please remember to run `mirai::daemons(0L)` afterwards. See `mirai` package documentation for more details.
Caroline Ring, Gilberto Padilla Mercado
This function estimates the parameters for each model in `stat_model` from the data, using numerical optimization implemented in [optimx::opm()]. The optimization is done by maximizing the log-likelihood function implemented in [log_likelihood()] (technically, by minimizing the negative log-likelihood). Only the non-excluded observations are used.
Due to limitations of [optimx::opm()], the log-likelihood function is forced to return finite values during this optimization. Impossible combinations of parameters (e.g., parameter values that produce negative predicted concentrations) should have a log-likelihood of `-Inf`, but due to this limitation, they instead have a log-likelihood of `-Machine.doublexmax`. This limitation means that the log-likelihood function is flat in regions of impossible parameter values. It is unlikely, but possible, that the optimizer might get "stuck" in such a flat region -- report convergence, but return a "bad" set of parameter values that produces non-physical predictions.
Before trusting the results of any fit, it is recommended to check the log-likelihood using [logLik()] and the Akaike Information Criterion using [AIC()], which check the log-likelihood *without* forcing it to return finite values.