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

tweedpois_pdf(n, alpha, delta, theta, nn)
% tweedpois_pdf.m - evaluates a Tweedie Poisson Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp and Kotz,
%   J. Wiley, p.482, 2005.
%
%   Vector form of PDF!!!
%
%    Created by:    J. Huntley,  10/12/2007
%

function [pdf] = tweedpois_pdf(n, alpha, delta, theta, nn)

%persistent P0 c ldelta lthp1

%if(isempty(c))    
    P0 = delta * (theta^alpha - (theta+1)^alpha) / alpha;
    c(1:nn,1:nn) = 0;
    for jn = 1:nn
        c(jn,1) = exp(gammaln(jn-alpha) - gammaln(1-alpha));
    end
    for jn = 1:nn
        for i = 2:jn
            if(i == jn)
                c(jn,i) = 1;
            else
                c(jn,i) = c(jn-1,i-1) + c(jn-1,i)*((jn-1)-i*alpha);
            end
        end
    end
    ldelta = log(delta);
    lthp1 = log(theta+1);
%end

if(n == 0)
    pdf = exp(P0);
elseif(n > 0)
    sumi = 0;
        for i = 1:n
            sumi = sumi + exp(log(c(n,i)) + i*ldelta + (i*alpha-n)*lthp1);        
        end
    pdf = exp(P0 + log(sumi) - gammaln(n+1));
end

return

Contact us