BUGS run 1
First edit the line.in file supplied with BUGS as follows:
list(tau = 5, alpha = -5, beta = 5, seed = 9876543210)
Note the inclusion of a random number seed in this file.
Carry out the following BUGS analysis using the line.bug and line.dat files supplied with BUGS, and the new line.in file which you have just created. (If you have saved the latter under a different name, such as line1.in, make sure that you also edit the name of the file which appears after the inits in ... statement in the line.bug file):
Bugs>compile("line.bug")
model line;
const
N = 5; # number of observations
var
x[N],Y[N],mu[N],alpha,beta,tau,sigma,x.bar;
data in "line.dat";
inits in "line.in";
{
for (i in 1:N) {
mu[i] <- alpha + beta*(x[i] - x.bar);
Y[i] ~ dnorm(mu[i],tau);
}
x.bar <- mean(x[]);
alpha ~ dnorm(0.0,1.0E-4);
beta ~ dnorm(0.0,1.0E-4);
tau ~ dgamma(1.0E-3,1.0E-3);
sigma <- 1.0/sqrt(tau);
}
Bugs>monitor(alpha)
Bugs>monitor(beta)
Bugs>monitor(sigma)
Bugs>update(200)
Bugs>q()
Now rename the bugs.out and bugs.ind files to line1.out and line1.ind respectively to ensure they don't get over-written after the next BUGS run.
BUGS run 2
Re-edit the file line.in to change the initial values and random number seed as follows:
list(tau = 0.01, alpha = 0.01, beta = 0.01, seed = 1234567890)
Now re-run the line example in BUGS for 200 iterations using the new initial values file.
Having completed the second BUGS run, rename the bugs.out and bugs.ind files to line2.out and line2.ind respectively.
You have now generated 2 parallel runs of the line problem in preparation for multiple chain analysis in CODA.