Hepatitis: a normal hierarchical model with measurement error (with measurement error)

This is the measurement-error version of the Hepatitis example, and it uses exactly the same data: the same 106 vaccinated children, their log anti-Hb titres in the 106-by-3 matrix Y (76 children measured three times, 30 twice, so 288 observed titres), the matching log measurement times in t, and the log titre at vaccination in the baseline covariate y0.

The regression structure is unchanged: each child has its own intercept $\alpha_i$ and slope $\beta_i$ against log time centred at 6.5, drawn from common population normals, and a single population coefficient $\gamma$ carries the effect of the baseline. What the measurement-error version adds is the recognition that y0 is a titre reading like any other, and therefore not the child's true baseline. A latent true baseline $\mu_{0i}$ is introduced for each child, the observed y0[i] is treated as a noisy reading of it with the same precision $\tau$ that governs the repeat titres, and the regression uses $\mu_{0i}$ in place of y0[i]. The latent baselines are themselves drawn from a population normal with mean $\theta$ and precision $\psi$, both estimated.

\[\begin{aligned} Y_{ij} &\sim \text{Normal}\left(\alpha_i + \beta_i (t_{ij} - 6.5) + \gamma\,(\mu_{0i} - \bar{y}_0),\ \tau\right) \\ y_{0i} &\sim \text{Normal}(\mu_{0i}, \tau), \qquad \mu_{0i} \sim \text{Normal}(\theta, \psi) \end{aligned}\]

As elsewhere in BUGS the second argument of dnorm is a precision rather than a variance. The centring term $\bar{y}_0$ is still the mean of the observed baselines, so only the covariate value itself becomes latent. The consequence is the classic one: regressing on a covariate measured with error attenuates its coefficient, and correcting for the error pulls $\gamma$ away from zero. The bundled reference summaries make this visible, with $\gamma$ near 0.67 in the basic model and near 1.08 here, while the growth-curve parameters $\alpha_0$ and $\beta_0$ barely move. This example is part of Volume 3 of the classic BUGS examples; see the MultiBUGS examples page and the OpenBUGS Hepatitis page, where this model appears under "With measurement error".

The model definition, data, initial values, and published reference results shown here all come from JuliaBUGS.BUGSExamples.VOLUME_3.hepatitis_me, which ships with the package.

Model

using JuliaBUGS

example = JuliaBUGS.BUGSExamples.VOLUME_3.hepatitis_me
example.model_def
quote
    var"tau.alpha" ~ dgamma(0.001, 0.001)
    alpha0 ~ dnorm(0.0, 1.0e-6)
    beta0 ~ dnorm(0.0, 1.0e-6)
    var"tau.beta" ~ dgamma(0.001, 0.001)
    for i = 1:N
        alpha[i] ~ dnorm(alpha0, var"tau.alpha")
        beta[i] ~ dnorm(beta0, var"tau.beta")
        y0[i] ~ dnorm(mu0[i], tau)
        mu0[i] ~ dnorm(theta, psi)
    end
    for j = 1:T
        for i = 1:N
            Y[i, j] ~ dnorm(mu[i, j], tau)
            mu[i, j] = alpha[i] + beta[i] * (t[i, j] - 6.5) + gamma * (mu0[i] - mean(y0[:]))
        end
    end
    tau ~ dgamma(0.001, 0.001)
    sigma = 1 / sqrt(tau)
    gamma ~ dnorm(0.0, 1.0e-6)
    theta ~ dnorm(0.0, 1.0e-6)
    psi ~ dgamma(0.001, 0.001)
end

The program as it appears in the original BUGS distribution:

