#### 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

μ_{t} on day t, the likelihood for the observed pollution concetration Y

_{t }is assumed to be independent Normal i.e.

Y

_{t}_{ }~ Normal(

μ_{t},

τ_{err}) where 1/

τ_{err}_{ }is the measurement error variance

μ_{t} =

β +

θ_{t}_{ }where

β is the overall mean pollution concentration at the site, and

θ_{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

**θ**_{ }=

{θ_{1}_{ }, ......,

θ_{366}_{ }} (see equation 7 in Shaddick and Wakefield):

θ_{t} |

θ_{-}_{t}_{ } ~ Normal

( θ_{t+1},

φ ) for t = 1

~ Normal

( (θ_{t-1}_{ }+ θ_{t+1})/2,

φ / 2 ) for t = 2, ...., T-1

~ Normal

( θ_{t-1},

φ ) for t = T

where

θ_{-}_{t}_{ }denotes all elements of

**θ**except the

θ_{t}. This prior may be specified in BUGS using the

*rand.walk *distribution.

The RW(1) reflects prior beliefs about smoothness of first differences, i.e. sudden jumps between consecutive values of

**θ**_{ }are unlikely. Alternatively, we may assume a second order random walk prior RW(2) for

**θ**_{ }, which represents prior beliefs that the rate of change (gradient) of

**θ**_{ }is smooth:

θ_{t} |

θ_{-}_{t}_{ }~ Normal

( 2

θ_{t+1}_{ }- θ_{t+2},

φ ) for t = 1

~ Normal

( (2

θ_{t-1}_{ }+ 4

θ_{t+1}_{ }- θ_{t+2}) / 5,

φ / 5 ) for t = 2

~ Normal

( (-θ_{t-2}_{ }+ 4

θ_{t-1}_{ }+ 4

θ_{t+1}_{ }- θ_{t+2}) / 6,

φ / 6 ) for t = 3, ...., T - 2

~ Normal

( (-θ_{t-2}_{ }+ 4θ_{t-1}_{ }+ 2

θ_{t+1}) / 5,

φ / 5 ) for t = T -1

~ Normal

( -θ_{t-2}+ 2

θ_{t-1},

φ ) for t = T

Again this may be specified using the

*stoch.trend *distribution in BUGS.

ModelThe model code for fitting these two models is given below.

model {

#likelihood

for(t in 1:T) {

y[t] ~ dnorm(mu[t], tau.err)

mu[t] <- beta + theta[t]

}

theta[1:T] ~ rand.walk(tau)

#theta[1:T] ~ stoch.trend(tau)

beta ~ dflat()

# 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____Inits for chain 1__ __Inits for chain 2__Plus click on

*gen inits* to generate initial values for the missing data

ResultsRW(1) prior:

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.

Equivalent plot assuming an RW(2) prior. Note the greater amount of smoothing imposed by this prior: