Fitting Non-Identifiable and Poorly Identifiable Models using Bayesian Inference

Author

Mohamed Tarek

In this tutorial, we will see how to use Bayesian inference in Pumas to fit a non-identifiable (or a poorly identifiable) model by sampling from the full posterior. Unlike maximum likelihood estimation methods which only find point estimates for the model parameters, Bayesian methods can be used to sample from the full posterior of the model parameters making it more robust to identifiability issues.

1 Model Identifiability

One of the goals of statistical learning is to identify the underlying parameter values in a parametric model that best fit the observed data. In many practical scenarios, some parameters in a model may not be identifiable, for one of the following problems:

  1. The model is over-parameterized with redundant parameters, where a continuum of parameter values, e.g \(0 \leq \theta \leq 1\), would all give identical model predictions. This tends to happen when a dynamical model has many compartments and associated parameters but only one or a few compartments are observed. Another case where this happens is if there is a typo in the model where a parameter is not used everywhere it should.
  2. The model has symmetries such that a discrete set of parameter values, e.g. \(\theta = -1\) or \(\theta = 1\), give identical model predictions. This tends to happen with inappropriate use of the “absolute value” function (abs) if used on a function that can be either negative or positive potentially creating 2 separate modes. This problem can sometimes be fixed by using appropriate parameter bounds, e.g. \(\theta \geq 0\), in the model.
  3. The data is insufficient to learn some parameters’ values but more data would have been sufficient.

The first 2 problems are problems in the model describing structural non-identifiability and the third problem is a problem in the data or data-model mismatch describing practical non-identifiability (sometimes called non-estimability).

Type of Identifiability Description
Globally Structurally Identifiable Every set of parameter values \(\theta\) makes a unique model prediction \(\mu(\theta)\).
Globally Practically Identifiable Globally structurally identifiable and there is enough data to estimate the data-generating parameter values.
Locally Structurally Identifiable Only dis-connected parameters values \(\{\theta_1, \theta_2, \dots, \theta_m\}\) can result in the same model prediction \(\mu\), i.e. \(\mu(\theta_1) = \mu(\theta_2) = \dots = \mu(\theta_m)\). However, in the neighborhood \(N(\theta)\) of each set of parameters \(\theta\), each \(\theta' \in N(\theta)\) results in a unique model prediction \(\mu(\theta')\).
Locally Practically Identifiable Locally structurally identifiable and there is enough data to estimate the (potentially non-unique but dis-connected) data-generating parameter values.
Key Points
  • Local (or global) practical identifiablity is what we usually want in analyses.
  • Practical identifiability (estimability) implies structural identifiability.
Poor Identifiability

When a model may be identifiable in exact arithmetic but its identifiability is sensitive to numerical errors in computations, we will call it poorly identifiable. When the term “poorly identifiable models” is used in the rest of this tutorial, this also includes truly non-identifiable models.

2 Example

Let’s consider an example of fitting a poorly identifiable model.

2.1 Loading Pumas

First, let’s load Pumas:

using Pumas

2.2 Two Compartment Model

Now let’s define a single-subject, 2-compartment model with a depot, central and peripheral compartments and a proportional error model.

model = @model begin
    @param begin
        θ  VectorDomain(lower = zeros(5))
        σ  RealDomain(lower = 0.0)
    end
    @pre begin
        CL = θ[1]
        Vc = θ[2]
        Ka = θ[3]
        Vp = θ[4]
        Q = θ[5]
    end
    @dynamics begin
        Depot' = -Ka * Depot
        Central' = Ka * Depot - (CL + Q) / Vc * Central + Q / Vp * Peripheral
        Peripheral' = Q / Vc * Central - Q / Vp * Peripheral
    end
    @derived begin
        cp := @. Central / Vc
        dv ~ @. CombinedNormal(cp, 1e-6, σ)
    end
end
PumasModel
  Parameters: θ, σ
  Random effects:
  Covariates:
  Dynamical system variables: Depot, Central, Peripheral
  Dynamical system type: Matrix exponential
  Derived: dv
  Observed: dv
Subject Model vs Population Model

Note that studying the identifiability of subject models is still relevant when fitting a population version of the model with typical values and random effects. The reason is that when evaluating the log likelihood using the Laplace method or first-order conditional estimation (FOCE), one of the steps involved is finding the empirical Bayes estimates (EBE) which is essentially fitting a subject’s version of the model, fixing population parameters and estimating random effects. Non-identifiability in the EBE estimation can often cause the EBE estimation to fail or to be so numerically unstable that the population parameters’ fit itself fails because the marginal likelihood (and its gradient) computed with Laplace/FOCE relied on incorrect or numerically unstable EBEs.

2.3 Parameter Values

Let’s define some parameter values to use for simulation.

params == [35, 100, 0.5, 210, 30], σ = 0.1)
(θ = [35.0, 100.0, 0.5, 210.0, 30.0], σ = 0.1)

2.4 Subject Definition

Next we define a subject skeleton with a single bolus dose and no observations.

skeleton = Subject(
    id = 1,
    time = 0.0:0.5:30.0,
    events = DosageRegimen(3000, time = 0.0, cmt = 1),
    observations = (; dv = fill(missing, 61)),
)
Subject
  ID: 1
  Events: 1
  Observations: dv: (n=61)

2.5 Fisher Information Matrix

The expected Fisher Information Matrix (FIM) is an important diagnostic which can be used to detect local practical identifiability (LPI) given the model and the experiment design [1]. The first order approximation of the expected FIM [2,3] has also been used successfully to analyze the LPI of pharmacometric nonlinear mixed effect (NLME) models [4,5,6].

The positive definiteness (non-singularity) of the expected FIM \(F(\theta)\) at parameters \(\theta\) is a sufficient condition for LPI at \(\theta\). Under more strict assumptions which are more difficult to verify, the positive definiteness of \(F(\theta)\) is even a necessary condition for LPI [1].

To compute a first-order approximation of the expected FIM, we will use the OptimalDesign package:

using OptimalDesign

times = OptimalDesign.ObsTimes(skeleton.time)
F = OptimalDesign.fim(model, [skeleton], params, [times])
6×6 Symmetric{Float64, Matrix{Float64}}:
  1.2949     -0.0538767     13.6935     0.0254882   -0.218697      -2.68028
 -0.0538767   0.0188821     -4.38016   -0.00168545   0.0296865     -0.325336
 13.6935     -4.38016     1054.71       0.635264    -7.13312       66.7482
  0.0254882  -0.00168545     0.635264   0.00215197  -0.00487914    -0.0895271
 -0.218697    0.0296865     -7.13312   -0.00487914   0.144605      -0.720992
 -2.68028    -0.325336      66.7482    -0.0895271   -0.720992    1667.74

2.6 Procedure for Detecting Practical Non-Identifiability

Next, let’s do an eigenvalue decomposition of F to find the smallest eigenvalue. The smallest eigenvalue is always the first one because they are sorted.

E = eigen(F)
E.values[1]
9.646901451998056e-5

It is close to 0! This implies that the matrix is very close to being singular. While this is not strictly a proof of local non-identifiability, it is one step towards detecting non-identifiability.

Tip

The non-singularity of the expected FIM is generally only a sufficient (not necessary) condition for local identifiability. So there are some locally identifiable models that have a singular or undefined expected FIM. However, there is a subclass of models satisfying strict assumptions for which the non-singularity of the expected FIM is a necessary condition for local identifiability [1]. In practice, these assumptions are difficult to verify for a general model but if our model happens to satisfy these assumptions, then a singular expected FIM would imply local non-identifiability. In that case, the eigenvector(s) corresponding to the 0 eigenvalue would be useful diagnostics as they point in the directions along which changes in the parameters will have no effect on the log likelihood.

To summarize:

  • Being “Non-Singular” Isn’t Always a Must: A non-singular expected FIM always signals that a model is “locally identifiable” (meaning you can find a locally unique solution for its parameters). However, some locally identifiable models can still have singular or undefined expected FIM.
  • Sometimes, It’s Absolutely Necessary: There’s a special group of models where a non-singular expected FIM is required to be locally identifiable. It’s hard to know if your model falls into this group.
  • Practical Use: Even if your expected FIM is singular, it may be a helpful diagnostic. The eigenvectors of the FIM with 0 eigenvalues show you directions where changing the model’s parameters may not affect the model’s predictions – this may help you pinpoint where the model is fuzzy.

To prove if a model is practically non-identifiable, it suffices to find a single set \(\Theta\) such that for all parameters \(\theta \in \Theta\), the log likelihood is unchanged. To find \(\Theta\) numerically, one can

  1. Assume parameter values \(\theta_0\),
  2. Define a criteria for changing the parameters \(\theta\) from their current values \(\theta_0\), and then create a candidate set of parameters \(\Theta_c\),
  3. Simulate synthetic data using the parameters \(\theta_0\),
  4. Evaluate the log likelihood \(L(\theta)\) for all \(\theta \in \Theta_c\),
  5. Evaluate the sensitivity of the log likelihood to local changes within \(\Theta_c\).

One way to construct a candidate \(\Theta_c\) is as the set \(\{\theta_0 + \alpha \cdot d : \alpha \in [-\epsilon, \epsilon] \}\) for a small \(\epsilon > 0\), where \(d\) is an eigenvector corresponding to the smallest eigenvalue of the expected FIM, \(F\). The sensitivity of the log likelihood to changes within \(\Theta_c\) can then be quantified as the average value of:

\[ \Bigg( \frac{L(\theta_0 + \alpha \cdot d) - L(\theta_0)}{\alpha} \Bigg)^2 \]

for all \(\alpha \in [-\epsilon, \epsilon]\), \(\alpha \neq 0\). Let’s follow this procedure for the above model assuming \(\theta_0\) is params.

2.7 Simulating Data

Here we simulate a synthetic subject using the skeleton subject we have. We fix the seed of the pseudo-random number generator for reproducibility.

using Random

Random.seed!(12345)
pop = [Subject(simobs(model, skeleton, params))]
Population
  Subjects: 1
  Observations: dv

To evaluate the log likelihood of params given pop, we can use the loglikelihood function:

ll0 = loglikelihood(model, pop, params, NaivePooled())
32.82509838337168

Since there are no random effects in this model, we use the NaivePooled() algorithm in Pumas.

2.8 Local Sensitivity Analysis of Log Likelihood

The eigenvectors corresponding to the smallest eigenvalue of F give us the directions that are likely to have the largest standard error in the maximum likelihood estimates. These are the most promising directions to test when constructing candidate sets \(\Theta_c\) for identifiability analysis. To get the eigenvector corresponding to the smallest eigenvalue, you can run:

d = E.vectors[:, 1]
6-element Vector{Float64}:
  0.006716973993299584
  0.83827361662032
  0.003756059324605163
 -0.5451731110412071
  0.004939326352942361
 -3.137362825983634e-6

The order of parameters is the same as the order of definition in the model: θ and then σ.

Note that the potential non-identifiability seems to be mostly in the second and fourth parameter, Vc and Vp. More precisely, the above eigenvector implies that simultaneously increasing Vc and decreasing Vp (or vice versa) by the ratios given in d may have little to no effect on the log likelihood.

Let’s try to add α * d[1:end-1] to params.θ (i.e. move params.θ in the direction d[1:end-1]) and evaluate the log likelihood for different step sizes α. To do that, we will first define a function that moves params.θ and call it on different step values α. These choices of α values correspond to a discrete candidate set \(\Theta_c\).

function moveθ(α)
    # unpacking the fields of params to variables with the same names
    (; θ, σ) = params
    # move θ by step * d[1:end-1]
    return (; θ = θ + α * d[1:end-1], σ)
end
# move by both negative and positive steps (excluding α = 0)
αs = vcat(-1e-3 .* (1:10), 1e-3 .* (1:10))
20-element Vector{Float64}:
 -0.001
 -0.002
 -0.003
 -0.004
 -0.005
 -0.006
 -0.007
 -0.008
 -0.009
 -0.01
  0.001
  0.002
  0.003
  0.004
  0.005
  0.006
  0.007
  0.008
  0.009
  0.01
