Code covered by the BSD License  

Highlights from
Generation of Random Variates

image thumbnail

Generation of Random Variates

by

 

generates random variates from over 870 univariate distributions

nbinnbin_pdf(n, Q, QQ, k, M)
% nbinnbin_pdf.m - evaluates a Negative Binomial Negative Binomial Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp & Kotz,
%   J. Wiley, 2005, 334. 
%
%  Created by Jim Huntley,  7/20/07
%

function [pdf] = nbinnbin_pdf(n, Q, QQ, k, M)

%persistent lcoef arg QQM ratio lratio

%if(isempty(arg))
    P = Q - 1;
    PP = QQ - 1;    
    arg = P * QQ / (PP * Q);
    QQM = QQ^(-M);
    lcoef = log(QQM) - gammaln(M);
    ratio = PP / (QQ * Q^k);
    lratio = log(ratio);
%end

pdf = QQM;
if(n > 0)
    %pdf = coef * gamma(M+n) * ratio^n *  ...
    %      hypergeom([1-n k*n],1-M-n,arg) / factorial(n);
    pdf = exp(lcoef + gammaln(M+n) + n*lratio + ...
          log(genHyper([1-n k*n],1-M-n,arg)) - gammaln(n+1));
end

return

Contact us