Random walk priors for temporal
smoothing of daily air pollution estimates
Shaddick and Wakefield (2002) consider spatiotemporal modelling of daily ambient air pollution at a number of monitoring sites in London. Here we take a subset of their data on a single pollutant measured at one site for 366 days, and model temporal autocorrelation using a random walk prior.
Conditional on the underlying mean concentration m t on day t, the likelihood for the observed pollution concetration Y t is assumed to be independent Normal i.e.
Y t ~ Normal( m t , t err ) where 1/ t err is the measurement error variance
m t = b + q t
where b is the overall mean pollution concentration at the site, and q t is a (zero mean) random error term representing daily fluctuations about this mean. To reflect the prior belief that these daily fluctuations are correlated, a random walk prior is assumed for q = {q 1 , ......, q 366 } (see equation 7 in Shaddick and Wakefield):
q t | q - t ~ Normal ( q t+1 , f ) for t = 1
~ Normal ( (q t-1 + q t+1 )/2, f / 2 ) for t = 2, ...., T-1
~ Normal ( q t-1 , f ) for t = T
where q - t denotes all elements of q except the q t . This prior may be specified in WinBUGS 1.4 using the car.normal distribution, with adjacency vector adj[] listing neighbouring time points (i.e. (t-1) and (t+1) are neighbours of time point t), corresponding weight vector weight[] set to a sequence of 1's, and vector giving the number of neighbours, num[] , set to 2 for all time points except num[1] and num[T] which are set to 1.
The RW(1) reflects prior beliefs about smoothness of first differences, i.e. sudden jumps between consecutive values of q are unlikely. Alternatively, we may assume a second order random walk prior RW(2) for q , which represents prior beliefs that the rate of change (gradient) of q is smooth:
q t | q - t ~ Normal ( 2 q t+1 - q t+2 , f ) for t = 1
~ Normal ( (2 q t-1 + 4 q t+1 - q t+2 ) / 5, f / 5 ) for t = 2
~ Normal ( (-q t-2 + 4 q t-1 + 4 q t+1 - q t+2 ) / 6, f / 6 ) for t = 3, ...., T - 2
~ Normal ( (-q t-2 + 4q t-1 + 2 q t+1 ) / 5, f / 5 ) for t = T -1
~ Normal ( -q t-2 + 2 q t-1 , f ) for t = T
Again this may be specified using the car.normal distribution in OpenBUGS via appropriate specification of the adj[] , weight[] and num[] vectors.
The model code for fitting these two models is given below.
Model
model {
#likelihood
for(t in 1:T) {
y[t] ~ dnorm(mu[t], tau.err)
mu[t] <- beta + theta[t]
}
# prior for temporal effects
# RW prior for theta[t] - specified using car.normal with
#neighbours (t-1) and (t+1)
# for theta[2],....,theta[T-1], and neighbours (t+1) for
#theta[1] and (t-1) for theta[T]
theta[1:T] ~ car.normal(adj[], weights[], num[], tau)
beta ~ dflat()
# Specify weight matrix and adjacency matrix corresponding to RW(1) prior
# (Note - this could be given in the data file instead)
for(t in 1:1) {
weights[t] <- 1;
adj[t] <- t+1;
num[t] <- 1
}
for(t in 2:(T-1)) {
weights[2+(t-2)*2] <- 1;
adj[2+(t-2)*2] <- t-1
weights[3+(t-2)*2] <- 1;
adj[3+(t-2)*2] <- t+1;
num[t] <- 2
}
for(t in T:T) {
weights[(T-2)*2 + 2] <- 1;
adj[(T-2)*2 + 2] <- t-1;
num[t] <- 1
}
# Alternatively, a weight matrix and adjacency matrix
#corresponding to RW(2) prior can
# be specified or given in the data file
#(note, no need to change the prior distribution
# on theta, just the weights/adjacencies)
# for(t in 1:1) {
# weights[t] <- 2; adj[t] <- t+1
# weights[t+1] <- -1; adj[t+1] <- t+2; num[t] <- 2
# }
# for(t in 2:2) {
# weights[t+1] <- 2; adj[t+1] <- t-1
# weights[t+2] <- 4; adj[t+2] <- t+1
# weights[t+3] <- -1; adj[t+3] <- t+2; num[t] <- 3
# }
#for(t in 3:(T-2)) {
# weights[6+(t-3)*4] <- -1; adj[6+(t-3)*4] <- t-2
# weights[7+(t-3)*4] <- 4; adj[7+(t-3)*4] <- t-1
# weights[8+(t-3)*4] <- 4; adj[8+(t-3)*4] <- t+1
# weights[9+(t-3)*4] <- -1; adj[9+(t-3)*4] <- t+2; num[t] <- 4
# }
# for(t in (T-1):(T-1)) {
# weights[(T-4)*4 + 6] <- 2; adj[(T-4)*4 + 6] <- t+1
# weights[(T-4)*4 + 7] <- 4; adj[(T-4)*4 + 7] <- t-1
# weights[(T-4)*4 + 8] <- -1; adj[(T-4)*4 + 8] <- t-2; num[t] <- 3
# }
# for(t in T:T) {
# weights[(T-4)*4 + 9] <- 2; adj[(T-4)*4 + 9] <- t-1
# weights[(T-4)*4 + 10] <- -1; adj[(T-4)*4 + 10] <- t-2; num[t] <- 2
# }
# other priors
tau.err ~ dgamma(0.01, 0.01) # measurement error precision
sigma.err <- 1 / sqrt(tau.err)
sigma2.err <- 1/tau.err
tau ~ dgamma(0.01, 0.01) # random walk precision
sigma <- 1 / sqrt(tau)
sigma2 <- 1/tau
# include this variable to use in time series (model fit) plot
for(t in 1:T) { day[t] <- t }
}
Note that pollution concentrations were not measured every day. However it is necessary to include days with no measurements as missing values (NA) in the data set, otherwise the temporal neighbourhood structure cannot be specified correctly.
Data click here to open data
Inits click here to open initial values
Plus click on gen inits to generate initial values for the missing data
Results
RW(1) prior:
node mean sd MC error 2.5% median 97.5% start sample
beta 3.029 0.0201 9.439E-4 2.99 3.029 3.069 1001 10000
mu[1] 2.867 0.1959 0.00221 2.483 2.863 3.254 1001 10000
mu[2] 2.824 0.1779 0.004028 2.481 2.82 3.179 1001 10000
mu[3] 3.115 0.1703 0.002417 2.783 3.115 3.443 1001 10000
mu[4] 3.334 0.1852 0.005685 2.968 3.336 3.694 1001 10000
mu[5] 3.111 0.1689 0.002165 2.783 3.11 3.446 1001 10000
.......
.......
mu[360] 2.584 0.1673 0.002305 2.258 2.583 2.916 1001 10000
mu[361] 2.383 0.1716 0.003417 2.044 2.381 2.72 1001 10000
mu[362] 2.414 0.1678 0.002228 2.084 2.411 2.746 1001 10000
mu[363] 2.47 0.1679 0.00229 2.147 2.47 2.802 1001 10000
mu[364] 2.516 0.1712 0.002963 2.176 2.52 2.847 1001 10000
mu[365] 2.399 0.1706 0.002618 2.063 2.398 2.729 1001 10000
mu[366] 2.288 0.196 0.003037 1.91 2.284 2.684 1001 10000
sigma 0.2709 0.03888 0.002482 0.2006 0.27 0.3485 1001 10000
sigma.err 0.2433 0.03411 0.002153 0.1717 0.2449 0.3063 1001 10000
Plot of posterior median (red line) and posterior 95% intervals (dashed blue lines) for mu[t] (the true mean daily pollutant concentration), with observed concentrations shown as black dots. (This plot was produced by selecting the model fit option from the Compare menu (available from the Inference menu), with mu specified as the node , day as the axis and y as other ). Note that the dashed blue line shows the posterior 95% interval for the estimated mean daily concentration, and is not a predictive interval - hence we would not necessarily expect all of the observed data points to lie within the interval.
MISSING FIGURE
Equivalent plot assuming an RW(2) prior. Note the greater amount of smoothing imposed by this prior:
MISSING FIGURE