Motivation
===============

Patients being treated for a given medical condition come in all shapes and sizes,
and each patient's illness will affect them differently.
Each patient should therefore receive personalized treatment that ensures
the best response for their particular circumstances.
This requires an understanding of how variation between patients influences
the effect of a given drug on a given condition.
Variation between patients can be both directly observed - properties such as age and 
weight, known as *covariates* - or observed indirectly through the patient's
response to a specific dosing regimen of the drug.

.. so...

In order to predict the effect of this variation better, compartmental models
were developed that approximate, in a simple way, what the body does to the drug 
(pharmacokinetics) and what the drug does to the body (pharmacodynamics). 
These models treat the body as a series of compartments through which the drug 
circulates until eventually eliminated either through metabolism or excretion.
The rate at which the drug moves between compartments is specified by 
a set of equations that are controlled by a set of model 
parameters.

.. but...

Because every individual in a population will process the drug differently, 
it is important that these model parameters be personalized to each individual.
This results, however, in an explosion of parameters for which there is rarely
enough data to constrain the solution.

.. so...

An approach called Nonlinear Mixed Effects Modelling (NLME) addresses this
problem by modelling individual parameters as random deviations 
from a population average, 
both of which have specific statistical distributions that indicate the
likelihood of any particular solution given observed data.

.. but...

The difficulty with these nonlinear models is that the equations defining them
are mathematically complex and must be solved numerically.

.. so...

In the late 1970s, Stuart L. Beal and Lewis B. Sheiner began developing a 
computer software package called |nonmem| - short for 
*Non*\ linear *M*\ ixed *E*\ ffects *M*\ odelling -
that was written in Fortran 
and was being used for data analysis at least as early as 1980 
[Evaluation of methods for estimating population pharmacokinetics 
parameters. I. Michaelis-Menten model: routine clinical pharmacokinetic data. 
Sheiner LB, Beal SL. J Pharmacokinet Biopharm. 1980 Dec;8(6):553-71. 
doi: 10.1007/BF01060053.].

|nonmem| was groundbreaking and quickly set the "Gold Standard" for modelling
nonlinear drug effects.
Perhaps surprisingly, over four decades later, 
|nonmem| is still the market leader 
in pharmacokinetic and pharmacodynamic (|pkpd|) analysis. 
A quick analysis of PAGE meeting abstracts 
suggests that |nonmem| still has around a 50% market share within the |pkpd|
community, and a similar analysis of PubMed abstracts indicates the same 
pattern.

.. but...

In those four decades, however, there have been many advances in programming
languages, numerical algorithms and computer hardware. Although |nonmem| has
benefited from some of these (|eg| developments in CPU power), 
its implementation in Fortran limits the advances on which it can capitalize
and from which its many users would benefit (|eg| an enhanced user interface
or improved numerical algorithms).

.. so...

As a result, a number of other packages have emerged that offer similar or
alternative approaches to dealing with nonlinear mixed effect models, often
using newer languages that can more easily be extended, suggesting 
that there is appetite for alternatives.

.. 
    (several of which we explore in :ref:`discussion`).

.. but...

Many of these alternative |pkpd| packages, however, 
only *simulate* new data 
and do not *estimate* population parameters from a given dataset and model,
which is arguably the most useful function of a |pkpd| modelling package.
Unsatisfied by most of these alternatives, therefore, we embarked upon a 
project to build a modelling package that was as powerful 
as |nonmem| only easier for developers to maintain and extend, and for 
modellers to use without the need for add-ons such as "Perl speaks 
|nonmem|" to augment its functionality (|eg| visualization and reporting).

.. comment
    Add-ons aren't necessarily a bad thing (we're likely to do something 
    similar ourselves) so it would be worth commenting on this.

.. so...

Because we wanted a system that would be easy to extend, 
we chose to implement our system in Python that has a vast ecosystem 
of libraries and an enormous user community, making it 
arguably the go-to language choice for data science at the time of writing.

The result is a software package for
*Po*\ pulation |pkpd| in *Py*\ thon - "|popy|" - with many desirable features:

* Simulation: To support simulating one or many populations from a model,
  either from scratch or from seed values, |popy| offers many closed-form models, 
  complex dosing functions and built-in sampling distributions 
  (rather than just the normal distribution). 
.. [...and also does trial design/simulation?]
* Parameter Estimation: To support fitting complex models to large datasets, |popy| offers several fitting algorithms, using symbolic differentation for more efficient and accurate parameter updates.
* Visualization: To assist in reporting, |popy| generates a range of plots, tables and reports.
* Ease-of-use: To be as easy to pick up as possible, especially for existing |nonmem| users, |popy| uses a structured input script format that makes it easy to write complex models yet *requires little to no Python experience from the user*.
* Performance: To be as powerful as possible, we compile much of the speed-critical code in Cython for high performance on a single CPU, and we provide parallel computing capabilities (via MPI) to maximize resource use on challenging problems with a large population of individuals.

Here we present |popy| and demonstrate its capability,
using comparisons to other major packages for illustration,
suggesting that |popy| shows promise as a research platform
for |pkpd| analysis.
