Solved – jags missing data error

bayesianjagsr

I am estimating a probit in jags on a time series cross sectional data set (country years) with 5 covariates, 4 of which are lagged, so the first observation for each country will be missing on those 4 variables. There is some scattered missingness elsewhere in the data, but nothing too bad. All of the variables are of numeric type, and missing values are coded as 'NA'. The model works fine when I omit all missing values, but when I don't I get the error

Compiling model graph
Resolving undeclared variables
Allocating nodes
Deleting model
Error in jags.model("model.bug", data.jags, n.chains = 4, n.adapt = 1000) : 
RUNTIME ERROR:
Compilation error on line 4.
Unable to resolve node Xbeta[1]
This may be due to an undefined ancestor node or a directed cycle in the graph

Here is my data loading code

data.all <- read.csv("http://dl.dropbox.com/u/1253073/blowback-all.csv")

data.jags <- list('onset.b.lag' = data.all$onset.b.lag,
                  'ongoing' = data.all$ongoing,
                  'peace' = data.all$peace,
                  'ln.gdppc.lag' = data.all$ln.gdppc.lag,
                  'all.lag' = data.all$all.lag,
                  'onset' = data.all$onset,
                  'n' = nrow(data.all))

rjags call:

mod.all <- jags.model('model.bug', data.jags, n.chains = 4, n.adapt = 1000)

Here is my model code:

model{

for (i in 1:n) {
probit(p[i]) <- Xbeta[i]
onset[i] ~ dbern(p[i])
Xbeta[i] <- b.0 +
            b.onset.b.lag * onset.b.lag[i] +
            b.peace * peace[i] +
    b.ln.gdppc.lag * ln.gdppc.lag[i] +
    b.ongoing * ongoing[i] +
    b.all.lag * all.lag[i]
}

b.0 ~ dnorm(0, .0001)
b.peace ~ dnorm(0, .0001)
b.onset.b.lag ~ dnorm(0, .0001)
b.ln.gdppc.lag ~ dnorm(0, .0001)
b.ongoing ~ dnorm(0, .0001)
b.all.lag ~ dnorm(0, .0001)

}

My understanding is that when jags encounters an index where a variable is coded NA it takes a draw from the posterior. Any hints would be appreciated.

Best Answer

My understanding is that if the outcome is NA then it will fill it in from the posterior predictive. NA in the predictors is not allowed, and must be imputed.