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

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

function [pdf] = negbin1_pdf(n, lambda, P)

%persistent coef term

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

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

Contact us