Hopefully Ben can jump in with some insight here.
Some comments below.
On 1/21/14, 3:42 AM, Nathan Lemoine wrote:
> I'm having trouble running a toy examples for multivariate regression. This stan code is:
>
> stanMod = """
> data{
> int<lower = 0> N;
> int<lower = 0> K;
>
> vector[K] Y[N];
> vector[N] D;
>
> cov_matrix[K] R;
> }
>
> parameters{
> vector[K] a;
> vector[K] b;
>
> cov_matrix[K] Omega;
> }
>
> transformed parameters{
> vector[K] mu[N];
>
> for(k in 1:K){
> for(i in 1:N){
> mu[i, k] <- a[k] + b[k] * D[i];
> }
> }
> }
>
> model{
> for(i in 1:N){
> Y[i] ~ multi_normal(mu[i], Omega);
> }
>
> Omega ~ inv_wishart(K+1, R);
> }
> """
We're no longer very keen on the inverse Wishart priors.
See this paper by Ben Goodrich et al.:
http://www.stat.columbia.edu/~gelman/research/unpublished/Visualization.pdf
But the model should still work.
>
> I get this warning:
>
> /Informational Message: The current Metropolis proposal is about to be rejected becuase of the following issue:/
> /Error in function stan::prob::inv_wishart_log(N4stan5agrad3varE): WW is not positive definite (7.3809879583185371e+71:0)./
> /If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the
> sampler is fine,/
> /but if this warning occurs often then your model may be either severely ill-conditioned or misspecified./
For what it's worth, that's *not* an error message. We just
don't know how to make that point any clearer to users. We don't
want to get rid of it as it's helpful, but we may have to in order
to stop freaking our users out about it.
The dump of the value is a mess here --- we really need to fix
that. But that 7e71 seems to indicate that you're getting
huge values in the covariance matrix.
The key issue is: does the error persist in most iterations? If
so, there's a problem.
I think we need to lower our tolerance for positive definiteness
somehow. We're using the Eigen built-ins to do this, and they're
very picky about what counts as positive definite.
> I'm not sure what I'm doing wrong, if this is the right way to parameterize it. This model works in JAGS so I thought
> I'd try porting it over to STAN. I've read other threads that suggest the problem is in the Omega (in particular the
> inv_wishart coming too close to not being positive definite for the covariance matrix). I've tried numerous things, such
> as changing Omega from a covariance matrix to a regular matrix (relaxing the requirement of positive definiteness I
> think).
No, you need to declare Omega as a covariance matrix. In general,
the constraints on a parameter need to match its support in the model.
This error's coming from the multivariate normal distribution, not
from the parameter itself.
The model runs, but the chains do not converge at all. I've tried removing the multivariate response and
> changing the model to:
>
> for(i in 1:N){
> for(k in 1:K){
> Y[i, k] ~ normal(mu[i], stdev[k]);
> }
> }
>
> I still get an error message:
>
> /Informational Message: The current Metropolis proposal is about to be rejected becuase of the following issue:/
> /Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is -3.364634555144618:0, but must be > 0!/
> /If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the
> sampler is fine,/
> /but if this warning occurs often then your model may be either severely ill-conditioned or misspecified./
>
> but the model runs and the chains do converge. I'm not crazy about this because a) I still get error messages,
See above.
b) I'm
> not modeling the covariance between response variables, which is preferable,
Right --- this one's the deal breaker.
> and c) the parameter estimates are just too
> similar (almost identical) for a[1]:a[2] and b[1]:b[2], so I'm not sure I trust it.
I'd recommend simulating data from the model and seeing
if you can recover the parameters.
> I've tried reparameterizing to the Cholesky decomposition as in the manual, but most examples I've found are for
> multivariate normal of parameters, not a response, and I'm pretty sure I did it wrong.
You can use the Cholesky decomposition on parameters.
It's just going in as an argument to the multivariate normal.
> Am I screwing something up?
Not that I can see from the model, but I don't know what your data
are like. If the covariance really does involve terms on the scale of
7e71, there may be a problem with the data.
- Bob