Closed ecod3r closed 10 years ago
Hi, try instead:
parameters {
cov_matrix[K] Sigma;
}
Thank you very much, that solved the problem!
It may save you (and some other clueless users such as myself) some time if it were stressed the need to use that type either in a note where the function is listed, or perhaps via a warning when the model is compiled.
On May 22, 2014, at 6:45 AM, ecoskian notifications@github.com wrote:
Thank you very much, that solved the problem!
It may save you (and some other clueless users such as myself) some time if it were stressed the need to use that type either in a note where the function is listed, or perhaps via a warning when the model is compiled.
That would be nice, but it's not so easy because there's no way for us to know at compile time if a user's constructed a proper symmetric, positive-definite matrix.
In general, we're trying to more heavily stress that in general the constraints on a parameter need to match its support. That's why if you have
Sigma ~ inv_wishart(...),
you need to ensure Sigma is symmetric, and positive definite, which can be achieved by declaring Sigma to be a cov_matrix parameter, or by constructing it as such. For instance, you can construct a 2 x 2 covariance matrix a out of a correlation and two scales:
data { cov_matrix[2] Omega; }
parameters {
vector
model { matrix[2,2] a;
a[1,1] <- square(sigma1); a[2,2] <- square(sigma2); a[1,2] <- sigma1 * sigma2 * rho; a[2,1] <- a[1,2];
a ~ inv_wishart(Omega);
}
and then a is OK to be on the left-hand side of an inv_wishart sample.
Note that the scale and correlation parameters themselves need to be constrained here.
— Reply to this email directly or view it on GitHub.
I am trying to use an inverse Wishart prior on a covariance matrix, however that is failing miserably no matter how easy the model I try. I have had problems with something as basic as
Where K = 2, W = [[1, 0], [0,1]], mu = [0, 0], y = [1, -0.5]. Note that I have fixed nu to 2.0. The errors I get are either look like the following:
and
Eventually, Stan gives up printing