Menu

#15 possible compiler issue

closed
nobody
None
5
2012-09-01
2012-01-04
Tim Handley
No

When I call jags.model() on a particular model of mine, I get the following error:

Error in jags.model(file = \"A108_YYYZ.bugs\", data = amind.4.jags, inits = amin.inits(nc), :
Error in node (((step((hits.is.zero.copy[2]-0.5)))*p.u0[387])/(dbin(0,p.cover[387],tran.Npts[387])))
Invalid parent values

Now, there may be a problem with the initial values, but my bigger concern is with the indices in the above error. The line flagged by JAGS is in a loop, and this calculation is supposed to be done using corresponding elements of each array. That is, JAGS should be trying to calculate

(((step((hits.is.zero.copy[387]-0.5)))*p.u0[387])/(dbin(0,p.cover[387],tran.Npts[387])))

Instead, it is doing a calculation with the 2nd element of hits.is.zero.copy, even though it is using the 387th element of the other arrays. So it seems like there is some problem with interpretation, in which the compiler is trying to do a calculation using the wrong set of array elements.

Platform: Win7-64 SP1, R 2.13.2, JAGS 3.1.0, corresponding version of rjags.
Attachment: A repeatable example. The .Rdata file contains all the necessary data (plus some extra stuff I didn\'t feel like weeding out). The .bugs file is the model description. The .R file contains a few lines of code to compile the given model with the proper data.

Discussion

  • Tim Handley

    Tim Handley - 2012-01-04

    repeatable example

     
  • Martyn Plummer

    Martyn Plummer - 2012-01-04

    The JAGS compiler recycles constant nodes and deterministic nodes in order to save computation. The savings can be substantial. In your model, we only need to calculate

    step(hist.is.zero,copy[i] - 0.5)

    twice since the elements of hist.is.zero.copy only take two values - 0 and 1.

    So hits.is.zero.copy[2] and hist.is.zero.copy[387] are exactly the same node. When it comes to deparsing the node (i.e. working out the BUGS expression that generated it) there is no unique answer which is why there is some confusion in the expression.

     

Anonymous
Anonymous

Add attachments
Cancel