I can make several suggestions on model and implementation.
First, don't use any of these priors:
mu_eta[K] ~ normal(0, 100);
sigmasq_y ~ inv_gamma(0.001, 0.001); //y residual error variance drawn from prior
Psi~ inv_wishart(3, Omega); //cov matrix among etas drawn from prior
They're all problematic for both computational and statistical
reasons. The fat normal and inverse gamma are just too fat.
the inverse Wishart usually doesn't make any sense. These priors
just get used by BUGS/JAGS becaus they're conjugate. We discuss
recommended alternatives in the manual chapter on regression.
We recommend a Cholesky-parameterized, scaled correlation matrix with
an LKJ prior for Psi, and at least weakly informative priors for the
others. There are references as to why in the manual, too.
Computationally, you probably don't want to define all those variables
as transformed parameters, because then they get written out at each
iteration.
I'm not sure what you're trying to do, but this doesn't make sense:
> for (n in 1:N)
> for (k in 1:K)
> tt[k]<-log(pi[k])+multi_normal_log(eta[n],mu_eta[k],Psi);
It redefines tt N times, then uses the last one (n == N) going forward.
I'm lost as to what this one's doing:
> for (n in 1:N){
> log_q_z[n]<-log(pi);
> for (t in 1:T)
> for(k in 1:K)
> log_q_z[n,k] <- log_q_z[n,k]+normal_log(y[n,t], eta[n, 1] +eta[n, 2]*x[t] +eta[n,3]*q[t], sigma_y);
The variables are:
// x : T x 1
// pi : K x 1
// eta: : N x 3
// q : T x 1
// sigma_y : 1
so there's nothing in that loop other that varies by k other than log_q_z.
If that's really what you want (I don't really have time to figure it out),
then you're far better of using vectorization on the normal_log over t
outside of the loop over K --- as is, you're doing way too much extra
work.
So that'd be something like this:
{
vector[K] log_pi;
log_pi <- log(pi);
for (n in 1:N) {
real lp;
lp <- normal_log(y[n],
eta[n,1] + eta[n,2] * x + eta[n,3] * q,
sigma_y);
for (k in 1:K)
log_q_z[n,k] <- log_pi[k] + lp;
}
}
But I'm not convinced you're doing what you want to do here.
- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> For more options, visit
https://groups.google.com/d/optout.
> <gmmq1.dat>