Hello,

I’ve been trying to fit some mixture models (Gaussian and Poisson). I am unsure of how to write the generated quantities block. I have seen some use cases in the discourses as well as tried to adapt the code in the Stan manual but have not had meaningful results.

I put the code for my Gaussian mixture model below, I would greatly appreciate some help with writing the “generated quantities” block.

mix_model <- "

data {

int<lower = 0> N;

vector[N] y;

}

parameters {

ordered[2] mu;

real<lower=0> sigma[2];

real<lower=0, upper=1> theta;

}

## model {

sigma ~ normal(0, 2);

mu[1] ~ normal(70, 10);

mu[2] ~ normal(110,10);

theta ~ beta(5, 5);

for (n in 1:N){

target += log_mix(theta,

normal_lpdf(y[n] | mu[1], sigma[1]),

normal_lpdf(y[n] | mu[2], sigma[2]));

}

}

"

Please let me know if I can provide more information/data etc to make my question clearer.

Additionally a question about Stan manual (version 2.17.0),

on page 194, for a mixture model with K mixture components the following code is given for the parameters block;

parameters {

simplex[K] theta; // mixing proportions

ordered mu[K]; // locations of mixture components

vector<lower=0>[K] sigma; // scales of mixture components

}

I think the [K] should be right after “ordered”, because Stan threw up an error, unless I am wrong, some clarification would help.