[pollution0]    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 to open)

Inits for chain 1   Inits for chain 2     (Click to open)



Plus click on
gen inits to generate initial values for the missing data



Results

RW(1) prior:


[pollution1]


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.
   
[pollution2]

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



[pollution3]