newparams = moveθ.(αs)
20-element Vector{@NamedTuple{θ::Vector{Float64}, σ::Float64}}:
 (θ = [34.99999328302601, 99.99916172638338, 0.4999962439406754, 210.00054517311105, 29.999995060673648], σ = 0.1)
 (θ = [34.999986566052016, 99.99832345276675, 0.4999924878813508, 210.00109034622207, 29.999990121347295], σ = 0.1)
 (θ = [34.999979849078024, 99.99748517915013, 0.4999887318220262, 210.00163551933312, 29.999985182020943], σ = 0.1)
 (θ = [34.999973132104024, 99.99664690553352, 0.49998497576270157, 210.00218069244417, 29.999980242694587], σ = 0.1)
 (θ = [34.99996641513003, 99.9958086319169, 0.499981219703377, 210.0027258655552, 29.999975303368235], σ = 0.1)
 (θ = [34.99995969815604, 99.99497035830028, 0.4999774636440524, 210.00327103866624, 29.999970364041882], σ = 0.1)
 (θ = [34.99995298118205, 99.99413208468366, 0.49997370758472776, 210.0038162117773, 29.99996542471553], σ = 0.1)
 (θ = [34.999946264208056, 99.99329381106703, 0.49996995152540313, 210.00436138488834, 29.999960485389177], σ = 0.1)
 (θ = [34.999939547234064, 99.99245553745041, 0.49996619546607857, 210.00490655799936, 29.999955546062825], σ = 0.1)
 (θ = [34.999932830260065, 99.9916172638338, 0.49996243940675394, 210.0054517311104, 29.99995060673647], σ = 0.1)
 (θ = [35.00000671697399, 100.00083827361662, 0.5000037560593246, 209.99945482688895, 30.000004939326352], σ = 0.1)
 (θ = [35.000013433947984, 100.00167654723325, 0.5000075121186492, 209.99890965377793, 30.000009878652705], σ = 0.1)
 (θ = [35.000020150921976, 100.00251482084987, 0.5000112681779738, 209.99836448066688, 30.000014817979057], σ = 0.1)
 (θ = [35.000026867895976, 100.00335309446648, 0.5000150242372984, 209.99781930755583, 30.000019757305413], σ = 0.1)
 (θ = [35.00003358486997, 100.0041913680831, 0.500018780296623, 209.9972741344448, 30.000024696631765], σ = 0.1)
 (θ = [35.00004030184396, 100.00502964169972, 0.5000225363559476, 209.99672896133376, 30.000029635958118], σ = 0.1)
 (θ = [35.00004701881795, 100.00586791531634, 0.5000262924152722, 209.9961837882227, 30.00003457528447], σ = 0.1)
 (θ = [35.000053735791944, 100.00670618893297, 0.5000300484745969, 209.99563861511166, 30.000039514610823], σ = 0.1)
 (θ = [35.000060452765936, 100.00754446254959, 0.5000338045339214, 209.99509344200064, 30.000044453937175], σ = 0.1)
 (θ = [35.000067169739935, 100.0083827361662, 0.500037560593246, 209.9945482688896, 30.00004939326353], σ = 0.1)

Now let’s evaluate the log likelihoods of all these parameter sets.

lls = map(newparams) do p
    loglikelihood(model, pop, p, NaivePooled())
end
20-element Vector{Float64}:
 32.825119311648166
 32.82514024037694
 32.825161169095495
 32.82518209882179
 32.82520302921025
 32.82522395943841
 32.82524488996207
 32.825265821411534
 32.82528675346804
 32.82530768588313
 32.82507745580337
 32.82505652827541
 32.82503560233059
 32.82501467557626
 32.824993750087216
 32.82497282459404
 32.82495189997024
 32.82493097587828
 32.82491005203674
 32.824889127763036

To compute the average sensitivity within \(\Theta_c\), we then call:

sens = abs2.((lls .- ll0) ./ αs)
mean(sens)
0.0004379767047476752

Not very sensitive! Therefore, we can conclude that the log likelihood is almost the same inside \(\Theta_c\). This is a strong sign of non-identifiability, or at least poor identifiability.

Let’s contrast this with a random direction d2:

d2 = normalize(rand(6))
function moveθ2(α)
    # unpacking the fields of params to variables with the same names
    (; θ, σ) = params
    # move θ by step * d2[1:end-1]
    return (; θ = θ + α * d2[1:end-1], σ)
end
newparams2 = moveθ2.(αs)
lls2 = map(newparams2) do p
    loglikelihood(model, pop, p, NaivePooled())
end
sens2 = abs2.((lls2 .- ll0) ./ αs)
mean(sens2)
648.2254070926463

Notice the difference in sensitivity compared to a random direction.

Note

In practice, it can be difficult to be definitive about practical non-identifiability with numerical tests due to the nature of computation in floating point numbers where numerical errors can accumulate and either:

  1. Mask a truly singular matrix by reporting its smallest eigenvalue as very close to 0 but not exactly 0 in floating point numbers, or
  2. Make a truly non-singular matrix appear singular because its smallest eigenvalue was close to 0 in exact arithmetic but was computed as exactly 0 in floating point arithmetic.

A small enough average local sensitivity can therefore be taken as numerically equivalent to 0, i.e. local practical non-identifiability. To be more general, we will sometimes use the term poor identifiability to refer to the case when the model is approximately non-identifiable.

3 Fitting a Poorly Identifiable Model

3.1 Maximum Likelihood Estimation

When using maximum likelihood (ML) estimation to fit a poorly identifiable model, the parameter values you get can be dependent on arbitrary factors such as:

  • The initial parameter estimates. Optimization algorithms will typically converge to values close to the initial value which is arbitrary.
  • Level of noise in the data. Different levels of noise in the data can cause the optimization algorithm to take different trajectories reaching different optimal parameter values at the end.
  • The implementation details of the optimization algorithm. For example, some optimization algorithms implicitly favor parameter values with the smallest norm.

Most of these factors have no statistical significance and can be considered arbitrary in any analysis. Therefore, any insights drawn from poorly identifiable parameter values fitted with ML estimation may be flawed. Luckily, the standard error estimation, if done right, will often reveal signs of poor identifiability. However, common techniques for estimating standard errors can often break down when the model is poorly identifiable. For instance,

  1. Asymptotic estimates of standard errors require the model to be locally identifiable,
  2. Bootstrap relies on the same arbitrary optimization algorithm for fitting the data resamples so its estimates are as unreliable as the ML estimates. For instance, since all the re-fits in bootstrapping are typically initialized from the ML estimates, there is a high probability that the optimization algorithm will only converge to nearby values, significantly under-estimating the variance in the ML estimates.
  3. Sampling importance resampling (SIR) may be able to handle non-identifiable models but it requires a good proposal and its results are sensitive to the proposal used.

