I was also confused by the language, but I
think you want something like this (I didn't compile it
to make sure it works, but the logic's right):
data {
int<lower=0> N; // # observations
vector[2] y[N]; // N binary observations
}
parameters {
vector[2] mu; // mean to fit
vector<lower=0>[2] sigma; // scales to fit
real<lower=-1,upper=1> rho; // correlation to fit
}
transformed parameters {
cov_matrix[2] Sigma;
Sigma[1,1] <- square(sigma[1]);
Sigma[2,2] <- square(sigma[2]);
Sigma[1,2] <- rho * sigma[1] * sigma[2];
Sigma[2,1] <- Sigma[1,2];
}
model {
for (n in 1:N)
y[n] ~ multi_normal(mu,Sigma);
}
This model has improper priors for mu and sigma.
Alternatively, you could remove sigma and rho and move
the declaration of Sigma to parameters and just fit it directly.
But as Luc pointed out in his reply, that's not the most efficient
thing to do.
As of release 2.3 (out any minute now), we have vectorized
multi-normal so you should be able to get away with a model
that's just
model {
y ~ multi_normal(mu,Sigma);
}
- Bob
On Jun 23, 2014, at 6:04 PM, Luc Coffeng <
lucco...@gmail.com> wrote:
> What are you exactly trying to do? My first intuition would be that in the model block, you should evaluate x (the random variable) rather than y (a density). Keep in mind that "sampling" statements in the model block (e.g. x ~ multi_normal(mu,sigma) simply represent adding the log-probability LP(x | mu,sigma) the log-posterior (leaving out any constants).
>
> Why do you need the density y?
>
> Also, if you want to extend the dimensions of this model, I recommend you take a look at some of the native parameter types that could make your life a lot easier (correlation matrices and cholesky factors, starting with the first). The simple constraints on rho that you have now will only work in the two-dimensional case; for higher dimensions, this approach will not guarantee that the covariance matrix is positive-definitive and will lead to a lot of Metropolis rejections and inefficient sampling. Cholesky factors have the added benefit of cranking down the computational effort through (no inversion of the full covariance matrix required).
>
>
> Luc
>
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
stan-users+...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.