[expanded subject --- Michael see below]
On Aug 10, 2014, at 5:40 PM, Jonathan Gilligan <
jonathan...@gmail.com> wrote:
> Thanks.
>
> I was going to ask a followup about the "r=1" case, but wanted to test the code myself first.
>
> This is a pretty standard utility function from economics, describing constant relative risk-aversion and plausible values span 1. The function is weird because what I really want is to know if f(x,r) > f(y,r) for some parameter r and data x: bernoulli_logit( scale * (f(x,r) - f(y,r))), where f(x,r) = x^(1-r) / (1-r) . But the function blows up near r=1 because it divides by zero. The special case for "r=1" is to avoid this singularity, and is the standard treatment in the econ literature. I probably should deal with the measure-zero issue by adjusting to use a neighborhood:
>
> if (fabs(r=1.0) < epsilon)
> return log(x);
> else
> return pow(x, 1.0 - r) / (1.0 - r);
>
this has to be coded with "r == 1.0", but the compiler
will tell you that.
> r > 1 (x to a negative power) is not an issue because x >= 0 and I can avoid the x=0 case by adding a small number to make x strictly greater than 0.
If you have a constraint lower=0 on x, then x will only be 0 if you initialize to
0 (which is an error in most cases) or if there's an underflow.
> If I could avoid r = 1, that would be nice, but the literature reports values that range from 0 to 40 or higher for different conditions and based on a lot of that literature, r=1 is a pretty reasonable mode for a prior. A published MLE of the data set I'm working with gives a 95% CI of 0.67 to 1.02 for r.
>
> How badly will this function screw up Stan's ability to calculate Jacobians? Do you have any suggestions for how to code something like this efficiently in Stan?
Maybe Michael will know.
I'm not sure where you mean. The only Jacobian (determinants) we compute
are for the transforms, and that doesn't depend on anything past the
parameters block.
It will screw up gradients at r = 1 as the function's discontinuous.
I'm not sure what happens under the crossing, because of the sign change.
With a fixed x and r = 1 + epsilon, you get a really big value, whereas
with a fixed x and r = 1 - epsilon, you get a really small value. So the
function's discontinuous at r, which is a problem. It's impossible to
simulate a particle moving according to the Hamiltonian when it has to
cross a discontinuous boundary. In fact, we want the derivatives to
be continuous, as well as the function (which is why fabs() can be problematic).
- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
stan-users+...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.