> On Dec 1, 2015, at 8:16 PM, Sachinthaka Abeywardana <
sachin.ab...@gmail.com> wrote:
>
> So I made the model as Bob suggested and looks like:
> parameters {
> simplex[k] pi;
> simplex[k+1] theta;
> }
> transformed parameters{
> positive_ordered[k] lambda;
> lambda <- a + head(cumulative_sum(theta), k) * (b - a);
> }
> model {
> lambda~exponential(1);
> ....
> }
>
> (The entire model is attached in the files below).
>
> So I have a few questions on this even though it works:
I'm glad it works.
> 1. Is it valid to do lambda~exponential(1). The reason I ask this is because lambda depends on theta (a simplex). Also isn't the model going to try to put a uniform distribution on theta, even though I specified the prior on lambda?
What matters if the final log density. Theta is
involved in both a default uniform prior over the simplex,
plus the distribution on lambda, which is defined in terms
of theta. Changing theta affects the value of lambda, which
in turn affects the exponential distribution's contribution
to the log density.
> Basically how does stan consolidate the fact that it has an exponential prior and the restrictions placed by the transformed parameters block (a rough explanation would be fine).
The way it really works is through HMC. There's an algorithm
section in the manual.
> 2. I got the following warning and not sure what it means:
> Warning (non-fatal):
> Left-hand side of sampling statement (~) may contain a non-linear transform of a parameter or local variable.
> If so, you need to call increment_log_prob() with the log absolute determinant of the Jacobian of the transform.
> Left-hand-side of sampling statement:
> lambda ~ exponential(...)
This you have to worry about. Hence the warning.
Because you apply a change of variables, you have to apply
a Jacobian adjustment. That's also described thoroughly in
the manual.
In this case, you're lucky, because a and b are constants
and the cumulative sum has a unit Jacobian determinant, so it's
a constant linear transform of a unit Jacobian, so there's no
affect on the posterior from the change of variables.
So you don't need to do anything.
I still think the Dirichlet on the bins and maybe an exponential
on the overall scale makes a lot of sense here, especially if
these are cutpoints for an ordinal regression.
> 3. Numerical problems:
> validate transformed params: lambda is not a valid ordered vector. The element at 2 is 0.00089928, b 2
> validate transformed params: lambda is not a valid ordered vector. The element at 2 is 3.72184, but 1
> Does the above mean that there were 3 numerical problems. Apologies if I was not meant to ask this on the
Looks like your response got cut off here.
How often does this turn up? I don't see how lambda can fail
to be an ordered vector. Is a < 0 perhaps?
- Bob
> <model2.stan><lambdaStan1.R><y250.csv>