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

invbinom_pdf(n, nn, p)
% invbinom_pdf.m - evaluates an Inverse Binomial Probability Density.
%   See "A Generalization of the Inverse Trinomial", K. Aoyama and K. Shimizu, Keio U., 
%   23 June, 2005.
%
%  Created by Jim Huntley,  8/31/06
%

function [pdf] = invbinom_pdf(n, nn, p)

%persistent q logp logq

%if(isempty(q))
    q = 1 - p;
    logp = log(p);
    logq = log(q);
%end

%nfac = factorial(n);
nfac = gammaln(n+1);

%pdf =  nn * nfac * p^((nn+n)/2) * q^((n-nn)/2) / (factorial(fix((n+nn)/2)) ...
%     * factorial(fix((n-nn)/2)) * n);
pdf =  nn * exp(nfac + ((nn+n)/2)*logp + ((n-nn)/2)*logq - (gammaln((n+nn)/2 + 1) ...
     + gammaln((n-nn)/2 + 1))) / n;

return

Contact us