Could you please take a look at the following WinBUGs code from WinBUGS Manual Volume 1, and explain what Y, Xa, Xs mean?, Thanks a lot!
=======================================
Dogs: loglinear model for binary data
Lindley (19??) analyses data from Kalbfleisch (1985) on the Solomon-Wynne experiment on
dogs, whereby they learn to avoid an electric shock. A dog is put in a compartment, the lights are
turned out and a barrier is raised, and 10 seconds later an electric shock is applied. The results
are recorded as success (Y = 1 ) if the dog jumps the barrier before the shock occurs, or failure
(Y = 0) otherwise.
Thirty dogs were each subjected to 25 such trials. A plausible model is to suppose that a dog
learns from previous trials, with the probability of success depending on the number of previous
shocks and the number of previous avoidances. Lindley thus uses the following model
pj = Axj Bj-xj
for the probability of a shock (failure) at trial j, where xj = number of success (avoidances) before
trial j and j - xj = number of previous failures (shocks). This is equivalent to the following log linear
model
log pj = axj + b ( j-xj )
Hence we have a generalised linear model for binary data, but with a log-link function rather than
the canonical logit link. This is trivial to implement in BUGS:
model
{
for (i in 1 : Dogs) {
xa[i, 1] <- 0; xs[i, 1] <- 0 p[i, 1] <- 0
for (j in 2 : Trials) {
xa[i, j] <- sum(Y[i, 1 : j - 1])
xs[i, j] <- j - 1 - xa[i, j]
log(p[i, j]) <- alpha * xa[i, j] + beta * xs[i, j]
y[i, j] <- 1 - Y[i, j]
y[i, j] ~ dbern(p[i, j])
}
}
alpha ~ dnorm(0, 0.00001)I(, -0.00001)
beta ~ dnorm(0, 0.00001)I(, -0.00001)
A <- exp(alpha)
B <- exp(beta)
}