Chapter 11 Exercises
Stagnant water: splines
Solutions

In the stagnant water example of 11.7.1, extend the linear change point model to a quadratic spline, and compare the parameter estimates, model fit and DIC.


model
{
for (i in 1:N) {
y[i] ~ dnorm(mu[i], tau)
mu[i] <- alpha + beta[1]*x[i] +
      beta[2]*(x[i] - theta) * step(x[i] - theta) +
      beta[3]*pow(x[i] - theta, 2) * step(x[i] - theta)
}
tau ~ dgamma(0.001, 0.001)
alpha ~ dnorm(0.0, 1.0E-6)
for (j in 1:3) {
beta[j] ~ dnorm(0.0, 1.0E-6)
}
sigma <- 1/sqrt(tau)
theta ~ dunif(-1.3, 1.1)
}
   
Data:
list(y = c(1.12, 1.12, 0.99, 1.03, 0.92, 0.90, 0.81, 0.83, 0.65, 0.67, 0.60, 0.59, 0.51, 0.44, 0.43, 0.43, 0.33, 0.30, 0.25, 0.24, 0.13, -0.01, -0.13, -0.14, -0.30, -0.33, -0.46, -0.43, -0.65),
x = c(-1.39, -1.39, -1.08, -1.08, -0.94, -0.80, -0.63, -0.63, -0.25, -0.25, -0.12, -0.12, 0.01, 0.11, 0.11, 0.11, 0.25, 0.25, 0.34, 0.34, 0.44, 0.59, 0.70, 0.70, 0.85, 0.85, 0.99, 0.99, 1.19),
N = 29)

Initial values:
list(alpha = 0.2, beta = c(-0.45, 0, 0), tau = 5, theta = 0)


   node   mean   sd   MC error   2.5%   median   97.5%   start   sample
   alpha   0.5549   0.01352   7.688E-4   0.5303   0.5543   0.5845   501   9500
   beta[1]   -0.4121   0.01505   7.414E-4   -0.4405   -0.4126   -0.3804   501   9500
   beta[2]   -0.421   0.08015   0.005119   -0.5661   -0.4259   -0.244   501   9500
   beta[3]   -0.1332   0.05109   0.002825   -0.2331   -0.1338   -0.03128   501   9500
   sigma   0.02003   0.003019   5.693E-5   0.01517   0.01972   0.02691   501   9500
   theta   -0.06109   0.06504   0.005198   -0.2209   -0.0533   0.04413   501   9500

Dbar = post.mean of -2logL; Dhat = -2LogL at post.mean of stochastic nodes
   Dbar   Dhat   pD   DIC   
y   -150.079   -156.250   6.171   -143.908   
total   -150.079   -156.250   6.171   -143.908   



[exercises-ch11-stagnant-solutions0]

There appears to be a statistically significant curvature in the regression line (judging by the posterior distribution of the quadratic coefficient beta[3] and the improvement of about 5 in DIC) but this is small in absolute terms, and qualitatively the fit is hardly changed. The uncertainty around the change point location theta is slightly increased.