On 10/2/12 2:47 PM, atzap wrote:
> Hi all
>
> Thanks for your help with my last problem. I've managed to get past the compiling stage but have predictably run into a
> new problem. Unfortunately, I can't seem to figure this one out and reckon other folk might run into this as well...
>
> I'm trying to standardized some parameters to a mean of zero and sd of one for use later in my model. I've tried doing
> this as follows (/this is a simplified version of my model/):
Let me try to make clearer what I mean by simplified.
I mean reduce the model to the point where it's as simple
as possible and still causes the error. For instance,
if you're having an issue with normalizing, write a model
that just does the normalization step.
That is, take something like this:
To simplify, you could reduce to only one of y, y2 and y3 and
pBound, pBound2 and pBound3.
It's not doing the same thing, but it should have the same
error behavior and it's MUCH easier to debug smaller
models because you can easily see what each piece is
doing.
The second way to simplify is to reduce the data set size.
This isn't BUGS -- we've taken more care in our inv_logit
implementation so you don't need to do things like:
> pBound[i] <- fmax(0, fmin(1, inv_logit(lambda[1]) ) );
Just
pBound[i] <- inv_logit(lambda[1]);
should suffice.
It's also not BUGS in that things like this are inefficient
in Stan:
> for(i in 1:N){
> pBound2_centered[i] <- (pBound2[i] - mean(pBound2))/sd(pBound2);
> pBound3_centered[i] <- (pBound3[i] - mean(pBound3))/sd(pBound3);
> }
It's computing the mean and sd every time through the
loop! Change this to this:
real mean_pbound_2 = mean(pBound2);
real sd_bound_2 = sd(pBound2);
for (n in 1:N)
pBound2_centered[n] <- (pBound2[i] - mean_pbound_2) / sd_bound_2;
Then, move all of this to the derived quantities block,
because nothing depends on pBound2_centered in the model.
It'll be MUCH faster with these two changes.
Having said all this, there's no reason to believe that
pBound2_centered[n] will remain between 0 and 1. If
sd_bound_2 is real low, then this value can be arbitrarily
big.
And do the same for pBound3. It'll be MUCH faster, because
the transformed params get executed each time.
I'll wait until you send us data to try your model. See
the last message I posted on asking for help.
- Bob