Quiz: identifiability and uncertainty of fitted parameters

Short questions to test your understanding of identifiability, standard errors and profiles. Try each on paper first, then open the answer.


Q1. What is the difference between structural and practical non-identifiability? Give one example of each from the pharmacokinetic model.

Ask: would perfect, noise-free data at every time point fix the problem?

Structural: the model equations themselves give the same output for different parameter values, so no data can tell them apart. Examples: \(F\) and \(V\) enter only as \(F/V\); the flip-flop \((k_a, k_e, V) \leftrightarrow (k_e, k_a, Vk_e/k_a)\). Practical: the model could tell them apart, but the available data do not (too few, too noisy or badly placed samples). Example: \(k_a\) when the first blood sample is taken at 3 h, after absorption is complete.


Q2. nls stops with “singular gradient matrix at initial parameter estimates” when you fit \(C(t)\) with both \(F\) and \(V\) free. Python’s least_squares returns an answer without complaint. Which one is right, and what should you do?

What do the columns \(\partial C/\partial\log V\) and \(\partial C/\partial\log F\) look like?

nls is right: the two columns of the Jacobian are exact negatives of each other (in log-parameters), so \(J^TJ\) is singular and Gauss–Newton cannot compute a step. least_squares uses a damped (trust-region) step, which still moves, and stops at some point on the line $V/F = $ const; which point depends on the start. Its \(F\) and \(V\) mean nothing. Reparameterise: fit the apparent volume \(V/F\), and get \(F\) from a separate experiment (an IV dose).


Q3. Two fits from different starting values give \((k_a, k_e, V) = (1.0151, 0.1906, 20.22)\) and \((0.1906, 1.0151, 3.796)\), both with SSE \(= 0.06646744\). Is this a convergence problem? How do you decide which one to report?

Compare the SSE values, and look at which numbers have been swapped.

