Sign up ×
Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It's 100% free, no registration required.

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) : 
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("")

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:


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.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
+1. How do you impute missing data on predictors in JAGS while accounting for the uncertainty in the imputed values? (i.e. much like multiple imputation does vs. single imputation) – Patrick Coulombe Mar 24 '14 at 17:52
@PatrickCoulombe I have seen strategies that treat each missing datum as an unknown (same treatment as e.g. a regression parameter). The design matrix is then reconstructed at each iteration. Thus, the uncertainty in the imputed value carries forward. – Eric Brown May 16 at 10:00

It is actually possible to have missing values in the predictors, although you need to put a prior distribution on any missing values (or all of the values, if this is easier). So if you have some missing values in peace[i] then you need an additional line in the code as follows:

 peace[i] ~ dnorm(0, 10^-6)  # Or whatever would be an appropriate prior

More informative priors would obviously be preferable - if you have very diffuse priors for all missing predictors, then these predictors are effectively contributing nothing to the posterior (except possibly convergence problems).

Note that JAGS/BUGS makes no real distinction between data and parameters, so the missing data (and/or predictor) values are in this case treated as parameters to be estimated. You could put hyper priors on these as well, such as estimating the mean and variance of the distribution of peace, from which missing values will be drawn.

share|improve this answer
Just noticed the date and this is 2 years old, sorry! I will leave the answer anyway in case it is useful to someone else. – Matt Denwood Apr 19 at 8:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.