Specify latent vector parameters in a hierarchical model

Hi everyone!

I am new to STAN and got a problem with modeling a hierarchical model. Here is my setting: Z=(Z1,Z2,Z3,Z4) is a vector representing 4 states, each Zi \in {0,1}. That is, Z\sim multinomial(1,p), where p is a vector with length 4 and sum 1. W=(W1, W2) follows some joint continuous distribution. X=(X1,X2) is the random variable depending on state Z, that is, X1=(Z3+Z4)W1 and X1=(Z2+Z4)W2. Finally, the data Y1\sim Poisson(X1) and Y2\sim Poisson(X2). I attach my attempt code below. My questions: (1) How to specify the intermediate Z with only values 0,1 as parameters? (2) How to write out w1,w2 and z1-4 separately in transformed parameters? Thank you so much for your patients and help!

data {
int<lower=1> n;
vector<lower=0>[4] alpha;
real x[n,2];
}

parameters {
simplex[4] p;
int z[n,4];
}

transformed parameters {
vector[n] x1 = (z[3]+z[4])*w[1];
vector[n] x2 = (z[2]+z[4])*w[2];
}

model {
target += dirichlet_lpdf(p | alpha);
for (j in 1:n)
target += multinomial_lpmf(z[j,] | p);
// likelihood for w given some known parameters (eg, bivariate lognormal)
// likelihood for y given x (Poisson)
}

Stan doesn’t sample discrete parameters, so if you have them in your model you’ll need to integrate them out.

Is this some sort of hidden Markov model? There’s some built in functions for those: 26 Hidden Markov Models | Stan Functions Reference

1 Like

@bbbales2, Thank you so much for your response! I checked STAN tutorial again and found that my question maybe a finite mixture problem. I will think it over.

1 Like