Rikard Nordgren (1), Stella Belin (1), Xiaomei Chen (1), Johan Borg (1), Antonia Hufnagl (1), Keqi Shi (1), Andrew C. Hooker (1), Mats O. Karlsson (1)
(1) Department of Pharmacy, Uppsala University, Sweden
The development of pharmacometric models is a complex, multi-step process. Generally, it begins with an informed starting model, which is 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 parts of 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. It has functionality ranging from reading and manipulating model files and datasets, to full tools where subsequent results are collected and presented. Pharmpy has tools to automatically develop different aspects of or a full model. Currently, Pharmpy supports NONMEM [2] parsing, writing, and execution and nlmixr2/rxode2 [3] writing and execution. Pharmpy is intended for pharmacometric researchers and modelers as well as tool developers, and has different application programming interface (API) layers to cater to the different needs of the groups. Pharmpy is implemented as a Python library, but can also be used in R [4] via the pharmr [5] package or via a command line interface (CLI) or a graphical user interface (GUI) for model building [6].
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, estimation 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 estimation tool is relevant. For example, the general Pharmpy function changes the absorption model, while the NONMEM specific update machinery chooses the correct ADVAN. By separating the model manipulations from the estimation tool, a function or tool only needs to be implemented once. The model representation also allows for translations between estimation tool code, e.g. a NONMEM model can be translated to a nlmixr2 model.
Scripting of modeling workflows in Python and R
Pharmpy has many different functions to simplify the pharmacometric model building process. The use case for these functions range from using only one function for a task that is tedious to perform manually (e.g. adding a time after dose (TAD) column) to fully scripting a workflow, including fitting and presenting results. Examples of types of functions include:
• Model creation
• Model transformations
◦ Change structural, IIV/IOV structure, RUV, and covariate effects
◦ Transform values below the limit of quantification
• Data transformations
◦ Add TAD column
◦ De-identify data
• Model estimation and analysis
◦ Execute models in from Python or R
◦ Create summary tables and plots
Pharmpy can also detect whether a model has been run and skip if necessary, meaning you can fully rerun your script, for example in an R Markdown document or a Jupyter notebook, without having to comment out the estimation call.
Automatic development of models
Pharmpy has multiple tools that can automatically develop different aspects of the model, and a fully automatic model development (AMD) tool that develops a model given a dataset [7]. The AMD tool consists of multiple subtools, that can also be run standalone, that develop the structural model [8], the IIV/IOV structure, the RUV model, and covariate effects. Currently AMD and the subtools support PK, PKPD, TMDD, and drug-metabolite models. 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., Basel, Switzerland 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.
References:
[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, Hamdan A, Wang S, Yang T, Nordgren R, Belin S, Huang Z, Carter SJ, Buatois S, Abrantes JA, Hooker AC, Karlsson MO, Development of a tool for fully automatic model development (AMD), PAGE 2022
[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
Reference: PAGE 32 (2024) Abstr 11039 [www.page-meeting.org/?abstract=11039]
Poster: Software Demonstration