User-defined generalised beta distribution as prior makes no difference from flat prior

Hi all,

I’m trying to define my own generalised beta distribution to be used as prior distribution. However it doesn’t seem to make a difference from the result using flat priors, in fact, did not improve the parameter estimation. I therefore wonder if I have written my generalised beta distribution correctly? Can anyone with better statistics knowledge than myself please advise?

mystancode2.stan (6.0 KB)

Results using flat prior vs informative prior appear to be similar

Thank you.

Best regards,
Huiying

wonder if I have written my generalised beta distribution correctly?

The custom _lpdf statements should return a log of a probability (I think _lpdf has replaced _log). Check out Aki’s case study: http://mc-stan.org/users/documentation/case-studies/gpareto_functions.html

However it doesn’t seem to make a difference from the result using flat priors, in fact, did not improve the parameter estimation.

Getting the same answer regardless of your prior could also be seen as an advantage. But fix the lpdf thing first and then see if anything changes.

That’s the log of a density—the “lpdf” stands for “log probability density function”.

This is more a computer science problem. Do you have another implementation of this density somewhere? If so, run tests on your implementation to make sure you’re getting the right answers. You can do this with generated quantities inside Stan or you can use the standalone function options in R.

Hi guys,

Thanks for the responding and for the comments.

I replaced _log with _lpdf, and it doesn’t seem to affect output.

or1 ~ genbeta(20,20) in the model block is the only place where it’s implemented.

If I were to test it in generated quantities inside Stan, I presume I need to have another separate user-defined function ending with _rng like what is done by Aki’s case study? http://mc-stan.org/users/documentation/case-studies/gpareto_functions.html However, with my user-defined functions. I do not quite sure how to derive _rng.

So far, I have only tested my user-defined function by plotting graphs with xlimit 0 to 2, but I doubt this is sufficient?

Huiying

Using _lpdf will just ensure your code keeps working in Stan 3. It shouldn’t change behavior.

You don’t necessarily need an RNG function. If you have the density function, you can generate MCMC random variates by declaring a parameter and then giving it a sampling statement (or target increment). It’s just less efficient than having the RNG.

I meant exposing the function in R (or Python) and testing it with known inputs and outputs. You can do that in Stan in generated quantities, but you don’t need RNGs for that.