Code covered by the BSD License  

Highlights from
Generation of Random Variates

image thumbnail

Generation of Random Variates

by

James Huntley (view profile)

 

generates random variates from over 870 univariate distributions

formel2_pdf(n, theta, q, k)
% formel2_pdf.m - evaluates a Formel II Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp & Kotz,
%   J. Wiley, p.241, 2005 (NOT NORMALIZED). 
%
%  Created by Jim Huntley,  05/08/07
%

function [pdf] = formel2_pdf(n, theta, q, k)

%persistent logt klogomq ratio

%if(isempty(logt))
    logt = log(theta);
    klogomq = k*log(1-q);
    ratio = q/theta;
%end

%coef = exp(-theta) * theta^n * (1-q)^k / (factorial(k-1) * factorial(n));
%coef = exp(-theta + n(jn)*logt + klogomq - (gammaln(k) + gammaln(n(jn)+1)));
coef = exp(-theta + n*logt - gammaln(n+1) - q); % Includes Normalization (not in REF)!!!

sum1 = 0;
for jn = 1:n+1
    sum1 = sum1 + binomial_coef(n,jn-1) * ratio^(jn-1);
end

pdf = coef * sum1;

return


Contact us