Birats: a bivariate normal hierarchical model

This example returns to the Rats data, the 30 young rats whose weights were measured on five occasions at ages $x_j = 8, 15, 22, 29, 36$ days, and refits it with a multivariate population distribution for the growth-curve coefficients. In the univariate version each rat's intercept and slope are drawn from two separate normal distributions, which forces them to be independent a priori. Here the pair is drawn jointly from a bivariate normal, so the model can express a correlation between them: positive correlation would mean that rats which start out heavy also tend to gain weight faster. This is the model Gelfand et al. (1990) adopted for these data.

Each rat $i$ has a coefficient vector beta[i, 1:2] drawn from a bivariate normal with population mean mu.beta and population precision matrix R, and its five weights are normal about $\beta_{i1} + \beta_{i2} x_j$ with a common measurement precision tauC. The ages are not centred in this version, so $\beta_{i1}$ is the rat's intercept at age zero and mu.beta[1] is the population intercept at birth directly, the quantity that the Rats example has to construct as alpha0.

\[\begin{aligned} Y_{ij} &\sim \text{Normal}(\beta_{i1} + \beta_{i2} x_j,\ \tau_c) \\ \beta_i &\sim \text{MVNormal}(\mu_\beta,\ R) \\ \mu_\beta &\sim \text{MVNormal}(\text{mean},\ \text{prec}) \\ R &\sim \text{Wishart}(\Omega,\ 2) \end{aligned}\]

Following the BUGS convention, the second argument of every normal here is a precision rather than a variance or a covariance matrix. The population mean gets a vague bivariate normal prior with mean zero and precision $10^{-6} I$, and the population precision matrix R a Wishart prior with 2 degrees of freedom, the smallest value its rank allows, and scale matrix $\Omega = \text{diag}(200, 0.2)$, whose entries say only how widely intercepts and slopes are expected to range relative to each other. The measurement precision gets the usual vague $\text{Gamma}(0.001, 0.001)$, with sigma recording the implied standard deviation. Note that the names in this program differ from those in the original write-up's algebra: the code's R is the population precision matrix, and Omega is the Wishart scale matrix. This is one of the examples in Volume 2 of the classic BUGS examples; see also the OpenBUGS version of this example.

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

Model

using JuliaBUGS

example = JuliaBUGS.BUGSExamples.VOLUME_2.birats
example.model_def
quote
    for i = 1:N
        beta[i, 1:2] ~ dmnorm(var"mu.beta"[:], R[:, :])
        for j = 1:T
            Y[i, j] ~ dnorm(mu[i, j], tauC)
            mu[i, j] = beta[i, 1] + beta[i, 2] * x[j]
        end
    end
    var"mu.beta"[1:2] ~ dmnorm(mean[:], prec[:, :])
    R[1:2, 1:2] ~ dwish(Omega[:, :], 2)
    tauC ~ dgamma(0.001, 0.001)
    sigma = 1 / sqrt(tauC)
end

The program as it appears in the original BUGS distribution:

print(example.original_syntax_program)
model {
    for( i in 1 : N ) {
        beta[i , 1 : 2] ~ dmnorm(mu.beta[], R[ , ])
        for( j in 1 : T ) {
            Y[i, j] ~ dnorm(mu[i , j], tauC)
            mu[i, j] <- beta[i, 1] + beta[i, 2] * x[j]
        }
    }

    mu.beta[1 : 2] ~ dmnorm(mean[], prec[ , ])
    R[1 : 2 , 1 : 2] ~ dwish(Omega[ , ], 2)
    tauC ~ dgamma(0.001, 0.001)
    sigma <- 1 / sqrt(tauC)
}

Data

example.data
(x = [8.0, 15.0, 22.0, 29.0, 36.0], N = 30, T = 5, Omega = [200.0 0.0; 0.0 0.2], mean = [0, 0], prec = [1.0e-6 0.0; 0.0 1.0e-6], Y = [151 199 … 283 320; 145 199 … 293 354; … ; 137 180 … 258 291; 153 200 … 286 324])

Compiling the model

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

  Model parameters:
    R[1:2, 1:2]
    beta[30, 1:2], beta[29, 1:2], beta[28, 1:2], beta[27, 1:2], beta[26, 1:2], beta[25, 1:2], beta[24, 1:2], beta[23, 1:2], beta[22, 1:2], beta[21, 1:2], beta[20, 1:2], beta[19, 1:2], beta[18, 1:2], beta[17, 1:2], beta[16, 1:2], beta[15, 1:2], beta[14, 1:2], beta[13, 1:2], beta[12, 1:2], beta[11, 1:2], beta[10, 1:2], beta[9, 1:2], beta[8, 1:2], beta[7, 1:2], beta[6, 1:2], beta[5, 1:2], beta[4, 1:2], beta[3, 1:2], beta[2, 1:2], beta[1, 1:2]
    mu.beta[1:2]
    tauC

  Variable sizes and types:
    mu.beta: size = (2,), type = Vector{Float64}
    prec: size = (2, 2), type = Matrix{Float64}
    Omega: size = (2, 2), type = Matrix{Float64}
    sigma: type = Float64
    x: size = (5,), type = Vector{Float64}
    N: type = Int64
    mean: size = (2,), type = Vector{Int64}
    R: size = (2, 2), type = Matrix{Float64}
    mu: size = (30, 5), type = Matrix{Float64}
    Y: size = (30, 5), type = Matrix{Int64}
    T: type = Int64
    beta: size = (30, 2), type = Matrix{Float64}
    tauC: type = Int64

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
(var"mu.beta[1:2][1]" = (mean = 106.6, std = 2.361), var"mu.beta[1:2][2]" = (mean = 6.185, std = 0.1063), sigma = (mean = 6.149, std = 0.4789))