print(example.original_syntax_program)
model
{
    tau.alpha ~ dgamma(0.001, 0.001)
    alpha0 ~ dnorm(0.0, 1.0E-6)
    beta0 ~ dnorm(0.0, 1.0E-6)
    tau.beta ~ dgamma(0.001, 0.001)
    for(i in 1:N) {
        alpha[i] ~ dnorm(alpha0, tau.alpha)
        beta[i] ~ dnorm(beta0, tau.beta)
        y0[i] ~ dnorm(mu0[i], tau)
        mu0[i] ~ dnorm(theta, psi)
    }
    for(j in 1:T) {
        for(i in 1:N) {
            Y[i, j] ~ dnorm(mu[i, j], tau)
            mu[i, j] <- alpha[i] + beta[i] * (t[i, j] - 6.5) +
                gamma * (mu0[i] - mean(y0[]))
        }
    }
    tau ~ dgamma(0.001, 0.001)
    sigma <- 1 / sqrt(tau)
    gamma ~ dnorm(0.0, 1.0E-6)
    theta ~ dnorm(0.0, 1.0E-6)
    psi ~ dgamma(0.001, 0.001)
}

Data

example.data
(N = 106, T = 3, Y = Union{Missing, Float64}[4.997 8.028 missing; 6.83 4.905 6.295; … ; 7.07326971745971 7.12608727329912 5.01063529409626; 9.08636319215647 7.9359451033537 missing], t = [6.541 6.963 10.0; 5.8406416573734 6.52941883826223 6.98193467715639; … ; 5.8171111599632 6.51174532964473 6.93634273583405; 5.85793315448346 6.92264389147589 10.0], y0 = [8.613, 7.105, 6.896, 5.63835466933375, 6.35088571671474, 5.03043792139244, 5.8664680569333, 5.73979291217923, 7.07834157955767, 8.56655462095396  …  7.58984151218266, 6.39024066706535, 6.04025471127741, 2.77258872223978, 7.62948991639399, 7.85476918349913, 7.09007683577609, 5.50125821054473, 6.98100574072173, 5.50533153593236])

Compiling the model

