Choosing Different Distributions based on if - else condition in JAGS

  • Shriram

    Shriram - 2013-03-15

    I am trying to write a Jags model for modeling multi grain topic models (exactly this paper ->

    Here I would like to choose a different distribution based on a particular value. For Eg: I would like to do something like

    if ( X[i] > 0.5 )
    Z[i] ~ dcat(theta-gl[D[i], 1:K-gl])
    W[i] ~ dcat(phi-gl[z[i], 1:V])
    Z[i] ~ dcat(theta-loc[D[i], 1:K-loc])
    W[i] ~ dcat(phi-loc[z[i], 1:V])

    Is this possible in JAGS? If so, how?

  • Martyn Plummer

    Martyn Plummer - 2013-03-22

    Because you are using the same distribution (dcat) and the choice is between different parameter values, you can do this with nested indexing

       c[i] <- ifelse(X[i] > 0.5, 2, 1) #indicates which mixture component to use
       Z[i] ~ dcat(probsZ[c[i], D[i], 1:K])
       W[i] ~ dcat(probsW[c[i], z[i], 1:K])

    where you set up the parameter vectors probsZ and probsW to correspond to the two models,e.g.

    probsZ[1, 1:ND, 1:K] <- theta - gl[1:ND, 1:K]
    probsZ[2, 1:ND, 1:K] <- theta - loc[1:ND, 1:K]
    probsW[1, 1:NZ, 1:K] <- phi - gl[1:NZ, 1:K]
    probsW[2, 1:NZ, 1:K] <- phi - loc[1:NZ, 1:K]

    where ND is the maximum value of D[i] and NZ is the maximum value of Z[i].


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks