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

poispas_pdf(n, theta, P, k, nmax)
% poispas_pdf.m - evaluates a Poisson Pascal Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%   J. Wiley, 2005, p.414.    
%
%  Created by Jim Huntley,  9/06/07
%

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

%persistent coef Q P0 ratio lratio term jmax

%if(isempty(coef))
    jmax = max(10,4*theta);             % Heuristic. See 'test_poispas.m'.
    Q = 1 + P;
    P0 = exp(theta*(Q^(-k)-1)) ;
    coef = theta * k * P / (Q^(k+1));
    ratio = P / Q;
    lratio = log(ratio);
    term = log(theta/Q^k);
%end

if(n == 0) 
    pdf = P0;
elseif(n > 0)
    sumj = 0;
    for j = 1:jmax
        %sumj = sumj + exp(gammaln(k*j+n) + j*log(theta/Q^k) - (gammaln(j+1)+gammaln(k*j)));
        sumj = sumj + exp(-theta + n*lratio + gammaln(k*j+n) + j*term - ...
               (gammaln(j+1)+gammaln(k*j)+gammaln(n+1)));
    end
    %pdf = exp(-theta + n*log(ratio) + log(sumj) - gammaln(n+1));
    pdf = sumj;
end

return

Contact us