Code covered by the BSD License  

Highlights from
Generation of Random Variates

image thumbnail

Generation of Random Variates

by

James Huntley (view profile)

 

generates random variates from over 870 univariate distributions

dblnegbin_pdf(n, p, p1, m, nn)
% dblnegbin_pdf.m - evaluates a Double Negative Binomial Probability Density.
%   See "Lagrangian Probability Distributions", P.C. Consul & F. Famoye,
%   Birkhauser, 2006, Table 2.4.
%
%  Created by Jim Huntley,  12/03/08
%

function [pdf] = dblnegbin_pdf(n, p, p1, m, nn)

%persistent q q1 logp1 logq coef

%if(isempty(q))
    q = 1 - p;
    q1 = 1 - p1;
    %coef = (q-m*p) * q1^nn / gamma(nn);
    coef = log(q-m*p) + nn*log(q1) - gammaln(nn);
    logp1 = log(p1);
    logq = log(q);
%end

%pdf =  coef * p1^n * q^(m*n-1) * gamma(nn+n) * ...
%       hypergeom([-n,m*n],1-n-nn,p/p1) / gamma(n+1);
pdf =  exp(coef + n*logp1 + (m*n-1)*logq + gammaln(nn+n) + ...
       log(genHyper([-n m*n],1-n-nn,p/p1)) - gammaln(n+1));          

return

Contact us