Example: Sensitivity to Initial Estimates

Let’s fit the model to the same subject but with 2 different sets of initial estimates:

params1 == [35, 100, 0.5, 210, 30], σ = 0.1)
fpm1 = fit(model, pop, params1, NaivePooled())
[ Info: Checking the initial parameter values.
[ Info: The initial negative log likelihood and its gradient are finite. Check passed.
Iter     Function value   Gradient norm 
     0    -3.282510e+01     5.896826e+01
 * time: 0.03471708297729492
     1    -3.299588e+01     8.371810e+01
 * time: 1.7206699848175049
     2    -3.440914e+01     3.937519e+01
 * time: 1.72200608253479
     3    -3.550332e+01     3.429526e+01
 * time: 1.7232592105865479
     4    -3.585849e+01     2.078271e+01
 * time: 1.724370002746582
     5    -3.605850e+01     4.208337e+00
 * time: 1.7255070209503174
     6    -3.606916e+01     5.500441e+00
 * time: 1.7264971733093262
     7    -3.607868e+01     5.143784e-01
 * time: 1.727466106414795
     8    -3.607872e+01     1.670003e-01
 * time: 1.7284331321716309
     9    -3.607872e+01     6.579100e-03
 * time: 1.729382038116455
    10    -3.607872e+01     3.924734e-03
 * time: 1.7303731441497803
    11    -3.607872e+01     5.349622e-02
 * time: 1.7313342094421387
    12    -3.607872e+01     2.860912e-02
 * time: 1.7323081493377686
    13    -3.607872e+01     3.132441e-03
 * time: 1.733295202255249
    14    -3.607872e+01     1.172498e-04
 * time: 1.7342891693115234
FittedPumasModel

Dynamical system type:          Matrix exponential

Number of subjects:                              1

Observation records:         Active        Missing
    dv:                          61              0
    Total:                       61              0

Number of parameters:      Constant      Optimized
                                  0              6

Likelihood approximation:              NaivePooled
Likelihood optimizer:                         BFGS

Termination Reason:                   GradientNorm
Log-likelihood value:                    36.078723

----------------
     Estimate
----------------
θ₁    34.397
θ₂   103.17
θ₃     0.46566
θ₄   204.44
θ₅    26.234
σ      0.092273
----------------
params2 == [10.0, 300, 1.0, 10.0, 5], σ = 0.2)
fpm2 = fit(model, pop, params2, NaivePooled())
[ Info: Checking the initial parameter values.
[ Info: The initial negative log likelihood and its gradient are finite. Check passed.
Iter     Function value   Gradient norm 
     0     4.245141e+02     6.802189e+02
 * time: 1.2874603271484375e-5
     1     1.499851e+02     4.520553e+01
 * time: 0.0010619163513183594
     2     1.436202e+02     4.485778e+01
 * time: 0.0020859241485595703
     3     1.108788e+02     4.698772e+01
 * time: 0.0030999183654785156
     4     9.146761e+01     4.889582e+01
 * time: 0.004083871841430664
     5     8.587686e+01     4.879770e+01
 * time: 0.005294084548950195
     6     8.353867e+01     5.068823e+01
 * time: 0.0064830780029296875
     7     8.061254e+01     4.923006e+01
 * time: 0.007710933685302734
     8     7.723505e+01     3.939533e+01
 * time: 0.008917093276977539
     9     7.347452e+01     6.732764e+01
 * time: 0.009922981262207031
    10     6.467186e+01     2.181862e+01
 * time: 0.010937929153442383
    11     5.389651e+01     4.261890e+01
 * time: 0.012185096740722656
    12     4.899496e+01     4.747087e+01
 * time: 0.0133209228515625
    13     4.635923e+01     4.385385e+01
 * time: 0.014373064041137695
    14     4.310628e+01     3.665783e+01
 * time: 0.015326976776123047
    15     3.451139e+01     4.222524e+01
 * time: 0.016499042510986328
    16     2.783156e+01     4.184498e+01
 * time: 0.017735958099365234
    17     2.167222e+01     2.490925e+01
 * time: 0.01892399787902832
    18     2.101609e+01     3.068432e+01
 * time: 0.01992487907409668
    19     2.012645e+01     9.150249e+00
 * time: 0.02096104621887207
    20     1.996284e+01     1.013947e+01
 * time: 0.021997928619384766
    21     1.919860e+01     1.426535e+01
 * time: 0.023006916046142578
    22     1.834470e+01     1.663386e+01
 * time: 0.024034976959228516
    23     1.770899e+01     8.638293e+00
 * time: 0.02502894401550293
    24     1.736337e+01     4.685621e+00
 * time: 0.026047945022583008
    25     1.698776e+01     5.459416e+00
 * time: 0.02709197998046875
    26     1.419162e+01     3.888220e+01
 * time: 0.0281829833984375
    27     1.413849e+01     1.322649e+01
 * time: 0.029294967651367188
    28     1.396486e+01     1.976848e+01
 * time: 0.030418872833251953
    29     1.381925e+01     5.251882e+00
 * time: 0.03151297569274902
    30     1.374284e+01     5.054361e+00
 * time: 0.03263497352600098
    31     1.287063e+01     1.257893e+01
 * time: 0.033715009689331055
    32     1.095164e+01     3.766952e+01
 * time: 0.034861087799072266
    33     9.527141e+00     5.917221e+01
 * time: 0.036103010177612305
    34     7.935017e+00     7.374433e+01
 * time: 0.03739309310913086
    35     5.133756e+00     8.073114e+01
 * time: 0.03879499435424805
    36     3.574430e+00     2.399332e+02
 * time: 0.039977073669433594
    37    -2.818015e+00     4.056217e+01
 * time: 0.04131507873535156
    38    -6.716130e+00     2.245883e+01
 * time: 0.04270195960998535
    39    -9.917655e+00     3.322705e+01
 * time: 0.0438690185546875
    40    -1.031668e+01     7.966725e+00
 * time: 0.04503488540649414
    41    -1.066621e+01     1.738575e+01
 * time: 0.0462188720703125
    42    -1.070012e+01     9.326113e+00
 * time: 0.04733395576477051
    43    -1.072844e+01     5.932161e+00
 * time: 0.04851102828979492
    44    -1.077821e+01     2.800923e+00
 * time: 0.04982590675354004
    45    -1.087937e+01     2.012460e+01
 * time: 0.05106997489929199
    46    -1.095502e+01     1.487566e+01
 * time: 0.05224895477294922
    47    -1.101592e+01     3.674092e+00
 * time: 0.053446054458618164
    48    -1.101981e+01     6.674368e-01
 * time: 0.054913997650146484
    49    -1.102041e+01     3.236929e-01
 * time: 0.05600309371948242
    50    -1.102050e+01     8.886111e-03
 * time: 0.057192087173461914
    51    -1.102050e+01     1.270485e-03
 * time: 0.05837297439575195
    52    -1.102050e+01     7.846672e-05
 * time: 0.059530019760131836
FittedPumasModel

Dynamical system type:          Matrix exponential

Number of subjects:                              1

Observation records:         Active        Missing
    dv:                          61              0
    Total:                       61              0

Number of parameters:      Constant      Optimized
                                  0              6

Likelihood approximation:              NaivePooled
Likelihood optimizer:                         BFGS

Termination Reason:                   GradientNorm
Log-likelihood value:                    11.020497

---------------
     Estimate
---------------
θ₁    30.967
θ₂   214.3
θ₃    52.714
θ₄   169.46
θ₅    12.074
σ      0.13904
---------------

Now let’s display the estimates of θ side by side:

hcat(coef(fpm1).θ, coef(fpm2).θ)
5×2 Matrix{Float64}:
  34.3968    30.9673
 103.168    214.304
   0.46566   52.7137
 204.442    169.462
  26.2337    12.0741

Notice the significant difference in the final estimates when changing nothing but the initial estimates. Also note that the 2 sets of coefficients are not in the same neighbourhood and don’t have similar log likelihoods. This is indicative of the existence of multiple dis-connected local optima.

Example: Sensitivity to Noise Level

To demonstrate the sensitivity to noise level, we will re-simulate the synthetic subject with the same seed but using a higher σ.

Random.seed!(12345)
newparams = (; θ = params.θ, σ = 0.2)
newpop = [Subject(simobs(model, skeleton, newparams))]
Population
  Subjects: 1
  Observations: dv

Now let’s do the fit once with pop and once with newpop:

fpm1 = fit(model, pop, params, NaivePooled())
[ Info: Checking the initial parameter values.
[ Info: The initial negative log likelihood and its gradient are finite. Check passed.
Iter     Function value   Gradient norm 
     0    -3.282510e+01     5.896826e+01
 * time: 1.5020370483398438e-5
     1    -3.299588e+01     8.371810e+01
 * time: 0.0013179779052734375
     2    -3.440914e+01     3.937519e+01
 * time: 0.0024771690368652344
     3    -3.550332e+01     3.429526e+01
 * time: 0.00357818603515625
     4    -3.585849e+01     2.078271e+01
 * time: 0.004683971405029297
     5    -3.605850e+01     4.208337e+00
 * time: 0.005812168121337891
     6    -3.606916e+01     5.500441e+00
 * time: 0.006780147552490234
     7    -3.607868e+01     5.143784e-01
 * time: 0.007739067077636719
     8    -3.607872e+01     1.670003e-01
 * time: 0.008713006973266602
     9    -3.607872e+01     6.579100e-03
 * time: 0.00967717170715332
    10    -3.607872e+01     3.924734e-03
 * time: 0.010684967041015625
    11    -3.607872e+01     5.349622e-02
 * time: 0.011640071868896484
    12    -3.607872e+01     2.860912e-02
 * time: 0.012608051300048828
    13    -3.607872e+01     3.132441e-03
 * time: 0.01356816291809082
    14    -3.607872e+01     1.172498e-04
 * time: 0.014532089233398438
FittedPumasModel

Dynamical system type:          Matrix exponential

Number of subjects:                              1

Observation records:         Active        Missing
    dv:                          61              0
    Total:                       61              0

Number of parameters:      Constant      Optimized
                                  0              6

Likelihood approximation:              NaivePooled
Likelihood optimizer:                         BFGS

Termination Reason:                   GradientNorm
Log-likelihood value:                    36.078723

----------------
     Estimate
----------------
θ₁    34.397
θ₂   103.17
θ₃     0.46566
θ₄   204.44
θ₅    26.234
σ      0.092273
----------------
fpm2 = fit(model, newpop, newparams, NaivePooled())
[ Info: Checking the initial parameter values.
[ Info: The initial negative log likelihood and its gradient are finite. Check passed.
Iter     Function value   Gradient norm 
     0     8.763732e+00     2.735810e+01
 * time: 9.059906005859375e-6
     1     8.405084e+00     2.531373e+01
 * time: 0.0012950897216796875
     2     6.620140e+00     1.286067e+01
 * time: 0.0024640560150146484
     3     5.297204e+00     8.779621e+00
 * time: 0.0036101341247558594
     4     4.963671e+00     3.840425e+00
 * time: 0.0047321319580078125
     5     4.930049e+00     1.184693e+01
 * time: 0.005746126174926758
     6     4.873733e+00     3.753111e+00
 * time: 0.006719112396240234
     7     4.858063e+00     2.308745e+00
 * time: 0.00782012939453125
     8     4.854703e+00     8.434993e-02
 * time: 0.008801937103271484
     9     4.854469e+00     7.173890e-02
 * time: 0.009768962860107422
    10     4.852883e+00     8.196445e-01
 * time: 0.010735034942626953
    11     4.851752e+00     1.270016e+00
 * time: 0.011716127395629883
    12     4.850465e+00     1.179807e+00
 * time: 0.012675046920776367
    13     4.849664e+00     1.617992e-01
 * time: 0.013642072677612305
    14     4.849480e+00     8.746251e-01
 * time: 0.01459193229675293
    15     4.849289e+00     1.703837e-01
 * time: 0.015577077865600586
    16     4.849187e+00     1.387087e-01
 * time: 0.016541004180908203
    17     4.849156e+00     1.190609e-01
 * time: 0.017512083053588867
    18     4.849150e+00     8.635074e-03
 * time: 0.01852893829345703
    19     4.849150e+00     2.415756e-02
 * time: 0.019531965255737305
    20     4.849149e+00     1.477038e-03
 * time: 0.020498991012573242
    21     4.849149e+00     1.662404e-04
 * time: 0.021496057510375977
FittedPumasModel

Dynamical system type:          Matrix exponential

Number of subjects:                              1

Observation records:         Active        Missing
    dv:                          61              0
    Total:                       61              0

Number of parameters:      Constant      Optimized
                                  0              6

Likelihood approximation:              NaivePooled
Likelihood optimizer:                         BFGS

Termination Reason:                   GradientNorm
Log-likelihood value:                   -4.8491495

---------------
     Estimate
---------------
θ₁    33.85
θ₂   125.52
θ₃     0.50012
θ₄   192.8
θ₅    22.25
σ      0.18103
---------------

Now let’s display the estimates of θ side by side:

hcat(coef(fpm1).θ, coef(fpm2).θ)
5×2 Matrix{Float64}:
  34.3968    33.8499
 103.168    125.517
   0.46566    0.500121
 204.442    192.8
  26.2337    22.2497

Given that we have many observations per subject, this level of fluctuation due to a higher noise is a symptom of non-identifiability. Also note the big difference compared to the true data-generating parameter values!

params.θ
5-element Vector{Float64}:
  35.0
 100.0
   0.5
 210.0
  30.0
Summary

In this section, we have demonstrated beyond reasonable doubt that ML estimation workflows can be unreliable when fitting poorly identifiable models, potentially leading to erroneous conclusions in a study. So if we cannot rely on ML estimation for fitting poorly identifiable models, what can we use? The answer is Bayesian inference.

3.2 Bayesian Inference

Using Bayesian methods to sample from the posterior of the parameter estimates is a mathematically sound way to fit non-identifiable models because even non-identifiable models have a well-defined posterior distribution, when their parameters are assigned prior distributions. If multiple parameter values all fit the data well, then all such values will be plausible samples from the posterior distribution, assuming reasonable priors were used.

3.2.1 Model Definition

Let’s see how to minimally change our model above to make it Bayesian using a weakly informative priors “roughly in the ballpark”:

bayes_model = @model begin
    @param begin
        θ ~ MvLogNormal([log(50), log(150), log(1.0), log(100.0), log(10.0)], I(5))
        σ ~ Uniform(0.0, 1.0)
    end
    @pre begin
        CL = θ[1]
        Vc = θ[2]
        Ka = θ[3]
        Vp = θ[4]
        Q = θ[5]
    end
    @dynamics begin
        Depot' = -Ka * Depot
        Central' = Ka * Depot - (CL + Q) / Vc * Central + Q / Vp * Peripheral
        Peripheral' = Q / Vc * Central - Q / Vp * Peripheral
    end
    @derived begin
        cp := @. Central / Vc
        dv ~ @. CombinedNormal(cp, 1e-6, σ)
    end
end
PumasModel
  Parameters: θ, σ
  Random effects:
  Covariates:
  Dynamical system variables: Depot, Central, Peripheral
  Dynamical system type: Matrix exponential
  Derived: dv
  Observed: dv

3.2.2 Sampling from the Posterior

Now to fit it, we need to pass an instance of BayesMCMC as the algorithm in fit. In this case, we used 4 chains for sampling with 3000 samples per chain out of which the first 1500 samples will be used to adapt the mass matrix and step size of the No-U-Turn sampler (NUTS) used in Pumas. All the chains are also parallelized using multi-threading.

# Setting the pseudo-random number generator's seed for reproducibility
Random.seed!(54321)
bayes_alg = BayesMCMC(; nsamples = 3_000, nadapts = 1_500)
bayes_fpm = fit(bayes_model, pop, params, bayes_alg)
[ Info: Checking the initial parameter values.
[ Info: The initial log probability and its gradient are finite. Check passed.
[ Info: Checking the initial parameter values.
[ Info: Checking the initial parameter values.
[ Info: The initial log probability and its gradient are finite. Check passed.
[ Info: Checking the initial parameter values.
[ Info: The initial log probability and its gradient are finite. Check passed.
[ Info: The initial log probability and its gradient are finite. Check passed.
Chains MCMC chain (3000×6×4 Array{Float64, 3}):

Iterations        = 1:1:3000
Number of chains  = 4
Samples per chain = 3000
Wall duration     = 132.97 seconds
Compute duration  = 500.19 seconds
parameters        = θ₁, θ₂, θ₃, θ₄, θ₅, σ

Use `describe(chains)` for summary statistics and quantiles.

Now let’s discard the NUTS warmup samples as burn-in:

bayes_fpm_samples = discard(bayes_fpm; burnin = 1500)
Chains MCMC chain (1500×6×4 Array{Float64, 3}):

Iterations        = 1:1:1500
Number of chains  = 4
Samples per chain = 1500
Wall duration     = 132.97 seconds
Compute duration  = 500.19 seconds
parameters        = θ₁, θ₂, θ₃, θ₄, θ₅, σ

Use `describe(chains)` for summary statistics and quantiles.
describe(bayes_fpm_samples)
Chains MCMC chain (1500×6×4 Array{Float64, 3}):

Iterations        = 1:1:1500
Number of chains  = 4
Samples per chain = 1500
Wall duration     = 132.97 seconds
Compute duration  = 500.19 seconds
parameters        = θ₁, θ₂, θ₃, θ₄, θ₅, σ

Summary Statistics
  parameters       mean       std      mcse    ess_bulk    ess_tail      rhat  ⋯
      Symbol    Float64   Float64   Float64     Float64     Float64   Float64  ⋯

          θ₁    34.2785    0.6365    0.0120   2821.1049   3227.7544    1.0014  ⋯
          θ₂   139.2919   35.1936    0.9858   1313.6815   2469.3308    1.0034  ⋯
          θ₃     0.6526    0.1854    0.0051   1307.2565   2318.8084    1.0037  ⋯
          θ₄   190.0433   19.0509    0.4736   1694.1802   2442.3016    1.0026  ⋯
          θ₅    23.2387    2.9452    0.0760   1533.3950   2222.5031    1.0034  ⋯
           σ     0.0981    0.0096    0.0002   2462.6168   3291.5674    1.0019  ⋯
                                                                1 column omitted

Quantiles
  parameters       2.5%      25.0%      50.0%      75.0%      97.5%
      Symbol    Float64    Float64    Float64    Float64    Float64

          θ₁    33.0141    33.8678    34.2764    34.6970    35.5219
          θ₂    69.8680   113.3728   143.1553   166.0829   199.3460
          θ₃     0.3442     0.5097     0.6479     0.7826     1.0348
          θ₄   158.4276   176.7684   187.7474   201.3510   232.0417
          θ₅    17.4839    21.1475    23.3923    25.3957    28.5251
           σ     0.0813     0.0915     0.0973     0.1042     0.1187

Notice how Bayesian inference was able to quantify the uncertainty in the non-identifiable parameters (mostly θ₂ which is Vc and θ₄ which is Vp) reflected in the large standard deviation of the marginal posterior of some parameters, std, relative to its mean value, mean. This is consistent with the eigenvector d we used earlier to prove that the model is poorly identifiable which also showed the poor identifiability was mostly prevalent in these 2 parameters.

d
6-element Vector{Float64}:
  0.006716973993299584
  0.83827361662032
  0.003756059324605163
 -0.5451731110412071
  0.004939326352942361
 -3.137362825983634e-6

3.2.3 Convergence Diagnostics

By default, we print summary statistics and a few convergence diagnostics: effective samples size (ess_bulk) and \(\hat{R}\) (rhat). In this case, the diagnostics look reasonable. The rhat is close to 1 and the minimum ess_bulk is around 1000.

Next we show the trace plot of all the parameters

using PumasPlots

trace_plot(bayes_fpm_samples)

It can be seen that the chains are mostly well mixed. Occasional jumps seem to happen which may indicate the presence of another mode in the posterior with a relatively small probability mass.

Now let’s look at the auto-correlation plot:

autocor_plot(bayes_fpm_samples)

Some auto-correlation seems to persist in some chains so let’s try some thinning, by keeping only one out of every 5 samples.

thin_bayes_fpm_samples = discard(bayes_fpm; burnin = 1500, ratio = 0.2)

autocor_plot(thin_bayes_fpm_samples)

Looks better!

To Thin Or Not To Thin

In general, thinning is not recommended unless there are extremely high levels of auto-correlation in the samples. This is because the thinned samples will always have less information than the full set of samples before thinning. However, we perform thinning in this tutorial for demonstration purposes.

3.2.4 Posterior Predictive Check

Now let’s do a posterior predictive check by first simulating 1000 scenarios from the posterior distribution of the response including residual noise.

obstimes = 0.0:0.5:30.0
sims = simobs(bayes_fpm_samples; samples = 1000, simulate_error = true, obstimes)
[ Info: Simulating 1000 sample(s) from the posterior predictive distribution of each subject.
Simulated population (Vector{<:Subject})
  Simulated subjects: 1000
  Simulated variables: dv

then we can do a visual predictive check (VPC) plot using the simulations

vpc_res = vpc(sims; observations = [:dv], ensemblealg = EnsembleThreads())

vpc_plt = vpc_plot(
    vpc_res;
    simquantile_medians = true,
    observations = true,
    axis = (xlabel = "Time (h)", ylabel = "Concentration", xticks = 0:2:30),
)
[ Info: Detected 1000 scenarios and 1 subjects in the input simulations. Running VPC.
[ Info: Continuous VPC

Summary

With very few changes in the model and a few lines of code, we were able to obtain samples from the full posterior of the parameters of our poorly identifiable model.

4 Uncertainty Propagation, Queries and Decision Making

Just because a model is non-identifiable does not mean that the model is useless or less correct. In fact, more correct models that incorporate more biological processes tend to be non-identifiable because we can only observe/measure very few variables in the model, while simplified models are more likely to be identifiable. Given samples from the posterior of a non-identifiable model, one can do the following:

  • Propagate the uncertainty forward to the predictions to get samples from the posterior predictive distribution, instead of relying on a single prediction using the ML estimates.
Value of Uncertainty Quantification

Parameter uncertainty due to structural non-identifiability will by definition have no effect on the model’s predictions when predicting the observed response. However, uncertainty due to practical non-identifiability, or otherwise insufficient data, can have an impact on the model’s predictions. In this case, basing decisions on the full posterior predictive distribution instead of a single prediction from the ML estimates will make the decisions more robust to parameter uncertainty due to insufficient observations and model misspecification.

  • Ask probabilistic questions given your data. For example, what’s the probability that the drug effect is \(> 0\)? Or what’s the probability that the new drug A is better than the control drug B after only 3 months of data? Or what’s the probability of satisfying a therapeutic criteria for efficacy and safety given the current dose?
  • What-if analysis (aka counter-factual simulation) and dose optimization. For example, you can make predictions assuming the subject is a pediatric using the model parameters’ posterior inferred from an adult’s data. Or you can test different dose levels to select the best dose according to some therapeutic criteria. This can also be done in the non-Bayesian setting.

4.1 Probabilistic Questions

In this section, we show how to

  1. Estimate the probability that a parameter is more than a specific value, and
  2. Estimate the probability that the subject satisfies a desired therapeutic criteria. From there, one can simulate multiple doses and choose the dose that maximizes this probability.

To estimate the probability that CL > 35, we can run:

mean(bayes_fpm_samples) do p
    p.θ[1] > 35
end
0.13066666666666665

To estimate the probability that a subject satisfies a desired therapeutic criteria, we first simulate from the posterior predictive distribution (without residual error):

ipreds = simobs(bayes_fpm_samples; samples = 1000, simulate_error = false, obstimes)
[ Info: Simulating 1000 sample(s) from the posterior predictive distribution of each subject.
Simulated population (Vector{<:Subject})
  Simulated subjects: 1000
  Simulated variables: dv

Next, we can estimate the area-under-curve (auc) and maximum drug concentration (cmax) given the different posterior samples.

using NCA

nca_params = postprocess(ipreds) do gen, obs
    pk_auc = NCA.auc(gen.dv, obstimes)
    pk_cmax = NCA.cmax(gen.dv, obstimes)
    (; pk_auc, pk_cmax)
end
1000-element Vector{@NamedTuple{pk_auc::Float64, pk_cmax::Float64}}:
 (pk_auc = 89.53949725961877, pk_cmax = 10.221629651531638)
 (pk_auc = 88.99394733028751, pk_cmax = 9.710320469396205)
 (pk_auc = 88.54129430978901, pk_cmax = 9.535462396382718)
 (pk_auc = 84.63907734035817, pk_cmax = 9.24782955526989)
 (pk_auc = 82.82723386632642, pk_cmax = 9.019821081372449)
 (pk_auc = 87.89854669691962, pk_cmax = 9.49015548793787)
 (pk_auc = 87.82396599850615, pk_cmax = 9.812936163859327)
 (pk_auc = 90.22578467706104, pk_cmax = 10.4760328347226)
 (pk_auc = 86.76998314193558, pk_cmax = 9.76620097328118)
 (pk_auc = 86.53998943326238, pk_cmax = 9.763678531892129)
 ⋮
 (pk_auc = 88.7671973889428, pk_cmax = 9.881567767585544)
 (pk_auc = 86.44962153507429, pk_cmax = 9.676090791272848)
 (pk_auc = 88.51732140702805, pk_cmax = 10.197806243398349)
 (pk_auc = 85.09179168896962, pk_cmax = 9.420845484093437)
 (pk_auc = 87.79526305186029, pk_cmax = 9.887705796635785)
 (pk_auc = 84.71093771902345, pk_cmax = 9.10892190122383)
 (pk_auc = 83.97419761670892, pk_cmax = 8.841560761340515)
 (pk_auc = 86.14125579944515, pk_cmax = 9.516294293640472)
 (pk_auc = 89.23157385603781, pk_cmax = 9.796373300995372)

Finally, we can estimate the probability of satisfying a therapeutic criteria.

prob = mean(nca_params) do p
    p.pk_auc > 90 && p.pk_cmax < 15.0
end
0.038

To compute the probability of efficacy and safety separately, one can instead run:

prob1 = mean(nca_params) do p
    p.pk_auc > 90
end
prob2 = mean(nca_params) do p
    p.pk_cmax < 15.0
end
prob1, prob2
(0.038, 1.0)

4.2 Counter-factual Analysis and Dose Optimization

After developing a model, one may be interested in simulating scenarios, e.g. different covariates or doses, that have not been observed in the data while reusing the same posterior distribution of the parameters learnt from the data. This can be used to select a new dose that maximizes the probabilities of efficacy and safety simultaneously given the previously observed data.

In Pumas, you can do this by defining a new subject that includes the new covariates or dose and then passing that to simobs. First, let’s define a new skeleton subject that represents our counter-factual scenario where a dose of 3200 was administered instead of the 3000 used in the observed case:

cf_skeleton = Subject(
    id = 1,
    time = 0.0:0.5:30.0,
    events = DosageRegimen(3200, time = 0.0, cmt = 1),
    observations = (; dv = fill(missing, 61)),
)
Subject
  ID: 1
  Events: 1
  Observations: dv: (n=61)

To simulate from the posterior predictive distribution of this new subject using the posterior of the parameters, you can run:

cf_ipreds = simobs(
    thin_bayes_fpm_samples,
    cf_skeleton;
    samples = 1000,
    simulate_error = false,
    obstimes,
    subject = 1,
)
[ Info: [Subject: 1] Simulating 1000 sample(s) from the posterior predictive distribution of subject 1 using the dose and covariates in the input subject.
Simulated population (Vector{<:Subject})
  Simulated subjects: 1000
  Simulated variables: dv

We can then re-evaluate the probability of satisfying a therapeutic criteria:

cf_nca_params = postprocess(cf_ipreds) do gen, obs
    pk_auc = NCA.auc(gen.dv, obstimes)
    pk_cmax = NCA.cmax(gen.dv, obstimes)
    (; pk_auc, pk_cmax)
end
cf_prob = mean(cf_nca_params) do p
    p.pk_auc > 90 && p.pk_cmax < 15.0
end
0.962

We can see that the probability increased. To understand why, let’s look at the probabilities of the auc and cmax criteria separately:

cf_prob1 = mean(cf_nca_params) do p
    p.pk_auc > 90
end
cf_prob2 = mean(cf_nca_params) do p
    p.pk_cmax < 15.0
end
cf_prob1, cf_prob2
(0.962, 1.0)

Contrast this to the old dose’s probabilities:

prob1, prob2
(0.038, 1.0)

Note that this example was not particularly interesting because of the dense sampling which despite of it, the uncertainty in the parameters was still high. This implies that the uncertainty was largely due to structural identifiability issues in the model. Since uncertainty in parameters due to structural non-identifiability does not affect the model predictions, the posterior predictive distribution was much more concentrated than the parameters’ posterior.

To estimate the mean and standard deviation of the predictions at each point in time we can run:

μs = mean.(postprocess((gen, _) -> gen.dv, ipreds))
σs = std.(postprocess((gen, _) -> gen.dv, ipreds))
61-element Vector{Float64}:
 0.0
 0.33228868619230967
 0.39259327569224445
 0.3634986544122638
 0.32305228308040795
 0.2932605116269078
 0.27165282412617636
 0.2517705087974945
 0.23055947106944327
 0.20803192132976867
 ⋮
 0.014204704605163534
 0.014511436995891554
 0.014860852890800882
 0.015239694210404515
 0.015636523179754124
 0.01604172337268067
 0.0164473783153448
 0.016847088881966454
 0.017235770420268175

To get the average relative standard deviations (ignoring the first prediction which is 0), we run:

mean(σs[2:end] ./ μs[2:end])
0.02552031542546678

So the predictions are not very sensitive to the parameter uncertainty.

5 Summary

In this tutorial, we have seen how to test for model non-identifiability using the Fisher information matrix and sensitivity analysis. We have shown that maximum likelihood estimation is unreliable when fitting poorly identifiable models. And we have seen how one can use Bayesian inference to: 1) fit non-identifiable or poorly identifiable models to data, 2) ask probabilistic questions of the model, and 3) simulate counter-factual scenarios.

6 References

  1. Thomas J. Rothenberg. Identification in parametric models. Econometrica, 1971.
  2. F. Mentre, A Mallet, and D. Baccar. Optimal design in random-effects regression models. Biometrika, 1997.
  3. S. Retout and F Mentre. Further development of the fisher information matrix in nonlinear mixed-effects models with evaluation in population pharmacokinetics. Journal of biopharmaceutical statistics, 2003.
  4. V. Shivva, K. Korell, I. Tucker, and S. Duffull. An approach for identifiability of population pharmacokinetic-pharmacodynamic models. CPT Pharmacometrics & Systems Pharmacology, 2013.
  5. Stephen Dufful, A workflow for resolving model internal consistency in use-reuse settings (aka repairing unstable models). PAGANZ, 2024.
  6. Dan Wright. The identifiability of a turnover model for allopurinol urate-lowering effect. PAGANZ, 2024.