No: both are exact minima with identical SSE, related by the flip-flop symmetry (\(V' = Vk_e/k_a = 20.22\cdot0.1906/1.0151 = 3.796\)). The concentration curve cannot decide. Outside knowledge must: an intravenous study gives \(k_e\) directly; or the formulation is known to be absorbed faster than it is eliminated, in which case impose \(k_a > k_e\) (e.g. fit \(k_a = k_e + e^\delta\)) and say so.


Q4. Write the approximate covariance matrix of least-squares estimates in terms of the Jacobian. Where does each part come from, and what does vcov(fit) compute?

Linearise the model around \(\hat\theta\); then it is a linear regression with design matrix \(J\).

\(\operatorname{Cov}(\hat\theta) \approx \sigma^2(J^TJ)^{-1}\), with \(J_{ij} = \partial C(t_i)/\partial\theta_j\) at \(\hat\theta\) and \(\sigma^2\) estimated by \(s^2 = S(\hat\theta)/(n - p)\). It is the linear-regression formula \(\sigma^2(X^TX)^{-1}\) with \(J\) as the design matrix. Equivalently \(2s^2H^{-1}\) with \(H \approx 2J^TJ\) the Hessian of the sum of squares, or the inverse Fisher information \((J^TJ/\sigma^2)^{-1}\). vcov computes \(s^2(J^TJ)^{-1}\) from the QR factor of \(J\), without forming \(J^TJ\).


Q5. The correlation between \(\hat k_a\) and \(\hat V\) is 0.90. A colleague says: “so absorption rate and volume are correlated in this patient”. What is wrong with that?

The correlation is between estimates. What would happen if you repeated the experiment with new noise?

The patient has one \(k_a\) and one \(V\); the correlation describes the estimates: over repeated experiments with new noise, a too-high \(\hat k_a\) tends to come with a too-high \(\hat V\), because the data constrain a combination better than either parameter. It is a property of the design and the model, not of the biology. It shows a tilted, elongated valley in the sum of squares; with a different sampling design the correlation changes.


Q6. The singular values of the log-parameter Jacobian are \(8.78\), \(3.48\) and \(1.01\), and \(s = 0.086\). What is the standard error along each right singular vector? Why scale the columns by the parameter values first?

Noise along \(v_i\) is amplified by \(1/\sigma_i\) (The SVD, rank deficiency and regularisation).

\(s/\sigma_i = 0.0098\), \(0.025\), \(0.085\) (log units, so about 1 %, 2.5 % and 9 %). The right singular vector \(v_3\) names the worst-determined combination of \(\log k_a, \log k_e, \log V\). Without scaling, columns are in different units (\(V\) in litres, rates per hour), so the singular values and \(\kappa(J) = 170\) mostly measure units; with \(\partial C/\partial\log\theta_j\) every column is “change per relative change”, \(\kappa = 8.7\), and the directions are comparable.


Q7. Why should you not compute standard errors with solve(crossprod(J)) for a badly conditioned problem? What is the alternative?

Pivoting, norms and conditioning and the normal equations.

\(\kappa(J^TJ) = \kappa(J)^2\), so forming \(J^TJ\) squares the condition number and loses about \(2\log_{10}\kappa(J)\) digits: with \(\kappa(J) = 10^8\) nothing correct is left, and solve may report a singular matrix. Use the QR factor, \((J^TJ)^{-1} = R^{-1}R^{-T}\) (chol2inv(qr.R(qr(J)))), or the SVD, \((J^TJ)^{-1} = V\Sigma^{-2}V^T\), which also shows which direction is the problem.


Q8. Describe how to compute the profile likelihood of \(k_a\). With the first sample at 3 h, the profile of \(k_a\) falls to 0 at \(\hat k_a = 1.12\), reaches 3.84 at \(k_a = 0.68\), and levels off at 1.07 for large \(k_a\). nls reports \(k_a = 1.12 \pm 0.41\). What is the 95 % interval, and which statement do you report?

Where does the profile cross 3.84 on each side?

Fix \(k_a\) on a grid; at each value re-fit all other parameters (\(k_e\), \(V\)) and record the minimal SSE; plot \((\text{PL}(k_a) - S(\hat\theta))/s^2\). The 95 % interval is where it is below 3.84: here \((0.68, \infty)\), since the profile never comes back up. Report “\(k_a > 0.68\) /h; not bounded above by these data”. The Wald interval \(1.12 \pm 1.96\cdot0.41 = (0.33, 1.92)\) is wrong on both sides, because the sum of squares is far from a quadratic bowl.


Q9. What is a sloppy model? If a model is sloppy, is it useless?

Look at the eigenvalues of \(J^TJ\) on a log scale, and think about predictions instead of parameters.

The eigenvalues of \(J^TJ\) (in log-parameters) are spread roughly evenly over many decades, with no clear gap: a few stiff parameter combinations are well determined and many sloppy ones are not (two-compartment PK model: 4.5 decades for 5 parameters). It is not useless: predictions that depend on the stiff combinations, typically predictions inside the sampled window, can be precise even when individual parameters are not. Check the uncertainty of the prediction you need (\(g^T\operatorname{Cov}\,g\), or a profile of the prediction), not only of the parameters.


Q10. Name three ways to deal with a parameter that is practically non-identifiable, and the price of each.

One acts before the experiment, one changes what you estimate, one adds information that is not in the data.

  1. Better design: choose sample times where \(\partial C/\partial\theta\) is large, compared in advance with \(J\) at a guessed \(\theta\) (for \(k_a\): samples in the first 2–3 h; SE of \(\log k_a\) 0.40 → 0.10 with the same six samples). Price: needs a new experiment and a rough guess. (2) Reparameterise: estimate what is determined (\(V/F\), AUC, clearance, \(\log\) parameters). Price: you do not get the original parameter. (3) Prior / regularisation: add \((\log k_a - \mu)/\tau\) as a residual. Price: the answer may be mostly prior; report \(\tau\) and compare the posterior SE with it.

Q11. In code (continuing from the setup block of the exercise): fit the model, compute the Jacobian J at the optimum, and from it the standard errors via QR and the correlation matrix.

\((J^TJ)^{-1} = (R^TR)^{-1}\) with \(R\) from the QR decomposition of \(J\).

fit <- nls(y ~ bateman(tt, ka, ke, V), start = list(ka = 0.5, ke = 0.1, V = 10))
J   <- jacobian(function(p) bateman(tt, p[1], p[2], p[3]), coef(fit))
s2  <- deviance(fit) / (length(y) - length(coef(fit)))
Cv  <- s2 * chol2inv(qr.R(qr(J)))        # = vcov(fit)
se  <- sqrt(diag(Cv))
round(se, 4)
# [1] 0.0624 0.0104 0.7165
round(Cv / outer(se, se), 2)             # = cov2cor(Cv)
#       [,1]  [,2]  [,3]
# [1,]  1.00 -0.82  0.90
# [2,] -0.82  1.00 -0.91
# [3,]  0.90 -0.91  1.00
th, S, res = fit_pk(tt, y, [0.5, 0.1, 10])
J = jacobian(lambda p: bateman(tt, *p), th)
s2 = S / (len(y) - len(th))
Rinv = np.linalg.inv(np.linalg.qr(J, mode="r"))
Cv = s2 * Rinv @ Rinv.T
se = np.sqrt(np.diag(Cv))
print(np.round(se, 4))
# [0.0624 0.0104 0.7165]
print(np.round(Cv / np.outer(se, se), 2))
# [[ 1.   -0.82  0.9 ]
#  [-0.82  1.   -0.91]
#  [ 0.9  -0.91  1.  ]]
// rust/examples/identifiability_q11.rs  —  cargo run --example identifiability_q11
// Quiz Q11: standard errors via QR, and the correlation matrix.
#![allow(dead_code)]
use nalgebra::{DMatrix, DVector};

// One-compartment model with oral absorption, dose D = 100 mg (mg/L)
const D: f64 = 100.0; // oral dose, mg
fn bateman(t: f64, ka: f64, ke: f64, v: f64) -> f64 {
    D * ka / (v * (ka - ke)) * ((-ke * t).exp() - (-ka * t).exp())
}
const TT: [f64; 12] = [0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0];
const Y: [f64; 12] = [1.02, 1.88, 2.34, 2.98, 3.27, 3.26, 3.17, 2.77, 1.92, 1.23, 1.00, 0.61];

// Central-difference Jacobian of f at p (like numDeriv::jacobian, less refined)
fn jacobian(f: &dyn Fn(&[f64]) -> Vec<f64>, p: &[f64]) -> DMatrix<f64> {
    let n = f(p).len();
    let mut j = DMatrix::zeros(n, p.len());
    for k in 0..p.len() {
        let h = 1e-5 * p[k].abs().max(1.0);
        let (mut pp, mut pm) = (p.to_vec(), p.to_vec());
        pp[k] += h;
        pm[k] -= h;
        let (fp, fm) = (f(&pp), f(&pm));
        for i in 0..n { j[(i, k)] = (fp[i] - fm[i]) / (2.0 * h); }
    }
    j
}

// Levenberg-Marquardt for min sum r(p)^2, hand-written (R: nls / nls.lm, Python: least_squares)
fn levmar(r: &dyn Fn(&[f64]) -> Vec<f64>, p0: &[f64]) -> Vec<f64> {
    let ss = |p: &[f64]| -> f64 { let v = r(p); if v.iter().all(|x| x.is_finite()) { v.iter().map(|x| x * x).sum() } else { f64::INFINITY } };
    let (mut p, mut mu) = (p0.to_vec(), 1e-3);
    for _ in 0..500 {
        let j = jacobian(r, &p);                     // Jacobian of the residuals
        let rv = DVector::from_vec(r(&p));
        let jtj = j.transpose() * &j;
        let g = j.transpose() * &rv;
        loop {
            let a = &jtj + DMatrix::from_diagonal(&jtj.diagonal()) * mu;
            let step = a.lu().solve(&(-&g)).unwrap();
            let pn: Vec<f64> = p.iter().zip(step.iter()).map(|(a, b)| a + b).collect();
            if ss(&pn) <= ss(&p) {
                let small = step.norm() < 1e-12 * (1.0 + DVector::from_vec(p.clone()).norm());
                p = pn;
                mu = (mu / 10.0).max(1e-12);
                if small { return p; }
                break;
            }
            mu *= 10.0;
            if mu > 1e12 { return p; }
        }
    }
    p
}

// Residuals y - C(t) for the one-compartment model at the sample times ts
fn resid(ts: &[f64], ys: &[f64]) -> impl Fn(&[f64]) -> Vec<f64> {
    let (ts, ys) = (ts.to_vec(), ys.to_vec());
    move |p: &[f64]| ts.iter().zip(&ys).map(|(ti, yi)| yi - bateman(*ti, p[0], p[1], p[2])).collect()
}
fn sse(r: &dyn Fn(&[f64]) -> Vec<f64>, p: &[f64]) -> f64 { r(p).iter().map(|x| x * x).sum() }

fn main() {
    let r = resid(&TT, &Y);
    let th = levmar(&r, &[0.5, 0.1, 10.0]);
    let j = jacobian(&r, &th);
    let s2 = sse(&r, &th) / (TT.len() - th.len()) as f64;
    let rinv = j.qr().r().try_inverse().unwrap();
    let cv = &rinv * rinv.transpose() * s2;
    let se: Vec<f64> = (0..3).map(|i| cv[(i, i)].sqrt()).collect();
    println!("{:.4} {:.4} {:.4}", se[0], se[1], se[2]);
    let cor = DMatrix::from_fn(3, 3, |i, k| cv[(i, k)] / (se[i] * se[k]));
    for i in 0..3 {
        println!("{:6.2} {:6.2} {:6.2}", cor[(i, 0)], cor[(i, 1)], cor[(i, 2)]);
    }
}

// Output:
// 0.0624 0.0104 0.7165
//   1.00  -0.82   0.90
//  -0.82   1.00  -0.91
//   0.90  -0.91   1.00

These are the numbers of vcov(fit) and cov2cor (exercise C1). The R and Python versions continue from the setup block of the exercise; the Rust file is complete.