Hi, I am new to Stan but a little familiar with jags and bugs, and I want to transition some codes from bugs to Stan. Recently I encountered a problem where I cannot figure how to deal with a special categorical distribution.
The parameter delta i (i as a subscript) can take any integer from 1 to J, and it follows a discrete (categorical) distribution with probability (p1,p2,…,pJ).
To reduce the number of parameters, only pJ and a hyperparameter omega are specified. So p1,p2,…p(J-1) can be expressed as
p _j=\frac{j^{\omega}-(j-1)^{\omega}}{(J-1)^{\omega}}(1-p _J), j=1,...,J-1
So I specified this in bugs as
model {
for (i in 1:I){
# some prior
theta[i] ~ dnorm(0, 1)
delta[i] ~ dcat(p[1:J])
# model
for (j in 1:J) {
eta[i,j] <- step(j - delta[i] - 0.5)
logit(p1[i,j]) <- theta[i] - b[j]
pp[i,j] <- eta[i,j] * 0.25 + (1 - eta[i,j]) * p1[i,j]
Y[i,j] ~ dbern(pp[i,j])
}
}
# the categorical distribution part
p[J] ~ dunif(0, 1)
temp <- (1 - p[J]) / pow(J-1, omega)
for (j in 1:(J-1)) {
p[j] <- (pow(j, omega) - pow(j-1, omega)) * temp
}
omega ~ dgamma(1, 1)
# some prior
for (j in 1:J) {
b[j] ~ dunif(-1, 3)
}
}
When I transiting the above codes into Stan, I cannot figure out how to specify pJ, can it be
parameters {
real<lower=0,upper=1> pJ;
}
or just
parameters {
real<lower=0,upper=1> p[J];
}
I think the second specification must be wrong, but I can’t work out a way to build a categorical distribution with parameters pJ and omega.
Thanks for your answering and please forgive me for my ignorance if this question is foolish.