Dugongs: nonlinear growth curve
This example is the nonconjugate analysis of Carlin and Gelfand (1991), working from a data set collected by Ratkowsky (1983). It pairs an age with a length for each of 27 dugongs, or sea cows. The ages $x_i$ run from 1 to 31.5 years and the lengths $Y_i$ from 1.77 to 2.72, one measurement of each per animal. Growth is clearly not linear: length rises quickly over the first few years and then flattens out, so the question is how to describe a curve that decelerates towards a maximum attainable size.
The curve chosen for the mean rises steadily without ever turning over, and levels off at a finite ceiling as the animals age. Each length is normal about a mean that approaches $\alpha$ geometrically, with $\beta$ the total growth from birth to that ceiling and $\gamma$ controlling how fast the curve gets there.
\[\begin{aligned} Y_i &\sim \text{Normal}(\mu_i, \tau), \qquad i = 1, \ldots, 27 \\ \mu_i &= \alpha - \beta \gamma^{x_i}, \qquad \alpha, \beta > 0, \; 0 < \gamma < 1 \end{aligned}\]
Here $\tau$ is the precision (inverse variance) of the normal, following the BUGS convention; the derived quantity sigma is $1/\sqrt{\tau}$. The prior on $\gamma$ is uniform on $(0.5, 1)$, with $\alpha$ and $\beta$ uniform on $(0, 100)$ and a vague gamma prior on $\tau$. The point of the example is that $\gamma$ enters the mean through an exponent, so its full conditional distribution is neither conjugate nor log-concave, which makes it a standard test case for samplers. The model also monitors $U_3 = \operatorname{logit}(\gamma)$, a transformation on which the posterior is better behaved.
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.dugongs, which ships with the package.
Model
using JuliaBUGS
example = JuliaBUGS.BUGSExamples.VOLUME_2.dugongs
example.model_defquote
for i = 1:N
Y[i] ~ dnorm(mu[i], tau)
mu[i] = alpha - beta * pow(gamma, x[i])
end
alpha ~ dunif(0, 100)
beta ~ dunif(0, 100)
gamma ~ dunif(0.5, 1.0)
tau ~ dgamma(0.001, 0.001)
sigma = 1 / sqrt(tau)
U3 = logit(gamma)
endThe program as it appears in the original BUGS distribution:
print(example.original_syntax_program)model {
for( i in 1 : N ) {
Y[i] ~ dnorm(mu[i], tau)
mu[i] <- alpha - beta * pow(gamma,x[i])
}
alpha ~ dunif(0, 100)
beta ~ dunif(0, 100)
gamma ~ dunif(0.5, 1.0)
tau ~ dgamma(0.001, 0.001)
sigma <- 1 / sqrt(tau)
U3 <- logit(gamma)
}Data
example.data(x = [1.0, 1.5, 1.5, 1.5, 2.5, 4.0, 5.0, 5.0, 7.0, 8.0 … 13.0, 13.0, 14.5, 15.5, 15.5, 16.5, 17.0, 22.5, 29.0, 31.5], Y = [1.8, 1.85, 1.87, 1.77, 2.02, 2.27, 2.15, 2.26, 2.47, 2.19 … 2.43, 2.47, 2.56, 2.65, 2.47, 2.64, 2.56, 2.7, 2.72, 2.57], N = 27)Compiling the model
model = JuliaBUGS.compile(example.model_def, example.data, example.inits)BUGSModel (parameters are in transformed (unconstrained) space, with dimension 4):
Model parameters:
alpha
beta
gamma
tau
Variable sizes and types:
alpha: type = Int64
N: type = Int64
beta: type = Int64
gamma: type = Float64
U3: type = Float64
mu: size = (27,), type = Vector{Float64}
Y: size = (27,), type = Vector{Float64}
sigma: type = Float64
tau: type = Int64
x: size = (27,), type = Vector{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(U3 = (mean = 1.866, std = 0.2873), alpha = (mean = 2.655, std = 0.07926), beta = (mean = 0.9751, std = 0.07952), gamma = (mean = 0.8626, std = 0.03457), sigma = (mean = 0.09917, std = 0.01503))