carlin:gelfand:smith:92 analyse data from bacon:watts:71 concerning a changepoint in a linear regression.
We assume a model with two straight lines that meet at a certain changepoint
-- this
is slightly different from the model of carlin:gelfand:smith:92 who do not
constrain the two straight lines to cross at the changepoint.
We assume
giving E(
at the changepoint, with gradient
before, and gradient
after the changepoint.
are
given independent ``noninformative'' priors. The appropriate graph is shown
in Figure 29, and the BUGS code follows.
We note that to be able to update the changepoint in the current version of BUGS we are required to have the changepoint as a discrete random variable; this could be a discretised X although here we have followed carlin:gelfand:smith:92 and forced the change to occur at one of the design points.
Figure 29:
Graphical model for stagnant example
}
Model specification for the stagnant example
model stagnant;
const
N = 29; # number of points
var
x[N], mu[N], Y[N], punif[N], J[N],
k, alpha, beta[2], tau, sigma;
data Y, x, punif in "stagnant.dat";
inits in "stagnant.in";
{
k ~ dcat(punif[]); # uniform prior over changepoint observation
for (i in 1:N) {
J[i] <- 1 + step(i - (k+0.5)); # J[i]=1 if i<=k; 2 if i>k
mu[i] <- alpha + beta[J[i]]*(x[i] - x[k]);
Y[i] ~ dnorm(mu[i],tau)
}
alpha ~ dnorm(0,1.0E-6);
beta1 ~ dnorm(0,1.0E-6);
beta2 ~ dnorm(0,1.0E-6);
tau ~ dgamma(1.0E-3,1.0E-3);
sigma <- 1.0/sqrt(tau);
}
Analysis
A BUGS run took 29 seconds for 1000 iterations after a 500 iteration burn-in and gave the following output.
The parameter estimates are very similar to those of carlin:gelfand:smith:92 and bacon:watts:71. The entire posterior distribution for k lay in the range 14-16, all of which correspond to a changepoint at X= .11. Plotting the data supports this finding, and contrasts slightly with the analysis of carlin:gelfand:smith:92 whose posterior mode lay at k=12. However, their posterior median of k=13 corresponds to the first 13 points being on one line, and the remainder on another, which is essentially our finding.