Is It Possible to put a Prior Distribution on the Upper Index of a For Loop?

  • John

    John - 2014-04-21

    I'm interested in fitting linear splines within a JAGS model, but would like to estimate the number and placement of knots. Is there any way to trick JAGS so that I can place a prior distribution on the upper index of a for loop?

    For example:

    for(i in 1:nk){
    knot[i] ~ dunif(x_min,x_max)
    knots <- sort(knot[])
    nk ~ dpois(15)

    x_min and x_max are the range of the dependent variable x. This throws an error in JAGS.

  • Martyn Plummer

    Martyn Plummer - 2014-05-19

    No. All JAGS models must be of fixed dimension. Sorry.

  • Dan Linden

    Dan Linden - 2014-05-21

    John, I would look into data augmentation (popular for Bayesian capture-recapture models). You create a vector with the maximum number of possible knots and then estimate knot membership at each iteration with a Bernoulli draw. This way your parameter dimension is fixed but the effective number of knots can vary. I have no idea if this will work in your case, but it definitely qualifies as a trick for handling stochastic dimensions.


Log in to post a comment.