Categorical parameter model from Jags


Hi,

I’m trying to transform Jags-code into Stan, but am struggling with including a categorical parameter. I’ve seen there are other questions on this, but I was not able to extract the correct information to make it work for my case. Below is Jags-code that works (although in this simplified example prob doesn’t make much sense). How could I write this in Stan? In the attempts I’ve made I run into the error that K is an integer.

Thanks for any help, and let me know if anything is unclear.

Best,
Mads

model {
  
  for (trial in 1:N) {
    y[trial] ~ dnorm(K,0.01)
  }
  
  K ~ dcat(omega)
  omega ~ ddirich(c(1.0,1.0,1.0,1.0))
  
}

Are you sure y[trial] ~ dnorm(K,0.01) is correct?
I’d have considered y[trial] ~ dnorm(mu[K],0.01).
If so, have a look at the rebar code

https://github.com/howardnewyork/rebar

1 Like

It looks like what you’re doing could be expressed as a Finite Mixture model. There’s a chapter in the user’s guide on how to marginalize the latent discrete parameter out in Stan.

2 Likes

Thanks for the help, I ended up modifying the example described for finite mixture model in the user’s guide.