I just finished a model for an experiment where a continuous state, described by a random walk for a series of individuals was classified into discrete states. Because individuals could not be identified, the actual data is the number of individuals in each state at each time point. The model works fine. One issue was that I had to generate the model in R because I used "dsum" and it would not take a vector argument to sum, only multiple arguments, so no a ~ dsum(b[]), only a ~ dsum(b[1],b[2],b[3]), which R will happily generate... but I think auto-generating BUGS code makes it difficult for other to read so... did I miss a cleaner way of doing this? Is this an easy feature to add? Actual R code which generates the model is below:

model_string <- paste(
'model {

    ## State process:
    for (i in 1:nInd) {
      x[i,1] ~ dunif(-.999,.999) 
      states[i,1] ~ dinterval(x[i,1],cutpoints)
      for (t in 2:nSteps) {
        x[i,t] ~ dnorm(muX[i,t],1/sdX^2) T(-5,5)
        muX[i,t] <- x[i,t-1] + beta[1] 
        states[i,t] ~ dinterval(x[i,t],cutpoints)

    for (i in 1:1) {
      beta[i] ~ dnorm(0,0.5)
    sdX ~ dgamma(2,1)

    ## Observation process:
    for (t in 1:nSteps) {
      for (s in 1:nStates) {
        count[s,t] ~ dsum(',
            paste('((states[',1:jags.list[['nInd']],',t]+1) == s)', collapse=' , ',     sep='')

', sep='')
Last edit: Krzysztof Sakrejda 2013-11-15