Is this Jacobian correction right? for --> (y_data - y_regressed_parameter) ./ x_real_parameter;

91 views
Skip to first unread message

Jan

unread,
Aug 8, 2016, 2:48:54 AM8/8/16
to Stan users mailing list

Hello,

in reference to few discussion on the impossibility (I believe so far) to properly constrain linear regressions based on lognormal, gamma and other only positive priors, I have restructured the model to have as transformed parameter the slope, which in my case is the only not hardly constrained variable (however I know it should be [0-1]).


Therefore with a regression of this form : y_regressed = y_data - a_parameter * x_real_parameter

I need to find the Jacobian transform for

transformed parameters{
  a[N] = (y_data[N] - y_regressed_parameter[N]) ./ x_real_parameter[N];
}
model {
a[N] ~ normal(a_parameter, sigma);
}

Is the following one correct? from the Quotient Rule


function(f/g) -->  
(f’ g − g’ f )/g2

for(n in 1:N) target += log( fabs (   ( -x_real_parameter[N] - y_data[N] + y_regressed_parameter[N] )   /   x_real_parameter[N]^2   ) );


Thanks a lot!

Bob Carpenter

unread,
Aug 8, 2016, 9:55:57 PM8/8/16
to stan-...@googlegroups.com
If it's a function mapping R^2 to R^2, then the Jacobian is
a matrix. The manual explains how to compute Jacobians
in the transforms for constrained parameters chapter near
the end.

There's no reason you can't have positive-constrained
noise have a positive-constrained distribution, but
that seems like a very unusual kind of noise.

- 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.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Jan

unread,
Aug 8, 2016, 10:54:02 PM8/8/16
to Stan users mailing list
Thanks for your answer. 

Yes, you might be right. Let me show few plots that will help in your evaluation:

What I have is a mix of two lognormal/gamma distributions

observed_ln = ln_1 * proportion_1 + ln_2 * (1 - proportion_1)

ln_1 is provided as data, and the parameter is proportion_1

my untrasformed data look like this


as you can see the Y noise is lognormal/gamma like (tested)


If I try to transform to log before doing the regression


log(y) ~ normal(mu + proportion_1 * x, ..) ; + Jacobian


OR (equivalent?)


y ~ lognormal(mu + proportion_1 * x, ..)


the data looks like this, the noise starts as normal but goes to a gamma-like straight away



While if I regress first and do the log,  


log(y - proportion_1 * x) ~ normal(mu, ..)


yes the noise now becomes normal




But now the problem of impossibility of constrain for 


y - proportion_1 * x > 0 && x > 0 


when proportion_1 and x are parameters, with


x ~ lognormal(.. , ..)


arises (according to few previous discussions in the forum).


What do you think? I imagine there are two solutions


1) the one propose above

2) use y - proportion_1 * x ~ lognormal(mu, ..) with a proper Jacobian tranformation and with a proper control somehow that the left side stays positive.


Thank

Jan

unread,
Aug 8, 2016, 11:01:01 PM8/8/16
to Stan users mailing list
I have a quite peculiar linear regression but with a lognormal/gamma noise model.

observed_ln = ln_1 * proportion_1 + ln_2 * (1 - proportion_1)



Please have a look to this tread https://groups.google.com/forum/#!category-topic/stan-users/general/jQKzA6vfgtU . Few questions are about solving the same problem in different ways


On Tuesday, August 9, 2016 at 11:55:57 AM UTC+10, Bob Carpenter wrote:

Bob Carpenter

unread,
Aug 11, 2016, 8:37:07 AM8/11/16
to stan-...@googlegroups.com
I hope someone else can take a shot at this one, because
I'm still confuse about what's going on with all the transforms
and which model you're trying to fit and what the problem is
that you're having.

Whatever is going on, I don't think you want to be multiplying
two parameters, as that leads to nasty banana-shaped non-identifiabilities.

- Bob



> On Aug 9, 2016, at 4:54 AM, Jan <mangiol...@gmail.com> wrote:
>
> Thanks for your answer.
>
> Yes, you might be right. Let me show few plots that will help in your evaluation:
>
> What I have is a mix of two lognormal/gamma distributions
>
> observed_ln = ln_1 * proportion_1 + ln_2 * (1 - proportion_1)
>
> ln_1 is provided as data, and the parameter is proportion_1
>
> my untrasformed data look like this
>
>
>
>
>
> as you can see the Y noise is lognormal/gamma like (tested)
>
>
>
> If I try to transform to log before doing the regression
>
>
>
> log(y) ~ normal(mu + proportion_1 * x, ..) ; + Jacobian
>
>
>
> OR (equivalent?)
>
>
>
> y ~ lognormal(mu + proportion_1 * x, ..)
>
>
>
> the data looks like this, the noise starts as normal but goes to a gamma-like straight away
>
>
>
>
>
>
>
> While if I regress first and do the log,
>
>
>
> log(y - proportion_1 * x) ~ normal(mu, ..)
>
>
>
> yes the noise now becomes normal
>
>
>
>
>
>
>
>
>
Reply all
Reply to author
Forward
0 new messages