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

binomsum_pdf(n, N1, p1, N2, p2)
% binomsum_pdf.m - evaluates a Binomial Sum Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%   J. Wiley, p.142, 2005. 
%
%  Created by Jim Huntley,  11/21/06
%

function [pdf] = binomsum_pdf(n, N1, p1, N2, p2)

% Initializations.
theta1 = p1 / (p1-1);
theta2 = p2 / (p2-1);
pd(1) = (1-p1)^N1 * (1-p2)^N2;
pd(2) = pd(1) * (N1*p1/(1-p1) + N2*p2/(1-p2));

if(n == 0)
    pdf = pd(1);
elseif(n == 1)
    pdf = pd(2);
elseif(n > 1)
    for jn = 2:n
        pd(jn+1) = (pd(jn)*((jn-N1-1)*theta1+(jn-N2-1)*theta2) + ...
                   pd(jn-1)*(N1+N2-jn+2)*theta1*theta2) / jn;
    end
    pdf = pd(jn+1);
end

return


Contact us