Beetles: choice of link function
This is a dose-response experiment on beetles, reported by Bliss (1935) and later analysed by Dobson (1983). Eight groups, between 56 and 63 insects each and 481 in total, were exposed to carbon disulphide for five hours at eight increasing concentrations, recorded on a log scale from 1.6907 up to 1.8839. The recorded outcome for each group is simply how many of the exposed beetles died: 6 of 59 at the lowest dose, rising to 60 of 60 at the highest. The question is what dose-response curve describes the kill rate, and the data are unusually informative about that because they span almost the whole range from very few deaths to complete mortality.
The counts are binomial, and the interest of the example is the choice of link function connecting the death probability to dose. The model as shipped uses the logistic link, with the two alternatives the original example compares against, the probit and the complementary log-log, left in place as comments that can be swapped in:
\[r_i \sim \text{Binomial}(p_i,\ n_i), \qquad \text{logit}(p_i) = \alpha^{*} + \beta \, (x_i - \bar{x})\]
Doses are centred at their mean, $\bar{x} \approx 1.793$, which decorrelates the intercept from the slope and makes the sampler's job much easier; the intercept on the original dose scale is then recovered as $\alpha = \alpha^{*} - \beta \bar{x}$. Both $\alpha^{*}$ and $\beta$ get vague normal priors with precision 0.001, the BUGS normal being parameterised by precision rather than variance. The quantity rhat[i] is the fitted expected number of deaths in group $i$, and comparing it group by group with the observed r[i] is how the three links are judged against each other. Note that in JuliaBUGS the link is written as an inverse-link function on the right-hand side, logistic(...) rather than BUGS's logit(p[i]) <- ..., with phi and cexpexp playing the same role for the other two.
The reference results bundled with the package are those for the logistic link; the source file also carries the published probit and complementary log-log summaries as comments. See Volume 2 of the classic BUGS examples and the OpenBUGS Beetles page.
The model definition, data, initial values, and published reference results shown here all come from JuliaBUGS.BUGSExamples.VOLUME_2.beetles, which ships with the package.
Model
using JuliaBUGS
example = JuliaBUGS.BUGSExamples.VOLUME_2.beetles
example.model_defquote
for i = 1:N
r[i] ~ dbin(p[i], n[i])
p[i] = logistic(var"alpha.star" + beta * (x[i] - mean(x[:])))
rhat[i] = n[i] * p[i]
end
alpha = var"alpha.star" - beta * mean(x[:])
beta ~ dnorm(0.0, 0.001)
var"alpha.star" ~ dnorm(0.0, 0.001)
endThe program as it appears in the original BUGS distribution:
print(example.original_syntax_program)model {
for( i in 1 : N ) {
r[i] ~ dbin(p[i],n[i])
logit(p[i]) <- alpha.star + beta * (x[i] - mean(x[]))
# probit(p[i]) <- alpha.star + beta * (x[i] - mean(x[]))
# cexpexp(p[i]) <- alpha.star + beta * (x[i] - mean(x[]))
rhat[i] <- n[i] * p[i]
}
alpha <- alpha.star - beta * mean(x[])
beta ~ dnorm(0.0,0.001)
alpha.star ~ dnorm(0.0,0.001)
}Data
example.data(x = [1.6907, 1.7242, 1.7552, 1.7842, 1.8113, 1.8369, 1.861, 1.8839], n = [59, 60, 62, 56, 63, 59, 62, 60], r = [6, 13, 18, 28, 52, 53, 61, 60], N = 8)Compiling the model
model = JuliaBUGS.compile(example.model_def, example.data, example.inits)BUGSModel (parameters are in transformed (unconstrained) space, with dimension 2):
Model parameters:
beta
alpha.star
Variable sizes and types:
alpha: type = Float64
N: type = Int64
beta: type = Int64
n: size = (8,), type = Vector{Int64}
p: size = (8,), type = Vector{Float64}
rhat: size = (8,), type = Vector{Float64}
alpha.star: type = Int64
r: size = (8,), type = Vector{Int64}
x: size = (8,), 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(alpha = (mean = -60.78, std = 5.168), beta = (mean = 34.3, std = 2.904), var"rhat[1]" = (mean = 3.571, std = 0.957), var"rhat[2]" = (mean = 9.955, std = 1.691), var"rhat[3]" = (mean = 22.51, std = 2.115), var"rhat[4]" = (mean = 33.9, std = 1.768), var"rhat[5]" = (mean = 50.04, std = 1.655), var"rhat[6]" = (mean = 53.21, std = 1.108), var"rhat[7]" = (mean = 59.14, std = 0.7393), var"rhat[8]" = (mean = 58.68, std = 0.4284))