0
$\begingroup$

I have a relatively simple multivariate response problem that seems to causing me problems with array indexing. I've scraped/rewworked the model program down to the bare essentials and hopefully haven't cut/replaced too much. I hav3 265 total observations, 5 different groups of responses, each with 53 replications.

# Notes: 
# N= total number of samples = 265
# K= number of clusters = 5
# T = number of observations in each clusters =53
# P = nterms=number of independent variables = 10
#  
model {
  for (j in 1:K) {   #K
      for (i in 1:T) {  #T
          y[i,j] ~ dnorm(mu[i,j], tau)
          mu[i,j]<-  b0 + b[1]*x[i,j,1] + b[2]*x[i,j,2] + b[3]*x[i,j,3] + b[4]*x[i,j,4] +     b[5]*x[i,j,5] + b[6]*x[i,j,6] + b[7]*x[i,j,7] + b[8]*x[i,j,8] + b[9]*x[i,j,9] + b[10]*x[i,j,10]   # error
    #            mu[i,j]<-  b0 + b[1]*x[i,j,1]+ b[2]*x[i,j,2]  # no error
         }
      }
# mean <- b0+ inprod(x[i,j,], beta[])
# priors ------------------
b0 ~ dnorm(0,0.001)  # prior on constant term
for(i in 1:nterms) {
       b[i] ~ dnorm(0,0.001)
    }
    tau ~ dgamma(1.0E-3, 1.0E-3)
    sigma <- 1 / sqrt(tau)
}

My data input is coming from an R script (data input snippet):

input<- "GB_migration.csv"
obs.raw<-read.table(input, header = TRUE, sep = ",")

P<-10
K <- 5
T <- 53
N <- nrow(obs.raw)
Y.raw <- obs.raw[,2]
X.raw <- obs.raw[,1:P+2]

X<-unlist(X.raw)
dim(X)<-c(T,K,P)

Y<-unlist(Y.raw)
dim(Y)<-c(T,K)

….snip ….

The error code I get when I run it with all 10 independent variables:

Error in jags.model("Migration.mod", jags.data, n.adapt = 500, n.chains = 2) : RUNTIME ERROR: Compilation error on line 10. Unable to resolve node mu[1,1] This may be due to an undefined ancestor node or a directed cycle in the graph

I feel like I'm missing something basic with the array indexing, but I cannot seem to put my finger on it. (I've un-nested as many of the vector operations as I could to try to track this down.Hopefully the code still makes sense. )

Thanks in advance for any insight. Dave

$\endgroup$
  • 1
    $\begingroup$ That's an error you would get, for example, when there is something wrong with your indexing, and you have a lot of indexing so... double check it (say, remove stuff until it works) thats my tip. $\endgroup$ – Rasmus Bååth Nov 12 '14 at 20:56
  • $\begingroup$ Did you pass nterms as well as P to JAGS somewhere? $\endgroup$ – conjugateprior Dec 13 '14 at 15:53
  • 1
    $\begingroup$ If you add terms one by one and it fails with b[6]*x[i,j,6] (because 6>K) then incorrectly assigned matrix dimensions are the problem. $\endgroup$ – conjugateprior Dec 13 '14 at 15:55
1
$\begingroup$

So there aren't a lot of things left that can go wrong here but since there's no toy data to look at I can't help you much more than this: nterms is less than 10 or the full array of x's is not defined. There are no cycles, so one of the b's or x's is undefined. If you would like a better answer, please post a minimal working/failing example.

$\endgroup$

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