# Sampling from the Generalized Beta of the Second Kind in Fortran

I need to sample from the generalized beta of the second kind (GB2) distribution (McDonald, 1984, Econometrica). Its PDF has the form $$f_{a,b,p,q}(x) = \frac{|a|x^{ap-1}}{b^{ap}B(p,q)(1+(x/b)^a)^{p+q}}.$$ Its CDF does not have a closed form, so I cannot use an inverse transform method. Does anyone know how to sample from this distribution or know of a Fortran random number generator library that contains this distribution?

None of the packages in the netlib.org/random library contain the GB2.

• I looked up GB2 on wikipedia and put the PDF directly into the question to make it easier to read. Can you please check that this is the right distribution and the right expression? Nov 15 '14 at 11:41
• If the inverse transform method is inapplicable, you can try to use the acceptance-rejection method. How efficient it would be, though, depends on what proposal distribution you choose. Nov 15 '14 at 11:50
• This is the correct distribution and expression. Thanks for clarifying. Nov 17 '14 at 21:06

If you're interested in the distribution for fixed values of $a,b,p,q$, you can compute and tabulate the cumulative distribution by quadrature. Since it's only a 1d function for fixed parameters, you can compute the cumulative function for fixed values of $x$ with pretty high accuracy, connect these points by a polynomial approximation, and then use this surrogate function for sampling.