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

disnbin_pdf(n, k, theta, r, nn)
% disnbin_pdf.m - evaluates a Displaced Negative Binomial Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, & Kotz,
%   J. Wiley, 2005, p.235.
%
%  Created by Jim Huntley,  7/26/07
%

function [pdf] = disnbin_pdf(n, k, theta, r, nn)

%persistent lsum1 ltheta

%if(isempty(lsum1))
    sum1 = 0;
    ltheta = log(theta);
    for jx = r:nn
        %sum1 = sum1 + factorial(k+jx-1) * theta^jx / factorial(jx);
        sum1 = sum1 + exp(gammaln(k+jx) + jx*ltheta - gammaln(jx+1));
    end
    lsum1 = log(sum1);
%end

%pdf = factorial(k+n-1) * theta^n / factorial(n) / sum1;
pdf = exp(gammaln(k+n) + n*ltheta - gammaln(n+1) - lsum1);

return

Contact us