
422 11 ANOVA and Elements of Experimental Design
alpha[diets[i]]. The priors on alpha[i] are noninformative and depend on
the selection of identifiability constraint. Here the code uses sum-to-zero, a
STZ constraint that fixes one of the
αs, while the rest are given standard non-
informative priors for the location. For example,
α
1
is fixed as −(α
2
+···+α
k
),
which explains the term sum-to-zero. Another type of constraints that ensures
model identifiability is corner or CR constraint. In this case “corner” value
α
1
is set to 0. Then the treatment 1 is considered as a baseline category.
The grand mean
mu0 is given a noninformative prior as well.
The parameter
tau is a precision, that is, a reciprocal of variance. Tradi-
tionally, the noninformative prior on the precision is gamma with small pa-
rameters, in this case
dgamma(0.001,0.001). From tau, the standard deviation
is calculated as
sigma<-sqrt(1/tau). Thus, the highlights of the code are (i)
the indexing of alpha via
diets[i], (ii) the identifiability constraints, and (iii)
the choice of noninformative priors.
model{
for (i in 1:ntotal){
times[i] ~ dnorm( mu[i], tau )
mu[i] <- mu0 + alpha[diets[i]]
}
#alpha[1] <- 0.0; #CR Constraint
alpha[1] <- -sum( alpha[2:a] ); #STZ Constraint
mu0 ~ dnorm(0, 0.0001)
alpha[2] ~ dnorm(0, 0.0001)
alpha[3] ~ dnorm(0, 0.0001)
alpha[4] ~ dnorm(0, 0.0001)
tau ~ dgamma(0.001, 0.001)
sigma <- sqrt(1/tau)
}
DATA
list(ntotal = 24, a=4,
times =c(62, 60, 63, 59, 63, 67, 71, 64, 65, 66,
68, 66, 71, 67, 68, 68, 56, 62, 60, 61, 63, 64, 63, 59),
diets = c(1,1,1,1, 2,2,2,2,2,2, 3,3,3,3,3,3, 4,4,4,4,4,4,4,4) )
INITS
list( mu0=0, alpha = c(NA,0,0,0), tau=1)
mean sd MC error val2.5pc median val97.5pc start sample
alpha[1] –3.001 1.03 0.002663 –5.039 –3.002 –0.9566 1001 100000
alpha[2] 1.999 0.893 0.003573 0.2318 1.999 3.774 1001 100000
alpha[3] 4.001 0.8935 0.003453 2.232 4.002 5.779 1001 100000
alpha[4] –2.999 0.8178 0.003239 –4.61 –2.999 –1.382 1001 100000
mu0 64.0 0.5248 0.00176 62.96 64.0 65.03 1001 100000
sigma 2.462 0.4121 0.001717 1.813 2.408 3.422 1001 100000
tau 0.1783 0.05631 2.312E-4 0.08539 0.1724 0.3043 1001 100000