model = JuliaBUGS.compile(example.model_def, example.data, example.inits)
BUGSModel (parameters are in transformed (unconstrained) space, with dimension 326):

  Model parameters:
    alpha[1], alpha[2], alpha[3], alpha[4], alpha[5], alpha[6], alpha[7], alpha[8], alpha[9], alpha[10], alpha[11], alpha[12], alpha[13], alpha[14], alpha[15], alpha[16], alpha[17], alpha[18], alpha[19], alpha[20], alpha[21], alpha[22], alpha[23], alpha[24], alpha[25], alpha[26], alpha[27], alpha[28], alpha[29], alpha[30], alpha[31], alpha[32], alpha[33], alpha[34], alpha[35], alpha[36], alpha[37], alpha[38], alpha[39], alpha[40], alpha[41], alpha[42], alpha[43], alpha[44], alpha[45], alpha[46], alpha[47], alpha[48], alpha[49], alpha[50], alpha[51], alpha[52], alpha[53], alpha[54], alpha[55], alpha[56], alpha[57], alpha[58], alpha[59], alpha[60], alpha[61], alpha[62], alpha[63], alpha[64], alpha[65], alpha[66], alpha[67], alpha[68], alpha[69], alpha[70], alpha[71], alpha[72], alpha[73], alpha[74], alpha[75], alpha[76], alpha[77], alpha[78], alpha[79], alpha[80], alpha[81], alpha[82], alpha[83], alpha[84], alpha[85], alpha[86], alpha[87], alpha[88], alpha[89], alpha[90], alpha[91], alpha[92], alpha[93], alpha[94], alpha[95], alpha[96], alpha[97], alpha[98], alpha[99], alpha[100], alpha[101], alpha[102], alpha[103], alpha[104], alpha[105], alpha[106]
    gamma
    tau.alpha
    beta0
    psi
    alpha0
    mu0[106], mu0[105], mu0[104], mu0[103], mu0[102], mu0[101], mu0[100], mu0[99], mu0[98], mu0[97], mu0[96], mu0[95], mu0[94], mu0[93], mu0[92], mu0[91], mu0[90], mu0[89], mu0[88], mu0[87], mu0[86], mu0[85], mu0[84], mu0[83], mu0[82], mu0[81], mu0[80], mu0[79], mu0[78], mu0[77], mu0[76], mu0[75], mu0[74], mu0[73], mu0[72], mu0[71], mu0[70], mu0[69], mu0[68], mu0[67], mu0[66], mu0[65], mu0[64], mu0[63], mu0[62], mu0[61], mu0[60], mu0[59], mu0[58], mu0[57], mu0[56], mu0[55], mu0[54], mu0[53], mu0[52], mu0[51], mu0[50], mu0[49], mu0[48], mu0[47], mu0[46], mu0[45], mu0[44], mu0[43], mu0[42], mu0[41], mu0[40], mu0[39], mu0[38], mu0[37], mu0[36], mu0[35], mu0[34], mu0[33], mu0[32], mu0[31], mu0[30], mu0[29], mu0[28], mu0[27], mu0[26], mu0[25], mu0[24], mu0[23], mu0[22], mu0[21], mu0[20], mu0[19], mu0[18], mu0[17], mu0[16], mu0[15], mu0[14], mu0[13], mu0[12], mu0[11], mu0[10], mu0[9], mu0[8], mu0[7], mu0[6], mu0[5], mu0[4], mu0[3], mu0[2], mu0[1]
    tau.beta
    Y[1, 3], Y[3, 3], Y[7, 3], Y[8, 3], Y[10, 3], Y[18, 3], Y[20, 3], Y[21, 3], Y[32, 3], Y[34, 3], Y[41, 3], Y[42, 3], Y[46, 3], Y[50, 3], Y[54, 3], Y[63, 3], Y[64, 3], Y[70, 3], Y[71, 3], Y[77, 3], Y[78, 3], Y[80, 3], Y[83, 3], Y[85, 3], Y[88, 3], Y[89, 3], Y[96, 3], Y[103, 3], Y[104, 3], Y[106, 3]
    tau
    beta[1], beta[2], beta[3], beta[4], beta[5], beta[6], beta[7], beta[8], beta[9], beta[10], beta[11], beta[12], beta[13], beta[14], beta[15], beta[16], beta[17], beta[18], beta[19], beta[20], beta[21], beta[22], beta[23], beta[24], beta[25], beta[26], beta[27], beta[28], beta[29], beta[30], beta[31], beta[32], beta[33], beta[34], beta[35], beta[36], beta[37], beta[38], beta[39], beta[40], beta[41], beta[42], beta[43], beta[44], beta[45], beta[46], beta[47], beta[48], beta[49], beta[50], beta[51], beta[52], beta[53], beta[54], beta[55], beta[56], beta[57], beta[58], beta[59], beta[60], beta[61], beta[62], beta[63], beta[64], beta[65], beta[66], beta[67], beta[68], beta[69], beta[70], beta[71], beta[72], beta[73], beta[74], beta[75], beta[76], beta[77], beta[78], beta[79], beta[80], beta[81], beta[82], beta[83], beta[84], beta[85], beta[86], beta[87], beta[88], beta[89], beta[90], beta[91], beta[92], beta[93], beta[94], beta[95], beta[96], beta[97], beta[98], beta[99], beta[100], beta[101], beta[102], beta[103], beta[104], beta[105], beta[106]
    theta

  Variable sizes and types:
    alpha: size = (106,), type = Vector{Float64}
    gamma: type = Float64
    tau.alpha: type = Float64
    beta0: type = Float64
    y0: size = (106,), type = Vector{Float64}
    sigma: type = Float64
    alpha0: type = Float64
    psi: type = Float64
    N: type = Int64
    mu0: size = (106,), type = Vector{Float64}
    mu: size = (106, 3), type = Matrix{Float64}
    tau.beta: type = Float64
    Y: size = (106, 3), type = Matrix{Float64}
    tau: type = Float64
    T: type = Int64
    beta: size = (106,), type = Vector{Float64}
    theta: type = Float64
    t: size = (106, 3), type = Matrix{Float64}

The example's own initial values are passed in here. Several of these models fail from random starting values, so example.inits is not optional in practice; a second set is available as example.inits_alternative.

See Getting Started for the recipe that takes a compiled model to posterior samples.

Reference results

The posterior summaries published with the original example. A converged chain should reproduce these up to Monte Carlo error.

example.reference_results
(alpha0 = (mean = 6.153, std = 0.1669), beta0 = (mean = -1.056, std = 0.1194), gamma = (mean = 1.075, std = 0.2103), sigma = (mean = 1.026, std = 0.06469))