Orange Trees: Non-linear growth curve

This is the multivariate normal version of the Orange Trees example, and it uses the same data: the trunk circumference of $K = 5$ orange trees, each measured on the same $n = 7$ occasions at $x_j = 118, 484, 664, 1004, 1231, 1372$ and $1582$ days. The measurements grow from around 30 at the first occasion to between 140 and 214 at the last, with the trees differing in both their eventual size and how quickly they approach it.

The likelihood is unchanged. Each observation is normal about a logistic growth curve with tree-specific parameters, written on an unconstrained scale so that the asymptote stays positive and the rate constant negative:

\[\begin{aligned} Y_{ij} &\sim \text{Normal}(\eta_{ij}, \tau_C) \\ \eta_{ij} &= \frac{\phi_{i1}}{1 + \phi_{i2} \exp(\phi_{i3} x_j)} \\ \phi_{i1} &= \exp(\theta_{i1}), \quad \phi_{i2} = \exp(\theta_{i2}) - 1, \quad \phi_{i3} = -\exp(\theta_{i3}) \end{aligned}\]

What changes is the prior on the tree-level parameters. Instead of three independent univariate normals, the vector $\theta_{i,1:3}$ is drawn from a single trivariate normal, $\theta_{i,1:3} \sim \text{MVN}(\mu, \tau)$, so the model can learn that a tree with a large asymptote also tends to have, say, a particular growth rate rather than treating the three coordinates as unrelated. Following the BUGS convention, dmnorm takes a precision matrix rather than a covariance matrix, so the 3-by-3 matrix the program calls tau is the inverse covariance of the random effects, not their covariance. It is given a Wishart prior, dwish(R, 3) with $R = 0.1 I$ and 3 degrees of freedom, the smallest value admissible for a 3-by-3 matrix and hence the vaguest choice available in this family. The mean vector $\mu$ gets a multivariate normal prior with zero mean and precision $10^{-6} I$, and the residual precision $\tau_C$ a vague gamma prior. The covariance matrix sigma2 is recovered by inverting tau, and sigma[i] is the square root of its $i$th diagonal element.

The example appears 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.orange_trees_multivariate, which ships with the package.

Model

using JuliaBUGS

example = JuliaBUGS.BUGSExamples.VOLUME_2.orange_trees_multivariate
example.model_def
quote
    for i = 1:K
        for j = 1:n
            Y[i, j] ~ dnorm(eta[i, j], tauC)
            eta[i, j] = phi[i, 1] / (1 + phi[i, 2] * exp(phi[i, 3] * x[j]))
        end
        phi[i, 1] = exp(theta[i, 1])
        phi[i, 2] = exp(theta[i, 2]) - 1
        phi[i, 3] = -(exp(theta[i, 3]))
        theta[i, 1:3] ~ dmnorm(mu[1:3], tau[1:3, 1:3])
    end
    mu[1:3] ~ dmnorm(mean[1:3], prec[1:3, 1:3])
    tau[1:3, 1:3] ~ dwish(R[1:3, 1:3], 3)
    sigma2[1:3, 1:3] = inverse(tau[1:3, 1:3])
    for i = 1:3
        sigma[i] = sqrt(sigma2[i, i])
    end
    tauC ~ dgamma(0.001, 0.001)
    sigmaC = 1 / sqrt(tauC)
end

The program as it appears in the original BUGS distribution:

print(example.original_syntax_program)
model {
    for (i in 1:K) {
        for (j in 1:n) {
            Y[i, j] ~ dnorm(eta[i, j], tauC)
            eta[i, j] <- phi[i, 1] / (1 + phi[i, 2] * exp(phi[i, 3] * x[j]))
        }
        phi[i, 1] <- exp(theta[i, 1])
        phi[i, 2] <- exp(theta[i, 2]) - 1
        phi[i, 3] <- -exp(theta[i, 3])
        theta[i, 1:3] ~ dmnorm(mu[1:3], tau[1:3, 1:3])
    }
    mu[1:3] ~ dmnorm(mean[1:3], prec[1:3, 1:3])
    tau[1:3, 1:3] ~ dwish(R[1:3, 1:3], 3)
    sigma2[1:3, 1:3] <- inverse(tau[1:3, 1:3])
    for (i in 1 : 3) {sigma[i] <- sqrt(sigma2[i, i]) }
    tauC ~ dgamma(1.0E-3, 1.0E-3)
    sigmaC <- 1 / sqrt(tauC)
}

Data

example.data
(n = 7, K = 5, x = [118.0, 484.0, 664.0, 1004.0, 1231.0, 1372.0, 1582.0], Y = [30.0 58.0 … 142.0 145.0; 33.0 69.0 … 203.0 203.0; … ; 32.0 62.0 … 209.0 214.0; 30.0 49.0 … 174.0 177.0], mean = [0, 0, 0], R = [0.1 0.0 0.0; 0.0 0.1 0.0; 0.0 0.0 0.1], prec = [1.0e-6 0.0 0.0; 0.0 1.0e-6 0.0; 0.0 0.0 1.0e-6])

Compiling the model

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

  Model parameters:
    mu[1:3]
    tauC
    theta[5, 1:3], theta[4, 1:3], theta[3, 1:3], theta[2, 1:3], theta[1, 1:3]
    tau[1:3, 1:3]

  Variable sizes and types:
    n: type = Int64
    prec: size = (3, 3), type = Matrix{Float64}
    eta: size = (5, 7), type = Matrix{Float64}
    K: type = Int64
    phi: size = (5, 3), type = Matrix{Float64}
    sigma2: size = (3, 3), type = Matrix{Float64}
    sigma: size = (3,), type = Vector{Float64}
    x: size = (7,), type = Vector{Float64}
    R: size = (3, 3), type = Matrix{Float64}
    mean: size = (3,), type = Vector{Int64}
    mu: size = (3,), type = Vector{Float64}
    Y: size = (5, 7), type = Matrix{Float64}
    sigmaC: type = Float64
    tau: size = (3, 3), type = Matrix{Float64}
    tauC: type = Int64
    theta: size = (5, 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
(var"mu[1]" = (mean = 5.266, std = 0.1363), var"mu[2]" = (mean = 2.196, std = 0.1629), var"mu[3]" = (mean = -5.885, std = 0.1421), var"sigma[1]" = (mean = 0.2587, std = 0.1145), var"sigma[2]" = (mean = 0.2636, std = 0.1282), var"sigma[3]" = (mean = 0.2302, std = 0.1073), sigmaC = (mean = 7.902, std = 1.207))