A fellow political methodologist asks:
I have been asked to do some forecasting… I have a vague idea of how to do this in WinBUGS, but was wondering if you have done such a model (I’m assuming you have given your interests). If so, do you have an sample-esque code you could send along.
Briefly, I’m predicting the probability of a certain type of event occuring given a set of covariates. The data are dichotomous with a lagged DV and some co-variates. It’s a trivial model to estimate, but I’m not exactly sure what to add to ‘forecast’ events.
I’m guessing it would be something like:
p_new <- mu[new]
mu[new] <- ???
The BUGS way of doing things makes this kind of easy. Suppose you've got data on points, 1, ..., R, and you want forecasts for R+1, ..., T. Then you can just write a loop for 1:T, and the fact that y[R+1:T] are unobserved nodes is really not problematic for the software, provided all the parents of those unobserved nodes are specified. Take a trivial case, a Gaussian random walk with unit innovation variance, and standard Gaussian initializing the walk:
for(i in 2:T){
y[i] ~ dnorm(y[i-1],1)
}
y[1] ~ dnorm(0,1) ## initial conditions
Now as far as BUGS is concerned, it doesn't matter if all or any of the y[i] are observed. The initialization for y[1] kicks things off, and away you go.
Generalize/modify this as appropriate for (a) covariates in the model for y; (b) discrete y. For the case with covariates X contemporaneous with y, you'll want some kind of prior or model to come up with values of X[R+1:T], since these are parents of y[R+1:T] and the program won't know what to do without some kind of model/prior for them.
The other thing here is that when you feed data to BUGS, you'll supply data for y[1:T], but with NAs as the "data" for y[R+1:T]. Similarly, pad out X with NAs for missing or yet-to-be-realized observations, but again, you'll need a model and/or prior for those elements of X (again, since they are parents of y). Finally, for the "missing" y and X, you can supply initial values: if you are going to do this, you create initial values for the entire y vector and X matrix, but with NAs as the initial values for elements of those objects that are actually observed.