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

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

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

%persistent lcoef arg logM logQ

%if(isempty(arg))
    P = Q - 1;
    arg = -P  / (M * Q);
%    coef = exp(-M);
    lcoef = -M;
    logM = log(M);
    logQ = log(Q);
%end

%pdf = coef * Q^(-k*n) * M^n *  ...
%      hypergeom([1-n k*n],[],arg) / factorial(n);
pdf = exp(lcoef - k*n*logQ + n*logM + ...
      log(genHyper([1-n k*n],[],arg)) - gammaln(n+1));

return

Contact us