Discrete uniform distribution

Hi, stan users,

I wonder if there is a discrete uniform distribution in stan. If not, how to build it?


Not sure if this is helpful, because the context is not clear.
Anyhow, you could use the categorical distribution:

or the Dirichlet distribution for the multivariate case:

These are great. Many thanks for your reply.

We’re going to be making this even easier by building in a symmetric simplex constructor, so uniform with K variables will look something like

y ~ categorical(uniform_simplex(K));

But we should probably just add a discrete uniform distribution with inclusive upper and lower bounds.

1 Like

I think this is the relevant issue: https://github.com/stan-dev/math/issues/719
I was going to have a go at it in the coming release cycle, so since there’s interest I might really try it.

Hi, I’m trying to implement a discrete uniform prior in Stan. Is it still recommended to use the categorical distribution? I don’t think the uniform_simplex was added so I’m not 100% sure how to do this. I took a look at the github issue you linked to and saw that the discrete_range was implemented. Is it possible to use with the ‘distributed as’ notation: y ~ discrete_range(lower, upper)? Any info would be appreciated. Thanks!

The main implementation is complete, but it was never exposed to the compiler, so at the moment this will not work. I’ve now opened https://github.com/stan-dev/stanc3/issues/750 to track the final part of this work, sorry we didn’t get it finished a few months ago.

Oh great, thanks for the info! I’ll keep an eye on that issue.