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?
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.
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?
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.