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

gengegen_pdf(n, alpha, bet, lambda, m)
% gengegen_pdf.m - evaluates a generalized Gegenbauer Probability Density.
%   See "Generalized Gegenbauer Distribution Revised ", G. Wimmer & G. Altmann, 
%   Indian Journal of Statistics, 1995, V. 57, Ser. B. Pt 3, p.452.
%
%  Created by Jim Huntley,  9/7/04
%

function [pdf] = gengegen_pdf(n, alpha, bet, lambda, m)

%persistent coef loga logb

%if(isempty(coef))
	coef = (1 - alpha - bet)^lambda;
    loga = log(alpha);
    logb = log(bet);
%end

pdf = coef;
if(n > 0)
    intlim = fix(n/m) + 1;
    sum1 = 0;
    for ji = 1:intlim       
        aflam = lambda;
        for jl = 1:n-m*(ji-1)+ji-2
            aflam = aflam * (lambda+jl);
        end
        %sum1 = sum1 + aflam * alpha^(n-m*(ji-1)) * bet^(ji-1) / ...
        %            (factorial(ji-1) * gamma(n-m*(ji-1)+1));
        sum1 = sum1 + exp(log(aflam) + (n-m*(ji-1))*loga + (ji-1)*logb - ...
                    (gammaln(ji) + gammaln(n-m*(ji-1)+1)));  
    end
    pdf = coef * sum1;
end

return

Contact us