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

poisnbin_pdf(n, theta, P, k)
% poisnbin_pdf.m - evaluates a Poisson Negative Binomial Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%   J. Wiley, 2005, p.333. 
%
%  Created by Jim Huntley,  9/10/07
%

function [pdf] = poisnbin_pdf(n, theta, P, k)

%persistent Q coef opk term1

%if(isempty(Q))
    Q = 1 + P;
    coef = k * P * Q^(-k-1);
    opk = 1 + k;
    term1 = Q^(-k);
%end

if(n == 0)
    pdf = term1;
elseif(n > 0)
    arg0 = theta * n;
    argn = -P / (arg0*Q);
    pdf = coef * exp((n-1)*log(arg0) - arg0 + ...
              log(genHyper([1-n opk], [], argn)) - gammaln(n+1));
end

return

Contact us