Rikard Nordgren1, Stella Belin1, Xiaomei Chen1, Ya-Han Hsu1, Peng Man1, Andrew C. Hooker1, Mats O. Karlsson1
1Department of Pharmacy, Uppsala University
The development of pharmacometric models is a complex, multi-step process. Generally, it begins with an informed starting model, which is then improved in a stepwise manner. Throughout the process, a modeler needs to master knowledge in multiple domains, including pharmacology and statistics. The technical component, i.e. how to implement and manipulate models, is an additional burden. Finally, having traceable and reproducible results is crucial, therefore scripting the model building rather than making manual changes can improve the quality of the process.
Pharmpy [1] is an open-source software package for pharmacometric modeling, and is intended for pharmacometric researchers and modelers as well as tool developers. The software has different application programming interface (API) layers to cater to the different needs of the groups. Key features include:
* Ability to fully script modeling workflows: script various aspects of model building (such as building a model, transforming the dataset, or estimating the model parameters) in Python, R (via the pharmr package), and from the command line [4, 5]
* Independent of modeling language: model abstraction is separate from the estimation language, meaning functions and tools can be used with multiple estimation tools and models can be translated between languages (currently NONMEM, nlmixr2, and rxode2) [2, 3]
* Tools for automatic model building: develop parts of or a full model automatically, with support for PK, PKPD, TMDD, and drug-metabolite models [7]
New features since PAGE 2024:
* New algorithms for covariate model building, including SAMBA, SCM-SLCS, and SCM-LCS [9]
* mBIC as a ranking criterion to account for multiple testing [10]
* New system for running workflows (allowing for rerunning of single estimations as well as tools)
* Improved log system for tools displayed in terminal/Rstudio
* MPI support for NONMEM execution
Model representation in Pharmpy
At the heart of Pharmpy lies its model abstraction. When a model is parsed from NONMEM, or when a new model is created from scratch in Pharmpy, it is represented as a general Pharmpy model object. The model is broken down into core components: model statements, parameters, random variables, execution steps, and the dataset, each of which can be manipulated through low level operations and through more complex functions. All functions and tools are agnostic of the original implementation of the model; it is only once the model is written down (e.g. for execution) that the specific tool to use is relevant. For example, a general Pharmpy function changes the absorption model, while the NONMEM specific update machinery chooses the correct ADVAN. By separating the model manipulations from the underlying tool, a function or tool only needs to be implemented once.
Scripting of modeling workflows
Pharmpy has many different functions to simplify the pharmacometric model building process. The use cases for these functions range from using only one function for a task that is tedious to perform manually to fully scripting a workflow, including fitting and presenting results. Examples of types of functions include:
* Model creation
* Model transformations
Change model structure, IIV/IOV structure, and add covariate effects
Transform values below the limit of quantification (BLQ)
* Data transformations
Add TAD column
De-identify data
* Model estimation and subsequent analysis
Execute models from Python or R
Create summary tables and plots
* One script workflows
Detect what was previously run and read in results
Automatic development of models
Pharmpy has multiple tools that can automatically develop different aspects of a model, and a fully automatic model development (AMD) tool that develops a model given a dataset [7]. The AMD tool integrates multiple subtools that selects the structural model [8], the IIV/IOV structure, the RUV model, and covariate effects. These subtools can also be run standalone. All the tools in AMD produce various results, including reports with model quality plots and tables. Pharmpy also has a tool to evaluate estimation methods, solvers, and parameter uncertainty methods.
Contributions to the Pharmpy-package are welcome!
Acknowledgement: This work was supported by F. Hoffmann-La Roche Ltd. and Bayer AG. A special thanks to Dr. Emilie Schindler, Dr. Sylvie Retout, Dr. Franziska Schaedeli Stark, Dr. Sreenath Krishnan, Dr. Orwa Albitar, and Dr. Valerie Cosson for conducting testing and providing feedback.
[1] Pharmpy: https://pharmpy.github.io/latest/index.html
[2] Bauer RJ. NONMEM Tutorial Part I: Description of Commands and Options, With Simple Examples of Population Analysis. CPT: Pharmacometrics & Systems Pharmacology. 2019;8(8):525–37.
[3] Fidler M, Xiong Y, Schoemaker R, Wilkins J, Trame M, Hooijmaijers R, Post T, Wang W. (2021) nlmixr: Nonlinear Mixed Effects Models in Population Pharmacokinetics and Pharmacodynamics. R package version 2.0.6. https://CRAN.R-project.org/package=nlmixr.
[4] R Core Team (2020). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. URL https://www.R-project.org/.
[5] pharmr: https://github.com/pharmpy/pharmr
[6] modelbuilder: https://github.com/pharmpy/modelbuilder
[7] Chen X, Nordgren R, Belin S, et al. A fully automatic tool for development of population pharmacokinetic models. CPT Pharmacomet Syst Pharmacol. 2024;13(10):1784-1797. doi:10.1002/psp4.13222
[8] Hamdan A, Chen X, Belin S, Nordgren R, Buatois S, Abrantes JA, Hooker AC, Karlsson MO, Automatic Development of Pharmacokinetic Structural Models – Pharmpy Model Search Tool, PAGE 2022
[9] Peng Man, Yevgen Ryeznik, Xiaomei Chen, Rikard Nordgren, Stella Belin, Chee M. Ng, Robert J. Bauer, Mats O. Karlsson, and Andrew C. Hooker, “Stepwise Covariate Modeling Acceleration Using Individual Uncertainty Adjusted Linear Covariate Screening Methods”, PAGE 2025
[10] Xiaomei Chen, Ya-Han Hsu, Rikard Nordgren, Stella Belin, Emilie Schindler, Andrew C. Hooker, and Mats O. Karlsson, “A modified Bayesian information criterion (mBIC) with multiple testing correction for population pharmacokinetic model building”, PAGE 2025
Reference: PAGE 33 (2025) Abstr 11599 [www.page-meeting.org/?abstract=11599]
Poster: Software Demonstration