My guess is that you're using a variable
somewhere that's not defined. print() is a good way to debug this.
Just print variable values before you use them and you'll usually see
where one snuck by that wasn't initialized.
The other altnernative is tha tyou have some densities that evaluate
to NaN.
Also, the model as written is going to be very inefficient because
you're computing determinants repeatedly rather than computing them
once and re-using the value. There's also a log_determinant function
that should be more stable than log(determinant(Sigma)), which is prone
to underflow or overflow.
More below on specifics.
> On Dec 17, 2014, at 4:57 PM, Greg Werbin <
ourob...@gmail.com> wrote:
>
> Thanks. I did that, and now I'm getting this error when I try to sample:
>
> Error :
>
> Initialization between (-2, 2) failed after 100 attempts.
> Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
>
> error occurred during calling the sampler; sampling not done
>
> I attached the second version of my code. I also made some other changes. Am I abusing the ability to declare variables in the model block? Only the regression coefficients are unbounded in the parameters block; surely it can't be the case that there are 100 values between -2 and 2 that are valid for one of the coefs. Or is some kind of initialization happening for other values as well?
Initialization happens for all variables declared as parameters.
We try 100 random initializations of all parameters, and in your
case, none of the 100 random initializations were valid.
This usually means variables not defined or violations of constraints,
though that's usually diagnosed with a warning message.
>
> And I guess here's a feature request: have the warning message state which parameter failed to initialize.
Making this more informative is already pending as a feature request:
https://github.com/stan-dev/stan/issues/779
But it's not going to be able to isolate a "which parameter failed to initialize"
because initialization doesn't work that way. There are two potential failure
points,
1. while reading in inits from a file or data list/function in R.
a. missing value for some parameter
b. parameter given value that violates constraint
2. while executing log density
Case (1) can be isolated to a given parameter. Case (2) arises when some
parameters aren't consistent. For instance, a, b, and c in:
a ~ uniform(b,c);
This requires a to be initialized between b and c, so there are
multiple ways to fix it by changing subsets of a,b,c. In some cases,
for some mathmetical functions, we'll get inputs to a non-primitive
function that throws an exception and that we can trap and list. If
the density just evaluates to -infinity or NaN through primitive
operations (like adding -1/0 as a term), then there's really no way for
us to catch it --- you need to add print statements to figure out when
the log density goes wrong.
- Bob