paul-buerkner / brms

brms R package for Bayesian generalized multivariate non-linear multilevel models using Stan
https://paul-buerkner.github.io/brms/
GNU General Public License v2.0
1.27k stars 183 forks source link

mismatch btw family=shifted_lognormal and rshifted_lnorm() #1449

Closed fusaroli closed 1 year ago

fusaroli commented 1 year ago

I am simulating data according to a logshifted distribution in order to test my model before running it on real data.

As expected, the shifted lognormal family in brms only accepts positive values, in other words, the shift can only be positive. However, the brms::rshifted_lnorm distribution can also generate negative values.

e.g. if I take estimated parameter values from a previous paper on reaction times and input them into the function:

rshifted_lnorm(1, meanlog = 0.14, sdlog = 0.7, shift = -0.85)

I get a consistent number of negative values.

I can get the kind of values I want by manually building a shifted lognormal:

exp(rnorm(1, mean = 0.14, sd = 0.7) - 0.85)

But shouldn't the rshifted_lnorm() produce the values that shifted_lognormal() would be able to analyze, so that we can ensure a a match between parameter values inputed and parameter values inferred?

paul-buerkner commented 1 year ago

The shift parameter should be outside of the exponent by definition. Whether we shall allow negative values in the rng is up for debate but I don't see a reason why we should dissallow that given that it has a sensible definition (even if not allowed in the corresponding brms model).

fusaroli commented 1 year ago

thanks for the answer, and the pointer to ndt being out of the exponent (whoops!).

What threw me off was: I fitted a model with brms and shifted_lognormal(), I then extracted the parameter values and ran a simulation with rshifted_lnorm() and I got quite a different distribution of values from both the original data and the predictions of the models. this was even more surprising given rshifted_lnorm() is a brms:: function.

Now I know, so not an issue for me, but maybe a note in the function?

paul-buerkner commented 1 year ago

You mean a note that the ndt is not in the exponent?

fusaroli commented 1 year ago

more that given that it allows for negative outcome values, the results will not necessarily be overlapping with those of a fitted shifted lognormal model with the same parameter values?

paul-buerkner commented 1 year ago

hmm but why would it not overlap if only positive shift is supplied? I guess reprex would help me understand

Riccardo Fusaroli @.***> schrieb am Mo., 23. Jan. 2023, 22:31:

more that given that it allows for negative outcome values, the results will not necessarily be overlapping with those of a fitted shifted lognormal model with the same parameter values?

— Reply to this email directly, view it on GitHub https://github.com/paul-buerkner/brms/issues/1449#issuecomment-1401011498, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADCW2ADPHDIALW6WCWTY3DDWT32ERANCNFSM6AAAAAAUD6D7PM . You are receiving this because you commented.Message ID: @.***>

fusaroli commented 1 year ago

sorry, I haven't managed yet, but I will. The main crux is that, as far as I can understand, the ndt parameter inferred by the shifted_lognormal() is on a log scale. So when comparing to rshifted_lnorm() there is an asymmetry. Plus it makes it harder to figure out: if it's on a log, should I just exponentiate it (I think), or should it take into account the non-linear nature of addition on a log-scale?

paul-buerkner commented 1 year ago

The ndt parameter is only on the log scale (via a log link), if it is predicted by a formula. That means you have to supply shift = exp(<log linear predictor of ndt>) if you wanted to reproduce brms' results.

fusaroli commented 1 year ago

Thanks, that solves it for me at least :-)