How do I specify for a variable to be uniformly sampled from the discrete values $1,2,\ldots,10$ in JAGS? I guess I want to use the dcat() distribution, but I have yet to find good documentation of the parameters for this.
2 Answers
$\begingroup$
$\endgroup$
7
Have a look at the JAGS user manual. dcat(pi)
is defined with a density of $\pi_x/\sum_i{\pi_i}$.
-
$\begingroup$ So I want to pass a list of probabilities to dcat(). Can this list be specified in the JAGS model or do I have to pass it from R? $\endgroup$ Commented Feb 3, 2013 at 22:55
-
$\begingroup$ You could pass the vector
pi
from R or define it in the model file; it contains the probabilities that sum to one. $\endgroup$ Commented Feb 4, 2013 at 0:15 -
$\begingroup$ Usually the probabilities are derived from another distribution. See e.g. mixture models $\endgroup$ Commented Feb 4, 2013 at 0:38
-
1$\begingroup$ I assume you want to use
dcat
as a prior. In your model specify e.g.:mu ~ dcat(pi)
. Then specifypi <- c(0.2,0.5,0.3)
and include it in thejags.model
data list:data=list(pi=pi, ...)
. $\endgroup$ Commented Feb 5, 2013 at 18:57 -
1$\begingroup$
dcat(pi)
as @user12719 is correct to use, but important to note that unlike BUGS language and other specifications of categorical distributions, JAGS is not expectingpi
to sum to 1 and normalizes it internally. This can effect the way eachpi[i]
is estimated. (answering instead of commenting as not enough rep to comment here) $\endgroup$– ScransomCommented Sep 3, 2015 at 5:51
$\begingroup$
$\endgroup$
Kruschke's in his book Doing Bayesian Data Analysis 2ed on page 278 has following code
model{
...
...
m ~ dcat( mPriorProb[] )
mPriorProb[1] <- .5
mPriorProb[2] <- .5
}
To quote from the book:
The argument of the dcat distribution is a vector of probabilities for each category. JAGS does not allow the vector constants to be defined inside the argument, like this:
m ~ dcat(c(.5,.5))
.