using Pumas
Fitting Non-Identifiable and Poorly Identifiable Models using Bayesian Inference
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:
- 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.
- 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. - 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. |
- Local (or global) practical identifiablity is what we usually want in analyses.
- Practical identifiability (estimability) implies structural 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
:
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 begin
model @param begin
∈ VectorDomain(lower = zeros(5))
θ ∈ RealDomain(lower = 0.0)
σ end
@pre begin
= θ[1]
CL = θ[2]
Vc = θ[3]
Ka = θ[4]
Vp = θ[5]
Q end
@dynamics begin
' = -Ka * Depot
Depot' = Ka * Depot - (CL + Q) / Vc * Central + Q / Vp * Peripheral
Central' = Q / Vc * Central - Q / Vp * Peripheral
Peripheralend
@derived begin
:= @. Central / Vc
cp ~ @. Normal(cp, abs(cp) * σ + 1e-6)
dv end
end
PumasModel
Parameters: θ, σ
Random effects:
Covariates:
Dynamical system variables: Depot, Central, Peripheral
Dynamical system type: Matrix exponential
Derived: dv
Observed: dv
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.
= (θ = [35, 100, 0.5, 210, 30], σ = 0.1) params
(θ = [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.
= Subject(
skeleton = 1,
id = 0.0:0.5:30.0,
time = DosageRegimen(3000, time = 0.0, cmt = 1),
events = (; dv = nothing),
observations )
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
= OptimalDesign.ObsTimes(skeleton.time)
times = OptimalDesign.fim(model, [skeleton], params, [times]) F
6×6 Symmetric{Float64, Matrix{Float64}}:
1.29489 -0.0538762 13.6934 0.0254882 -0.218694 -2.68028
-0.0538762 0.0188821 -4.38015 -0.00168545 0.0296863 -0.325336
13.6934 -4.38015 1054.71 0.635262 -7.13309 66.7482
0.0254882 -0.00168545 0.635262 0.00215196 -0.00487912 -0.0895271
-0.218694 0.0296863 -7.13309 -0.00487912 0.144604 -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.
= eigen(F)
E 1] E.values[
9.646842560416682e-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.
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
- Assume parameter values \(\theta_0\),
- Define a criteria for changing the parameters \(\theta\) from their current values \(\theta_0\), and then create a candidate set of parameters \(\Theta_c\),
- Simulate synthetic data using the parameters \(\theta_0\),
- Evaluate the log likelihood \(L(\theta)\) for all \(\theta \in \Theta_c\),
- 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)
= [Subject(simobs(model, skeleton, params))] pop
Population
Subjects: 1
Observations: dv
To evaluate the log likelihood of params
given pop
, we can use the loglikelihood
function:
= loglikelihood(model, pop, params, NaivePooled()) ll0
32.82461166031001
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:
= E.vectors[:, 1] d
6-element Vector{Float64}:
0.006717009021479834
0.8382731175154712
0.003756057847021547
-0.5451738773536942
0.00493940395644825
-3.137352344514509e-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)
= vcat(-1e-3 .* (1:10), 1e-3 .* (1:10)) αs
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
= moveθ.(αs) newparams
20-element Vector{@NamedTuple{θ::Vector{Float64}, σ::Float64}}:
(θ = [34.99999328299098, 99.99916172688249, 0.499996243942153, 210.00054517387736, 29.999995060596042], σ = 0.1)
(θ = [34.999986565981956, 99.99832345376497, 0.49999248788430595, 210.0010903477547, 29.999990121192088], σ = 0.1)
(θ = [34.999979848972934, 99.99748518064746, 0.4999887318264589, 210.00163552163207, 29.99998518178813], σ = 0.1)
(θ = [34.99997313196391, 99.99664690752994, 0.4999849757686119, 210.00218069550942, 29.999980242384176], σ = 0.1)
(θ = [34.99996641495489, 99.99580863441243, 0.49998121971076487, 210.00272586938678, 29.999975302980218], σ = 0.1)
(θ = [34.99995969794587, 99.9949703612949, 0.4999774636529179, 210.00327104326414, 29.99997036357626], σ = 0.1)
(θ = [34.99995298093685, 99.9941320881774, 0.49997370759507087, 210.00381621714146, 29.999965424172306], σ = 0.1)
(θ = [34.999946263927825, 99.99329381505987, 0.49996995153722384, 210.00436139101882, 29.999960484768348], σ = 0.1)
(θ = [34.99993954691881, 99.99245554194236, 0.4999661954793768, 210.00490656489617, 29.999955545364394], σ = 0.1)
(θ = [34.99993282990979, 99.99161726882484, 0.4999624394215298, 210.00545173877353, 29.999950605960436], σ = 0.1)
(θ = [35.00000671700902, 100.00083827311751, 0.500003756057847, 209.99945482612264, 30.000004939403958], σ = 0.1)
(θ = [35.000013434018044, 100.00167654623503, 0.500007512115694, 209.9989096522453, 30.000009878807912], σ = 0.1)
(θ = [35.000020151027066, 100.00251481935254, 0.500011268173541, 209.99836447836793, 30.00001481821187], σ = 0.1)
(θ = [35.00002686803609, 100.00335309247006, 0.5000150242313881, 209.99781930449058, 30.000019757615824], σ = 0.1)
(θ = [35.00003358504511, 100.00419136558757, 0.5000187802892351, 209.99727413061322, 30.000024697019782], σ = 0.1)
(θ = [35.00004030205413, 100.0050296387051, 0.5000225363470822, 209.99672895673586, 30.00002963642374], σ = 0.1)
(θ = [35.00004701906315, 100.0058679118226, 0.5000262924049291, 209.99618378285854, 30.000034575827694], σ = 0.1)
(θ = [35.000053736072175, 100.00670618494013, 0.5000300484627762, 209.99563860898118, 30.000039515231652], σ = 0.1)
(θ = [35.00006045308119, 100.00754445805764, 0.5000338045206232, 209.99509343510383, 30.000044454635606], σ = 0.1)
(θ = [35.00006717009021, 100.00838273117516, 0.5000375605784703, 209.99454826122647, 30.000049394039564], σ = 0.1)
Now let’s evaluate the log likelihoods of all these parameter sets.
= map(newparams) do p
lls loglikelihood(model, pop, p, NaivePooled())
end
20-element Vector{Float64}:
32.82463258809126
32.82465351677627
32.824674446000195
32.82469537568664
32.824716304984676
32.8247372358197
32.82475816602154
32.82477909749628
32.82480002929201
32.82482096111186
32.82459073300787
32.82456980631988
32.8245488798115
32.824527953804534
32.824507026997054
32.824486102814475
32.82446517756737
32.824444254060836
32.82442333007209
32.824402406539726
To compute the average sensitivity within \(\Theta_c\), we then call:
= abs2.((lls .- ll0) ./ αs)
sens mean(sens)
0.0004379688926570479
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
:
= normalize(rand(6))
d2 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
= moveθ2.(αs)
newparams2 = map(newparams2) do p
lls2 loglikelihood(model, pop, p, NaivePooled())
end
= abs2.((lls2 .- ll0) ./ αs)
sens2 mean(sens2)
648.2220903337222
Notice the difference in sensitivity compared to a random direction.
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:
- Mask a truly singular matrix by reporting its smallest eigenvalue as very close to 0 but not exactly 0 in floating point numbers, or
- 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,
- Asymptotic estimates of standard errors require the model to be locally identifiable,
- 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.
- 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:
= (θ = [35, 100, 0.5, 210, 30], σ = 0.1)
params1 = fit(model, pop, params1, NaivePooled()) fpm1
[ 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.282461e+01 5.896801e+01
* time: 0.029909849166870117
1 -3.299541e+01 8.371540e+01
* time: 1.1290550231933594
2 -3.440867e+01 3.937303e+01
* time: 1.1297929286956787
3 -3.550285e+01 3.429323e+01
* time: 1.1304819583892822
4 -3.585802e+01 2.078146e+01
* time: 1.1311619281768799
5 -3.605801e+01 4.208231e+00
* time: 1.1318528652191162
6 -3.606867e+01 5.500193e+00
* time: 1.1324329376220703
7 -3.607820e+01 5.143560e-01
* time: 1.1330039501190186
8 -3.607823e+01 1.670014e-01
* time: 1.1338460445404053
9 -3.607823e+01 6.594679e-03
* time: 1.1347038745880127
10 -3.607823e+01 3.931880e-03
* time: 1.1353600025177002
11 -3.607823e+01 5.365684e-02
* time: 1.1359610557556152
12 -3.607823e+01 2.875458e-02
* time: 1.1365408897399902
13 -3.607823e+01 3.163448e-03
* time: 1.1370999813079834
14 -3.607823e+01 1.189047e-04
* time: 1.1376688480377197
FittedPumasModel
Successful minimization: true
Likelihood approximation: NaivePooled
Likelihood Optimizer: BFGS
Dynamical system type: Matrix exponential
Log-likelihood value: 36.078234
Number of subjects: 1
Number of parameters: Fixed Optimized
0 6
Observation records: Active Missing
dv: 61 0
Total: 61 0
-----------------
Estimate
-----------------
θ₁ 34.397
θ₂ 103.17
θ₃ 0.46566
θ₄ 204.44
θ₅ 26.234
σ 0.092273
-----------------
= (θ = [10.0, 300, 1.0, 10.0, 5], σ = 0.2)
params2 = fit(model, pop, params2, NaivePooled()) fpm2
[ 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.245135e+02 6.802168e+02
* time: 3.790855407714844e-5
1 1.499850e+02 4.520555e+01
* time: 0.000762939453125
2 1.436201e+02 4.485781e+01
* time: 0.0014510154724121094
3 1.108786e+02 4.698780e+01
* time: 0.0021169185638427734
4 9.146731e+01 4.889574e+01
* time: 0.0027818679809570312
5 8.587677e+01 4.879782e+01
* time: 0.0035469532012939453
6 8.353852e+01 5.068832e+01
* time: 0.004315853118896484
7 8.061237e+01 4.922992e+01
* time: 0.0050868988037109375
8 7.723482e+01 3.939427e+01
* time: 0.005867958068847656
9 7.347395e+01 6.732180e+01
* time: 0.006538867950439453
10 6.467070e+01 2.181937e+01
* time: 0.007197856903076172
11 5.389941e+01 4.260985e+01
* time: 0.0079498291015625
12 4.899559e+01 4.746853e+01
* time: 0.00871896743774414
13 4.636064e+01 4.389414e+01
* time: 0.009363889694213867
14 4.311120e+01 3.667380e+01
* time: 0.010031938552856445
15 3.452695e+01 4.210878e+01
* time: 0.010809898376464844
16 2.786722e+01 4.181505e+01
* time: 0.011595964431762695
17 2.167865e+01 2.502622e+01
* time: 0.012343883514404297
18 2.102586e+01 3.073394e+01
* time: 0.013007879257202148
19 2.012361e+01 9.155807e+00
* time: 0.013675928115844727
20 1.993999e+01 8.931312e+00
* time: 0.01432490348815918
21 1.899136e+01 3.290299e+01
* time: 0.08056902885437012
22 1.831295e+01 1.555682e+01
* time: 0.08130002021789551
23 1.764099e+01 4.156266e+00
* time: 0.08198690414428711
24 1.734278e+01 4.764554e+00
* time: 0.0826869010925293
25 1.692204e+01 5.545117e+00
* time: 0.0833749771118164
26 1.576407e+01 6.312613e+00
* time: 0.08418893814086914
27 1.433865e+01 8.298711e+00
* time: 0.08503890037536621
28 1.402269e+01 1.935486e+01
* time: 0.08588600158691406
29 1.388981e+01 5.313925e+00
* time: 0.08662700653076172
30 1.380201e+01 6.598826e+00
* time: 0.08734393119812012
31 1.361376e+01 1.819858e+01
* time: 0.08807086944580078
32 1.307080e+01 3.715714e+01
* time: 0.08879899978637695
33 1.084751e+01 4.989781e+01
* time: 0.08955502510070801
34 8.794248e+00 2.744496e+01
* time: 0.1075749397277832
35 7.967402e+00 6.287105e+01
* time: 0.10846996307373047
36 5.931368e+00 1.205492e+02
* time: 0.10920190811157227
37 1.326739e+00 7.171268e+01
* time: 0.10992097854614258
38 -3.688673e+00 4.982944e+01
* time: 0.11074185371398926
39 -7.683634e+00 6.784296e+01
* time: 0.11157393455505371
40 -8.093111e+00 7.793740e+01
* time: 0.11230587959289551
41 -9.110435e+00 4.537001e+01
* time: 0.11303496360778809
42 -9.287455e+00 8.053249e+00
* time: 0.11376690864562988
43 -9.348580e+00 4.062388e+00
* time: 0.11462879180908203
44 -9.351767e+00 5.738585e+00
* time: 0.11533188819885254
45 -9.356980e+00 7.032363e+00
* time: 0.11602783203125
46 -9.368311e+00 8.133604e+00
* time: 0.11672401428222656
47 -9.397386e+00 8.740281e+00
* time: 0.11740994453430176
48 -9.477884e+00 5.350272e+00
* time: 0.11810588836669922
49 -9.561787e+00 2.652045e+01
* time: 0.1187899112701416
50 -9.929166e+00 4.058352e+01
* time: 0.11947989463806152
51 -1.065000e+01 1.579981e+01
* time: 0.1201479434967041
52 -1.075194e+01 4.940469e+00
* time: 0.12094593048095703
53 -1.084774e+01 3.374353e+01
* time: 0.12160801887512207
54 -1.092895e+01 1.839000e+01
* time: 0.12226486206054688
55 -1.096946e+01 1.467589e+01
* time: 0.12293601036071777
56 -1.100983e+01 6.336931e+00
* time: 0.12360000610351562
57 -1.101466e+01 1.163012e+00
* time: 0.12425398826599121
58 -1.101772e+01 1.274154e+00
* time: 0.12492799758911133
59 -1.102000e+01 5.895134e-01
* time: 0.12559986114501953
60 -1.102013e+01 6.917960e-02
* time: 0.12625384330749512
61 -1.102013e+01 2.213221e-03
* time: 0.12692689895629883
62 -1.102013e+01 1.812675e-04
* time: 0.12760090827941895
FittedPumasModel
Successful minimization: true
Likelihood approximation: NaivePooled
Likelihood Optimizer: BFGS
Dynamical system type: Matrix exponential
Log-likelihood value: 11.020132
Number of subjects: 1
Number of parameters: Fixed Optimized
0 6
Observation records: Active Missing
dv: 61 0
Total: 61 0
----------------
Estimate
----------------
θ₁ 30.963
θ₂ 214.26
θ₃ 55.564
θ₄ 169.43
θ₅ 12.071
σ 0.13904
----------------
Now let’s display the estimates of θ
side by side:
hcat(coef(fpm1).θ, coef(fpm2).θ)
5×2 Matrix{Float64}:
34.3968 30.9629
103.168 214.262
0.465659 55.5644
204.442 169.427
26.2337 12.0708
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)
= (; θ = params.θ, σ = 0.2)
newparams = [Subject(simobs(model, skeleton, newparams))] newpop
Population
Subjects: 1
Observations: dv
Now let’s do the fit once with pop
and once with newpop
:
= fit(model, pop, params, NaivePooled()) fpm1
[ 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.282461e+01 5.896801e+01
* time: 2.8133392333984375e-5
1 -3.299541e+01 8.371540e+01
* time: 0.0007960796356201172
2 -3.440867e+01 3.937303e+01
* time: 0.001438140869140625
3 -3.550285e+01 3.429323e+01
* time: 0.0020890235900878906
4 -3.585802e+01 2.078146e+01
* time: 0.002711057662963867
5 -3.605801e+01 4.208231e+00
* time: 0.003348112106323242
6 -3.606867e+01 5.500193e+00
* time: 0.0038940906524658203
7 -3.607820e+01 5.143560e-01
* time: 0.004456043243408203
8 -3.607823e+01 1.670014e-01
* time: 0.0050160884857177734
9 -3.607823e+01 6.594679e-03
* time: 0.005591154098510742
10 -3.607823e+01 3.931880e-03
* time: 0.006173133850097656
11 -3.607823e+01 5.365684e-02
* time: 0.006788015365600586
12 -3.607823e+01 2.875458e-02
* time: 0.0073699951171875
13 -3.607823e+01 3.163448e-03
* time: 0.007958173751831055
14 -3.607823e+01 1.189047e-04
* time: 0.008535146713256836
FittedPumasModel
Successful minimization: true
Likelihood approximation: NaivePooled
Likelihood Optimizer: BFGS
Dynamical system type: Matrix exponential
Log-likelihood value: 36.078234
Number of subjects: 1
Number of parameters: Fixed Optimized
0 6
Observation records: Active Missing
dv: 61 0
Total: 61 0
-----------------
Estimate
-----------------
θ₁ 34.397
θ₂ 103.17
θ₃ 0.46566
θ₄ 204.44
θ₅ 26.234
σ 0.092273
-----------------
= fit(model, newpop, newparams, NaivePooled()) fpm2
[ 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.763976e+00 2.735808e+01
* time: 2.8133392333984375e-5
1 8.405325e+00 2.531358e+01
* time: 0.0009250640869140625
2 6.620382e+00 1.286061e+01
* time: 0.001722097396850586
3 5.297438e+00 8.779519e+00
* time: 0.002524137496948242
4 4.963913e+00 3.840318e+00
* time: 0.0033249855041503906
5 4.930293e+00 1.184668e+01
* time: 0.004027128219604492
6 4.873975e+00 3.753008e+00
* time: 0.0047261714935302734
7 4.858307e+00 2.308575e+00
* time: 0.005518198013305664
8 4.854947e+00 8.434789e-02
* time: 0.006214141845703125
9 4.854713e+00 7.173484e-02
* time: 0.006940126419067383
10 4.853126e+00 8.197275e-01
* time: 0.007683992385864258
11 4.851996e+00 1.269989e+00
* time: 0.008426189422607422
12 4.850709e+00 1.179594e+00
* time: 0.009150981903076172
13 4.849908e+00 1.616556e-01
* time: 0.009888172149658203
14 4.849724e+00 8.747458e-01
* time: 0.010619163513183594
15 4.849534e+00 1.703991e-01
* time: 0.011355161666870117
16 4.849431e+00 1.385411e-01
* time: 0.012080192565917969
17 4.849400e+00 1.192474e-01
* time: 0.012817144393920898
18 4.849395e+00 8.727158e-03
* time: 0.013559103012084961
19 4.849394e+00 2.408207e-02
* time: 0.014322996139526367
20 4.849394e+00 1.491007e-03
* time: 0.015119075775146484
21 4.849394e+00 1.658889e-04
* time: 0.015922069549560547
FittedPumasModel
Successful minimization: true
Likelihood approximation: NaivePooled
Likelihood Optimizer: BFGS
Dynamical system type: Matrix exponential
Log-likelihood value: -4.8493937
Number of subjects: 1
Number of parameters: Fixed Optimized
0 6
Observation records: Active Missing
dv: 61 0
Total: 61 0
----------------
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.465659 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
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”:
= @model begin
bayes_model @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
= θ[1]
CL = θ[2]
Vc = θ[3]
Ka = θ[4]
Vp = θ[5]
Q end
@dynamics begin
' = -Ka * Depot
Depot' = Ka * Depot - (CL + Q) / Vc * Central + Q / Vp * Peripheral
Central' = Q / Vc * Central - Q / Vp * Peripheral
Peripheralend
@derived begin
:= @. Central / Vc
cp ~ @. Normal(cp, abs(cp) * σ + 1e-6)
dv 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)
= BayesMCMC(; nsamples = 3_000, nadapts = 1_500)
bayes_alg = fit(bayes_model, pop, params, bayes_alg) bayes_fpm
[ 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: 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.
Chains MCMC chain (3000×6×4 Array{Float64, 3}):
Iterations = 1:1:3000
Number of chains = 4
Samples per chain = 3000
Wall duration = 63.49 seconds
Compute duration = 239.86 seconds
parameters = θ₁, θ₂, θ₃, θ₄, θ₅, σ
Summary Statistics
parameters mean std mcse ess_bulk ess_tail rhat ⋯
Symbol Float64 Float64 Float64 Float64 Float64 Float64 ⋯
θ₁ 34.2653 0.6524 0.0091 5560.7363 4315.8799 1.0004 ⋯
θ₂ 139.6789 35.0263 0.7813 2085.6410 3832.5950 1.0010 ⋯
θ₃ 0.6554 0.1855 0.0041 2051.4930 3674.0996 1.0007 ⋯
θ₄ 190.0748 18.9361 0.3653 2863.5219 4289.7292 1.0010 ⋯
θ₅ 23.1891 2.9890 0.0589 2637.4048 4046.8344 1.0003 ⋯
σ 0.0983 0.0098 0.0001 6139.5722 6315.1669 1.0003 ⋯
1 column omitted
Quantiles
parameters 2.5% 25.0% 50.0% 75.0% 97.5%
Symbol Float64 Float64 Float64 Float64 Float64
θ₁ 32.9656 33.8489 34.2753 34.6921 35.5300
θ₂ 72.0041 112.5028 143.8744 167.2478 197.3135
θ₃ 0.3506 0.5040 0.6519 0.7880 1.0281
θ₄ 159.1648 176.4174 188.1600 201.6452 231.8126
θ₅ 17.3172 21.0155 23.4058 25.3718 28.5518
σ 0.0815 0.0915 0.0975 0.1042 0.1196
Now let’s discard the NUTS warmup samples as burn-in:
= Pumas.discard(bayes_fpm, burnin = 1500) 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 = 63.49 seconds
Compute duration = 239.86 seconds
parameters = θ₁, θ₂, θ₃, θ₄, θ₅, σ
Summary Statistics
parameters mean std mcse ess_bulk ess_tail rhat ⋯
Symbol Float64 Float64 Float64 Float64 Float64 Float64 ⋯
θ₁ 34.2602 0.6637 0.0142 2545.7045 2015.8210 1.0010 ⋯
θ₂ 140.1054 35.1259 1.0927 1068.3604 2148.5638 1.0046 ⋯
θ₃ 0.6584 0.1881 0.0061 976.0496 1895.4011 1.0049 ⋯
θ₄ 189.8635 18.9390 0.4970 1558.0093 2180.1383 1.0045 ⋯
θ₅ 23.1569 3.0126 0.0877 1214.6592 1763.6933 1.0033 ⋯
σ 0.0983 0.0099 0.0002 3083.9398 3313.6080 1.0013 ⋯
1 column omitted
Quantiles
parameters 2.5% 25.0% 50.0% 75.0% 97.5%
Symbol Float64 Float64 Float64 Float64 Float64
θ₁ 32.9334 33.8365 34.2792 34.6861 35.5418
θ₂ 72.3979 113.3379 143.8530 167.8664 197.8678
θ₃ 0.3522 0.5073 0.6520 0.7916 1.0377
θ₄ 159.0653 176.1478 188.1336 201.5046 231.8082
θ₅ 17.2903 20.9603 23.3497 25.3492 28.5567
σ 0.0814 0.0913 0.0973 0.1043 0.1199
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.006717009021479834
0.8382731175154712
0.003756057847021547
-0.5451738773536942
0.00493940395644825
-3.137352344514509e-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; linkyaxes = false)
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; linkyaxes = false)
Some auto-correlation seems to persist in some chains so let’s try some thinning, by keeping only one out of every 5 samples.
= Pumas.discard(bayes_fpm, burnin = 1500, ratio = 0.2)
thin_bayes_fpm_samples
autocor_plot(thin_bayes_fpm_samples; linkyaxes = false)
Looks better!
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.
= 0.0:0.5:30.0
obstimes = simobs(bayes_fpm_samples; samples = 1000, simulate_error = true, obstimes) sims
[ Info: Sampling 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(sims; observations = [:dv], ensemblealg = EnsembleThreads())
vpc_res
= vpc_plot(
vpc_plt
vpc_res;= true,
simquantile_medians = true,
observations = (xlabel = "Time (h)", ylabel = "Concentration", xticks = 0:2:30),
axis )
[ Info: Detected 1000 scenarios and 1 subjects in the input simulations. Running VPC.
[ Info: Continuous VPC
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.
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 drugB
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
- Estimate the probability that a parameter is more than a specific value, and
- 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
1] > 35
p.θ[end
0.12083333333333333
To estimate the probability that a subject satisfies a desired therapeutic criteria, we first simulate from the posterior predictive distribution (without residual error):
= simobs(bayes_fpm_samples; samples = 1000, simulate_error = false, obstimes) ipreds
[ Info: Sampling 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
= postprocess(ipreds) do gen, obs
nca_params = NCA.auc(gen.dv, obstimes)
pk_auc = NCA.cmax(gen.dv, obstimes)
pk_cmax
(; pk_auc, pk_cmax)end
1000-element Vector{@NamedTuple{pk_auc::Float64, pk_cmax::Float64}}:
(pk_auc = 85.23807656378106, pk_cmax = 9.424857317752819)
(pk_auc = 86.0329082707837, pk_cmax = 9.74847135662025)
(pk_auc = 89.54665574658951, pk_cmax = 10.308994028362013)
(pk_auc = 87.03718638812137, pk_cmax = 9.653787711392967)
(pk_auc = 87.07949808638695, pk_cmax = 9.959070188657499)
(pk_auc = 88.72384593165604, pk_cmax = 10.308764191850871)
(pk_auc = 85.91937053837992, pk_cmax = 9.505193210247015)
(pk_auc = 88.81136140666904, pk_cmax = 10.198981235844684)
(pk_auc = 86.56337455452247, pk_cmax = 9.677059457254273)
(pk_auc = 86.16038372001704, pk_cmax = 9.92316710574459)
⋮
(pk_auc = 86.8247241472587, pk_cmax = 9.624614872506436)
(pk_auc = 86.71032696627313, pk_cmax = 9.284386772762288)
(pk_auc = 87.18212567384609, pk_cmax = 9.77581253010367)
(pk_auc = 86.65979240034193, pk_cmax = 9.697603558886472)
(pk_auc = 90.16238294625272, pk_cmax = 10.242840574414371)
(pk_auc = 87.1102830882913, pk_cmax = 9.740081362098135)
(pk_auc = 89.41668620593165, pk_cmax = 9.765428964454733)
(pk_auc = 88.04519805575593, pk_cmax = 9.35929256271468)
(pk_auc = 88.88679023392854, pk_cmax = 10.413288103301836)
Finally, we can estimate the probability of satisfying a therapeutic criteria.
= mean(nca_params) do p
prob > 90 && p.pk_cmax < 15.0
p.pk_auc end
0.036
To compute the probability of efficacy and safety separately, one can instead run:
= mean(nca_params) do p
prob1 > 90
p.pk_auc end
= mean(nca_params) do p
prob2 < 15.0
p.pk_cmax end
prob1, prob2
(0.036, 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:
= Subject(
cf_skeleton = 1,
id = 0.0:0.5:30.0,
time = DosageRegimen(3200, time = 0.0, cmt = 1),
events = (; dv = nothing),
observations )
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:
= simobs(
cf_ipreds
thin_bayes_fpm_samples,
cf_skeleton;= 1000,
samples = false,
simulate_error
obstimes,= 1,
subject )
[ Info: 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:
= postprocess(cf_ipreds) do gen, obs
cf_nca_params = NCA.auc(gen.dv, obstimes)
pk_auc = NCA.cmax(gen.dv, obstimes)
pk_cmax
(; pk_auc, pk_cmax)end
= mean(cf_nca_params) do p
cf_prob > 90 && p.pk_cmax < 15.0
p.pk_auc end
0.944
We can see that the probability increased. To understand why, let’s look at the probabilities of the auc
and cmax
criteria separately:
= mean(cf_nca_params) do p
cf_prob1 > 90
p.pk_auc end
= mean(cf_nca_params) do p
cf_prob2 < 15.0
p.pk_cmax end
cf_prob1, cf_prob2
(0.944, 1.0)
Contrast this to the old dose’s probabilities:
prob1, prob2
(0.036, 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:
= mean(ipreds) do gen, obs
μs
gen.dvend
= std(ipreds) do gen, obs
σs
gen.dvend
61-element Vector{Float64}:
0.0
0.3342869404164667
0.40521741960369306
0.38613010976714557
0.3494051832755949
0.31647076081922587
0.2880784468874247
0.2610276715665535
0.23386680675279967
0.20700027475240781
⋮
0.014499837844263546
0.01483568709985409
0.01522086682809398
0.015640843979409128
0.016083006720454807
0.01653670365181253
0.016993131871029396
0.017445147287977462
0.017887046774356166
To get the average relative standard deviations (ignoring the first prediction which is 0), we run:
mean(σs[2:end] ./ μs[2:end])
0.02580544027921953
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
- Thomas J. Rothenberg. Identification in parametric models. Econometrica, 1971.
- F. Mentre, A Mallet, and D. Baccar. Optimal design in random-effects regression models. Biometrika, 1997.
- 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.
- V. Shivva, K. Korell, I. Tucker, and S. Duffull. An approach for identifiability of population pharmacokinetic-pharmacodynamic models. CPT Pharmacometrics & Systems Pharmacology, 2013.
- Stephen Dufful, A workflow for resolving model internal consistency in use-reuse settings (aka repairing unstable models). PAGANZ, 2024.
- Dan Wright. The identifiability of a turnover model for allopurinol urate-lowering effect. PAGANZ, 2024.