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

negbin2_pdf(n, alpha, lambda)
% negbin2_pdf.m - evaluates a Negative Binomial 2 Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp & Kotz,
%   J. Wiley, 2005, 483. 
%
%  Created by Jim Huntley,  7/17/07
%

function [pdf] = negbin2_pdf(n, alpha, lambda)

%persistent coef term

%if(isempty(coef))
    %coef = (alpha/(lambda+alpha))^alpha / gamma(alpha);
    coef = alpha*log(alpha/(lambda+alpha)) - gammaln(alpha);
    term = log(lambda/(alpha+lambda));
%end

%pdf = coef * gamma(alpha + n) * (lambda/(alpha+lambda))^n / factorial(n);
pdf = exp(coef + gammaln(alpha + n) + n*term - gammaln(n+1));
    
return

Contact us