I am working on a model like the one below and I am trying to come up with the right way to vectorize the V[k]
inference in the model.
V[k] ~ binomial_logit(I[,kk[k]] , logit_p);
where logit_p
is a vector of length N and I[,kk[k]]
is array of length N.
Stan Code:
data {
int<lower=0 > N;
int<lower=0 > K;
int<lower=0 > J;
int<lower=0> V[K,N];
int<lower=1> I[2,N];
int<lower=1, upper=J> jj[K];
int<lower=1, upper=2> kk[K];
}
parameters {
vector[N] theta;
vector<lower=0>[K] alpha;
vector[N] gamma[J];
vector[K] beta;
}
model {
beta~ normal(0,1);
theta~ normal(0, 1);
alpha ~ lognormal(0, 1);
for (i in 1: J){
gamma[i] ~ normal(theta,1);
}
{
vector[N] logit_p;
for (k in 1:K) {
logit_p = alpha[k]*gamma[jj[k]] + beta[k]
V[k] ~ binomial_logit(I[,kk[k]] , logit_p);
}
}
}