Hearts: a mixture model for count data

This example uses data reported by Berry (1987) on 12 patients treated with a drug for frequent premature ventricular contractions (PVCs) of the heart. For each patient the data give the PVC count recorded before the drug was administered, x, and the count recorded afterwards, y. The pre-drug counts range from 5 to 51, and seven of the twelve patients recorded no PVCs at all after treatment. The question is how much the drug reduces the PVC rate, and in particular whether it suppresses the contractions entirely in some patients rather than merely lowering the rate in all of them.

Following Farewell and Sprott (1988), the counts are treated as coming from two kinds of patient: those in whom the drug has suppressed the contractions altogether, and those whose rate it has merely reduced by some amount. Conditioning each patient's post-drug count on the total $t_i = x_i + y_i$ eliminates the patient-specific Poisson rates and leaves a binomial likelihood, which is what the model codes. The awkwardness is that the two kinds of patient cannot be told apart from the data alone. An observed zero is equally consistent with complete suppression and with a rate that is merely low and happened to yield nothing over the observation period, so which group a patient belongs to has to be inferred rather than read off. The indicator state[i], written $s_i$ below, says which mixture component patient $i$ belongs to, selecting a success probability of $p$ when it is 0 and of exactly 0 when it is 1.

\[\begin{aligned} y_i &\sim \text{Binomial}(P_{s_i + 1},\ t_i), \qquad t_i = x_i + y_i \\ s_i &\sim \text{Bernoulli}(\theta) \\ P_1 &= p, \qquad P_2 = 0 \\ \text{logit}(p) &= \alpha, \qquad \text{logit}(\theta) = \delta \end{aligned}\]

Both $\alpha$ and $\delta$ are given vague $\text{Normal}(0, 10^{-4})$ priors, where the second argument is a precision in the BUGS convention, so a standard deviation of 100 on the logit scale. The derived quantity $\beta = \exp(\alpha)$ is the ratio of the post-drug to the pre-drug PVC rate among uncured patients, and $\theta$ is the probability of a cure. Note that state[i] is a discrete latent variable, so a gradient-based sampler cannot update it directly; it has to be summed out, or updated by a sampler that supports discrete parameters. 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.hearts, which ships with the package.

Model

using JuliaBUGS

example = JuliaBUGS.BUGSExamples.VOLUME_2.hearts
example.model_def
quote
    for i = 1:N
        y[i] ~ dbin(P[state1[i]], t[i])
        state[i] ~ dbern(theta)
        state1[i] = state[i] + 1
        t[i] = x[i] + y[i]
        prop[i] = P[state1[i]]
    end
    P[1] = p
    P[2] = 0
    p = logistic(alpha)
    alpha ~ dnorm(0, 0.0001)
    beta = exp(alpha)
    theta = logistic(delta)
    delta ~ dnorm(0, 0.0001)
end

The program as it appears in the original BUGS distribution:

print(example.original_syntax_program)
model
{
   for (i in 1 : N) {
      y[i] ~ dbin(P[state1[i]], t[i])
      state[i] ~ dbern(theta)
      state1[i] <- state[i] + 1
      t[i] <- x[i] + y[i]
      prop[i] <- P[state1[i]]
   }
   P[1] <- p
   P[2] <- 0
   logit(p) <- alpha
   alpha ~ dnorm(0,1.0E-4)
   beta <- exp(alpha)
   logit(theta) <- delta
   delta ~ dnorm(0, 1.0E-4)
}

Data

example.data
(x = [6, 9, 17, 22, 7, 5, 5, 14, 9, 7, 9, 51], y = [5, 2, 0, 0, 2, 1, 0, 0, 0, 0, 13, 0], N = 12)

Compiling the model

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

  Model parameters:
    alpha
    state[12], state[11], state[10], state[9], state[8], state[7], state[6], state[5], state[4], state[3], state[2], state[1]
    delta

  Variable sizes and types:
    prop: size = (12,), type = Vector{Float64}
    alpha: type = Int64
    p: type = Float64
    state: size = (12,), type = Vector{Float64}
    delta: type = Int64
    x: size = (12,), type = Vector{Int64}
    N: type = Int64
    P: size = (2,), type = Vector{Float64}
    beta: type = Float64
    y: size = (12,), type = Vector{Int64}
    state1: size = (12,), type = Vector{Float64}
    theta: type = Float64
    t: size = (12,), type = Vector{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
(alpha = (mean = -0.4786, std = 0.2764), beta = (mean = 0.6434, std = 0.1777), delta = (mean = 0.3172, std = 0.6269), theta = (mean = 0.5721, std = 0.141))