In general,
\[E[f(X)]\ne f(E[X])\]
and
\[\hat{f}(\boldsymbol\theta)\ne f(\hat{\boldsymbol\theta})\]
yet statisticians keep assuming equality.
This presentation is drawn from our paper that is under review at the Journal of Biopharmaceutical Statistics.
Divan A. Burger\(^{1,2}\), Sean van der Merwe\(^{2}\), Emmanuel Lesaffre\(^{3,4}\)
Consider the rate at which people get better from HIV when taking ARVs
The expected rate of healing for a random future person is not the same as for the typical person (doesnβt exist)
The ACTG 315 dataset, available in the ushr R package (Morris et al. 2020), includes longitudinal measurements of HIV viral load (log\(_{10}\) RNA copies/mL) over time. It features data on 46 patients, with the longest measurement recorded on Day 196 after baseline (Day 0).
We observe two kinds of censoring:
We address these in different ways:
We build up the model step by step.
Random effects are important to help address the fact that our residuals are not independent.
Each person has their own curve
Each person has an intercept, an initial slope, a turning point, an ultimate slope, and their own turning smoothness. Some turn gradually while others are more kinky (literally, not figuratively).
Examples of papers implementing this idea in various fields include: Perelson et al. (1996), Heerspink et al. (2021), Bacon and Watts (1971), Donald and Diacon (2008), Burger and Schall (2015), Hall et al. (2000), Ghosh and Vaida (2007), van den Hout et al. (2011), etc.
While we did formally use the DHARMa approach in the paper to check the goodness-of-fit for the two models (Hartig 2021), I want to encourage all researchers to try to plot the model and data together if at all possible (sometimes some creativity and some conditioning is needed).
model {
for (r in 1:3) {
L_chol[r, r] ~ dt(0, 0.5, 3)T(0, )
for (c in 1:(r - 1)) {
L_chol[r, c] ~ dnorm(0, 0.001)
}
for (c in (r + 1):3) {
L_chol[r, c] <- 0
}
}
for (r in 1:3) {
for (c in 1:3) {
Prec_RE[r, c] <- inprod(L_chol[r, 1:3], L_chol[c, 1:3])
}
}
for (j in 1:3) {
Beta_RE_bar[j] ~ dnorm(0, 0.001)
}
Sigma_resid ~ dt(0, 0.5, 3)T(0, )
Tau_resid <- pow(Sigma_resid, -2)
Lambda ~ dunif(-1, 1)
Eps ~ dexp(1)
NuMinus2 ~ dgamma(2, Eps)
Nu <- NuMinus2 + 2
LogC <- loggam((Nu + 1)/2) - 0.5*log(pi*(Nu - 2)) - loggam(Nu/2)
Cc <- exp(LogC)
Aconst <- 4*Lambda*Cc*(Nu - 2)/(Nu - 1)
B2 <- 1 + 3*pow(Lambda, 2) - pow(Aconst, 2)
Bconst <- sqrt(B2)
Kfac <- sqrt(Nu/(Nu - 2))
Knot <- -Aconst/Bconst
Mu_tau ~ dnorm(0, 0.001)
Sigma_tau ~ dt(0, 0.5, 3)T(0, )
Tau_tau <- pow(Sigma_tau, -2)
Mu_kappa ~ dnorm(0, 0.001)
Sigma_kappa ~ dt(0, 0.5, 3)T(0, )
Tau_kappa <- pow(Sigma_kappa, -2)
Phi0 <- 1/sqrt(2*pi)
KappaSwitch <- 1.0E-4
for (i in 1:N) {
v[i, 1:3] ~ dmnorm(Beta_RE_bar[1:3], Prec_RE[,])
Alpha0[i] <- v[i, 1]
Beta1[i] <- v[i, 2]
Beta2[i] <- v[i, 3]
Tau[i] ~ dnorm(Mu_tau, Tau_tau)T(0, TauMax)
Kappa[i] ~ dnorm(Mu_kappa, Tau_kappa)T(0, )
}
for (n in 1:Ntotal) {
DeltaT[n] <- Month[n] - Tau[Id[n]]
Delta0[n] <- -Tau[Id[n]]
Zk[n] <- Kappa[Id[n]]*DeltaT[n]
Zk0[n] <- Kappa[Id[n]]*Delta0[n]
PhiZ[n] <- pnorm(Zk[n], 0, 1)
PhiZ0[n] <- pnorm(Zk0[n], 0, 1)
phiZ[n] <- dnorm(Zk[n], 0, 1)
phiZ0[n] <- dnorm(Zk0[n], 0, 1)
HingeExact[n] <- DeltaT[n]*PhiZ[n] + phiZ[n]/Kappa[Id[n]]
Hinge0Exact[n] <- Delta0[n]*PhiZ0[n] + phiZ0[n]/Kappa[Id[n]]
CenteredHingeExact[n] <- HingeExact[n] - Hinge0Exact[n]
CenteredHingeApprox[n] <- 0.5*Month[n] +
0.5*Phi0*Kappa[Id[n]]*(pow(DeltaT[n], 2) - pow(Delta0[n], 2))
UseApprox[n] <- step(KappaSwitch - Kappa[Id[n]])
CenteredHinge[n] <- UseApprox[n]*CenteredHingeApprox[n] +
(1 - UseApprox[n])*CenteredHingeExact[n]
Mu[n] <- Alpha0[Id[n]] + Beta1[Id[n]]*Month[n] +
Beta2[Id[n]]*CenteredHinge[n]
Z[n] <- (Y[n] - Mu[n])/Sigma_resid
Zup[n] <- (Upper[n] - Mu[n])/Sigma_resid
Ztilde[n] <- Bconst*Z[n] + Aconst
ZtildeUp[n] <- Bconst*Zup[n] + Aconst
Left[n] <- step(Knot - Z[n])
Right[n] <- 1 - Left[n]
BaseL[n] <- 1 + pow(Ztilde[n]/(1 - Lambda), 2)/(Nu - 2)
BaseR[n] <- 1 + pow(Ztilde[n]/(1 + Lambda), 2)/(Nu - 2)
PartL[n] <- Left[n]*(Bconst*Cc)*pow(BaseL[n], -(Nu + 1)/2)
PartR[n] <- Right[n]*(Bconst*Cc)*pow(BaseR[n], -(Nu + 1)/2)
PDFstd[n] <- PartL[n] + PartR[n]
PDF[n] <- PDFstd[n]/Sigma_resid
LeftUp[n] <- step(Knot - Zup[n])
RightUp[n] <- 1 - LeftUp[n]
tL_up[n] <- (ZtildeUp[n]/(1 - Lambda))*Kfac
tR_up[n] <- (-ZtildeUp[n]/(1 + Lambda))*Kfac
CDF_left_up[n] <- (1 - Lambda)*pt(tL_up[n], 0, 1, Nu)
CDF_right_up[n] <- 1 - (1 + Lambda)*pt(tR_up[n], 0, 1, Nu)
CDFstd_up[n] <- LeftUp[n]*CDF_left_up[n] + RightUp[n]*CDF_right_up[n]
CDF[n] <- CDFstd_up[n]
Like[n] <- pow(PDF[n], Censor[n])*pow(CDF[n], 1 - Censor[n])
p[n] <- Like[n]/C
Ones[n] ~ dbern(p[n])
}
}We consider two equations for \(\mu\):
\[y_i\sim N(\beta_0+\beta_1(x_i-\gamma)I(x_i>\gamma)+\beta_2(x_i-\gamma)I(x_i<\gamma),\ \sigma^2)\]
To obtain a differentiable version, we work with the smooth hinge
\[ h_{\kappa}\left(x\right) = x \Phi\left(\kappa x\right) + \frac{\phi\left(\kappa x\right)}{\kappa}, \qquad \kappa > 0, \]
which is continuous and differentiable, with derivative \(h_{\kappa}'\left(x\right) = \Phi\left(\kappa x\right)\), where \(\Phi\) and \(\phi\) denote the standard normal cumulative distribution function (CDF) and density, respectively. For large \(\kappa\), \(h_{\kappa}\left(x\right)\) is close to the hard hinge \(x^{+} = \max\left(x,0\right)\); for small \(\kappa\), the bend is gradual and spans a wider time interval around \(x = 0\).
The observed outcome is \(Y_{ijk}\), with conditional mean for \(k = 1,\ldots,n_{ij}\):
\[ \mu_{ijk} = \alpha_{0ij} + \beta_{1ij} t_{ijk} + \beta_{2ij} \left\{h_{\kappa_{ij}}\left(t_{ijk} - \tau_{ij}\right) - h_{\kappa_{ij}}\left(-\tau_{ij}\right)\right\}, \] where \(\tau_{ij}\) is a subject-specific changepoint and \(\kappa_{ij} > 0\) controls the smoothness of the transition.
The instantaneous slope with respect to \(t\) is
\[ \frac{d \mu_{ij}\left(t\right)}{d t} = \beta_{1ij} + \beta_{2ij} \Phi\left(\kappa_{ij}\left(t - \tau_{ij}\right)\right), \] which transitions smoothly from \(\beta_{1ij}\) for \(t \ll \tau_{ij}\) to \(\beta_{1ij} + \beta_{2ij}\) for \(t \gg \tau_{ij}\).
The parameter \(\beta_{1ij}\) is the initial slope before the gate, and \(\beta_{1ij} + \beta_{2ij}\) is the long-term slope after the gate.
The subject-specific smoothness parameter \(\kappa_{ij}\) controls how quickly the slope changes; a larger \(\kappa_{ij}\) means a sharper bend, and a smaller \(\kappa_{ij}\) means a slower bend over time.
Conditional on the mean trajectory, the outcome follows an error distribution:
\[ Y_{ijk} \left| \mu_{ijk}, \boldsymbol{\theta}_j \right. \sim f_{\varepsilon}\left(y; \mu_{ijk}, \boldsymbol{\theta}_j\right), \]
where \(\boldsymbol{\theta}_j\) collects dispersion, skewness, and tail-thickness parameters for treatment group \(j\), and the parameterization of \(f_{\varepsilon}\) ensures \(E\left(\varepsilon_{ijk}\right) = 0\) for \(\varepsilon_{ijk} = Y_{ijk} - \mu_{ijk}\). Examples include Gaussian, Student-\(t\), and skew-\(t\) families, parameterized so that \(E\left(\varepsilon_{ijk}\right) = 0\); allowing heavy-tailed residuals in nonlinear mixed-effects models is standard practice, e.g. Davidian and Giltinan (1995) Davidian and Giltinan (2003). In the Bayesian implementation for ACTG~315 we take \(f_{\varepsilon}\) to be a skew-\(t\) density.
To enable accurate calculation of predictive quantities we must be able to simulate from the posterior predictive distribution.
A simulation function for the residual distribution is created, which can then be applied for each combination of posterior vectors and new data matrices to arrive as predictions for any quantity of interest.
In this study the residual distribution used comes from Hansen (1994) (https://www.jstor.org/stable/2527081).
When building models, ask yourself whether you are trying to model or predict, then ask yourself whether you are trying to model or predict
Consider an ordinary normal regression on the log scale. What happens when you transform back? Are you still modelling the mean?
For illustration we consider a few subjects.
Subject 1 had few points and then dropped out so produced wide intervals.
Subject 2 did not follow the model pattern so produced even wider intervals which barely accommodate the observed pattern.
Subject 8 fitted the expected data pattern nearly perfectly, showing neat alignment and smaller intervals.
Subject 9 is extra, pun intended π
The real data curves are smooth, not kinky, so we smooth out the kink in 3 ways β¦
This presentation was created using the Reveal.js format in Quarto, using the RStudio IDE. Font and line colours according to UFS branding, and background image using image editor GIMP by compositing images from CoPilot.
| Model | ParameterName | Median | Lower95 | Upper95 | Rhat |
|---|---|---|---|---|---|
| Abrupt | \(\beta_{1,1}\) | -3.764 | -4.104 | -3.448 | 1.004 |
| Smooth | \(\beta_{1,1}\) | -4.659 | -5.656 | -4.085 | 1.040 |
| Abrupt | \(\beta_{2,1}\) | 3.498 | 3.166 | 3.841 | 1.004 |
| Smooth | \(\beta_{2,1}\) | 4.522 | 3.908 | 5.542 | 1.039 |
| Abrupt | \(\Lambda_{1}\) | 0.252 | 0.000 | 0.485 | 1.000 |
| Smooth | \(\Lambda_{1}\) | 0.212 | -0.033 | 0.451 | 1.000 |
| Abrupt | \(\nu_{1}\) | 2.320 | 2.049 | 3.138 | 1.000 |
| Smooth | \(\nu_{1}\) | 2.552 | 2.078 | 3.863 | 1.000 |
| Abrupt | \(\sigma_{1}\) | 0.624 | 0.410 | 1.448 | 1.001 |
| Smooth | \(\sigma_{1}\) | 0.461 | 0.330 | 1.048 | 1.003 |
| Abrupt | \(L_{1,11}\) | 2.316 | 1.601 | 10.667 | 1.019 |
| Smooth | \(L_{1,11}\) | 2.841 | 1.708 | 12.595 | 1.028 |
| Abrupt | \(L_{1,21}\) | -0.241 | -30.211 | 22.713 | 1.011 |
| Smooth | \(L_{1,21}\) | 1.948 | -27.815 | 35.707 | 1.009 |
| Abrupt | \(L_{1,22}\) | 4.682 | 2.602 | 23.693 | 1.066 |
| Smooth | \(L_{1,22}\) | 5.306 | 2.355 | 29.102 | 1.040 |
| Abrupt | \(L_{1,31}\) | 0.625 | -16.788 | 28.243 | 1.013 |
| Smooth | \(L_{1,31}\) | -0.441 | -30.432 | 19.287 | 1.015 |
| Abrupt | \(L_{1,32}\) | 1.607 | -14.172 | 6.671 | 1.009 |
| Smooth | \(L_{1,32}\) | 0.444 | -17.068 | 7.551 | 1.010 |
| Abrupt | \(L_{1,33}\) | 2.537 | 1.053 | 11.765 | 1.033 |
| Smooth | \(L_{1,33}\) | 2.559 | 1.098 | 11.706 | 1.009 |
| Abrupt | Beta_RE_bar[1] | 5.094 | 4.912 | 5.275 | 1.000 |
| Smooth | Beta_RE_bar[1] | 5.098 | 4.922 | 5.274 | 1.001 |
| Smooth | Mu_kappa | 3.636 | -12.426 | 7.010 | 1.018 |
| Abrupt | Mu_tau | 0.529 | 0.467 | 0.592 | 1.002 |
| Smooth | Mu_tau | 0.440 | 0.329 | 0.519 | 1.029 |
| Smooth | Sigma_kappa | 3.440 | 1.222 | 13.398 | 1.013 |
| Abrupt | Sigma_tau | 0.099 | 0.034 | 0.154 | 1.000 |
| Smooth | Sigma_tau | 0.092 | 0.042 | 0.148 | 1.001 |
2026/08/14 - Two slope