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

binnegbin_pdf(n, p, m, P, k)
% binnegbin_pdf.m - evaluates a Binomial Negative Binomial Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%   J. Wiley, p.333, 2005. 
%
%  Created by Jim Huntley,  11/27/06
%

function [pdf] = binnegbin_pdf(n, p, m, P, k)

%persistent q Q lQ lP arg gamlnk

% Initializations.
%if(isempty(q))
    q = 1 - p;
    Q = 1 + P;
    lQ = log(Q);
    lP = log(P*q^m);
    arg = -p*Q/(q*P);
    gamlnk = gammaln(k);
%end

%pdf = gamma(k+n) * (P*q^m)^n * hypergeom([1-n -m*n],1-n-k,-p*Q/(q*P)) ...
%      / (gamma(k)*Q^(k+n)*factorial(n));
arga1 = 1 - n;
arga2 = -m * n;
argb = 1 - n - k;
pdf = exp(gammaln(k+n) + n*lP + log(genHyper([arga1 arga2],argb,arg)) ...
            - (gamlnk + (k+n)*lQ + gammaln(n+1)));

return


Contact us