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

tweedie_pdf(x, lambda, alpha, tau)
% tweedie_pdf.m - evaluates a Tweedie Probability Density.
%   See " Regression Analysis of Quantity Data with Exact Zeros", G. K. Smyth,
%   Proc. 2nd Australia-Japan Workshop on Stochastic Models in Engineering, 
%   Technology and Management, 1996.
%
%   Vector form of PDF!!!
%
%  Created by Jim Huntley,  10/10/07
%

function [pdf] = tweedie_pdf(x, lambda, alpha, tau)

%persistent jmax llambda

%if(isempty(jmax))
    jmax = 20;
    llambda = log(lambda);
%end

pdf(1) = exp(-lambda);
for jx = 2:size(x,2)
    W = 0;
    for j = 1:jmax
        %W = W + lambda^j * (x(jx)/tau)^(j*alpha-1) / (gamma(j+1)*gamma(j*alpha));
        W = W + exp(j*llambda + (j*alpha-1)*log(x(jx)/tau) - (gammaln(j+1)+gammaln(j*alpha)));
    end
    pdf(jx) = W * exp(-x(jx)/tau - lambda) / tau;
end

return

Contact us