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

boxcoxpe_pdf(x, mu, sigma, nu, tau)
% boxcoxpe_pdf.m - evaluates a Box Cox Power Exponential Probability Density.
%   See BCPE, "The GAMLSS Package", 
%   http://cran.r-project.org/doc/packages/gamlss.pdf, p.9.
%
%   Vector Form of PDF !!!
%
%  Created by Jim Huntley,  11/19/07
%

function [pdf] = boxcoxpe_pdf(x, mu, sigma, nu, tau)

%persistent coef c anu pxcdfend

%if(isempty(coef))
    %c = sqrt(2^(-2/tau) * gamma(1/tau) / gamma(3/tau))
    %coef = tau  / (mu^nu * sigma * c * gamma(1/tau) * 2^(1+1/tau))
    c = sqrt(exp(log(2^(-2/tau)) + gammaln(1/tau) - gammaln(3/tau)));
    coef = log(tau) - nu*log(mu) - log(sigma*c*2^(1+1/nu)) - gammaln(1/tau);
    anu = abs(nu);
    % Normalization.
    ny = 1000;
    ymin = -10;
    ymax = 1/(sigma*anu);
    dy = (ymax-ymin) / (ny-1);
    y = ymin:dy:ymax;
    pxcdf = powexp_cdf(y,0,1,tau);
    pxcdfend = pxcdf(end);
%end

if(nu == 0)
    z = log(x./mu) ./ sigma;
else
    z = ((x./mu).^nu - 1) ./ (nu * sigma);
end

pdf = exp(coef + (nu-1).*log(x) -0.5.*((abs(z./c)).^tau));

pdf = pdf ./ pxcdfend;

return

Contact us