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

normexpt_pdf(x, mu, sigma, k1, k2)
% normexpt_pdf.m - evaluates a Normal Exponential T Probability Density.
%   See "Statistical Modeling Using GAMLSS in R", R. Rigby & M. Stasinopoulos, 
%   1 June, 2006.
%
%   Vector Form of PDF !!!
%
%  Created by Jim Huntley,  11/19/07
%

function [pdf] = normexpt_pdf(x, mu, sigma, k1, k2)

%persistent c k1k2 k1sq

%if(isempty(c))
    k1k2 = k1 * k2;
    k1sq = k1 * k1;
    c1 = sqrt(2*pi) * (1 - 2*gaus_cdf(-k1,0,1));
    c2 = 2 * exp(-0.5*k1sq) / k1;
    c3 = 2* exp(-k1k2+0.5*k1sq) / (k1 * (k1k2-1));
    c = 1 / (c1 + c2 + c3);
%end

sx = size(x,2);
z = (x - mu) ./ sigma;

for jx = 1:sx
    absz = abs(z(jx));
    if(absz <= k1)
        pdf(jx) = exp(-0.5*z(jx)^2);
    elseif(absz > k1 && absz <= k2)
        pdf(jx) = exp(0.5*k1sq-k1*absz);
    elseif(absz > k2)
        pdf(jx) = exp(-k1k2*log(absz/k2) -k1k2 +0.5*k1sq);
    end
end

pdf = pdf .*c ./ sigma;

return

Contact us