Skip to contents

Internal companion to run_nlme(); called when the input model is in pharmpy's nlmixr backend. The function turns the pharmpy nlmixr model into an rxode2/nlmixr2 function, fits it with nlmixr2::nlmixr2(), and wraps the result in a list that mimics the shape of a pharmpy ModelfitResults so downstream helpers (attach_fit_info(), compare_nlme_fit(), etc.) work without engine-specific branches.

Usage

run_nlme_nlmixr(
  model,
  data = NULL,
  id,
  path = getwd(),
  estimation_method = NULL,
  control = NULL,
  force = NULL,
  save_fit = TRUE,
  save_summary = TRUE,
  save_final = TRUE,
  clean = TRUE,
  verbose = TRUE
)

Arguments

model

pharmpy model object or NONMEM model code (character) or path to NONMEM model file.

data

filename of dataset or data.frame as input to NONMEM / nlmixr. Optional, can also be included in model object (if specified as pharmpy model object).

id

run id, e.g. run1. This will be the folder in which the NONMEM model is run. If no folder is specified, it will create a folder run1 in the current working directory, and will increment the run number for each subsequent run.

path

path to nonmem model. If not specified, will assume current working directory.

estimation_method

Optional. Character vector of estimation method(s) to apply to model. Will remove all existing estimation steps in the model and update with methods specified in argument.

control

nlmixr2-only. Optional control list passed verbatim to nlmixr2::nlmixr2() (e.g. nlmixr2est::foceiControl() or nlmixr2est::saemControl()). Ignored for NONMEM models.

force

if run folder (id) exists, should existing results be removed before rerunning NONMEM? Default FALSE.

save_fit

save fit object. If TRUE, will save as <run_id.rds>. Can also specify filename (rds) to save to.

save_summary

save fit summary and parameter estimates to file? Default is TRUE. Will use current folder, and save as fit_summary_<id>.txt and fit_parameters_<id>.csv.

save_final

after running the model, should a file final.mod be created with the final estimates from the run.

clean

clean up run folder after NONMEM execution?

verbose

verbose output?

Details

Pharmpy can in principle drive nlmixr2 itself, but that path requires the Python pyreadr module which is not part of the standard install; calling nlmixr2 directly is also faster (no R→Python→R round-trip).