Hypergeometric random numbers
R = distfun_hygernd(M,k,N) R = distfun_hygernd(M,k,N,[m,n]) R = distfun_hygernd(M,k,N,m,n)
a n-by-m matrix of doubles, the total size of the population . M belongs to the set {0,1,2,3........}
a n-by-m matrix of doubles, the number of successful states in the population . k belongs to the set {0,1,2,3.......M-1,M}
a n-by-m matrix of doubles, the total number of draws in the experiment . N belongs to the set {0,1,2,3,.......M-1,M}
a 1x1 matrix of floating point integers, the number of rows of R
a 1x1 matrix of floating point integers, the number of columns of R
a matrix of doubles, the random numbers in the set {0,1,2,...,min(N,k)}.
Generates random variables from the Hypergeometric distribution function.
Any scalar input argument is expanded to a matrix of doubles of the same size as the other input arguments.
The algorithm is based on the inversion of the CDF.
// Check R = distfun_hygernd(M,k,N,v) computed = distfun_hygernd(80,50,30,[4 5]) // Check mean and variance M = 80; k = 50; N = 30; n = 50000; computed = distfun_hygernd(M,k,N,[1 n]); c = mean(computed(1:n)) d = st_deviation(computed(1:n)) [M,V] = distfun_hygestat(M,k,N) // Check actual distribution M=80; k=50; N=30; nsamples=10000; R=distfun_hygernd(M,k,N,1,nsamples); h=scf(); distfun_inthisto(R); h.children.children(1).children.background=-2; [Me,Va] = distfun_hygestat(M,k,N); x=int(Me-3*sqrt(Va)):int(Me+3*sqrt(Va)); y=distfun_hygepdf(x,M,k,N); plot(x,y,"ro-"); xtitle("Hypergeometric Random Numbers","X","Frequency") legend(["Empirical","PDF"]); | ![]() | ![]() |
http://en.wikipedia.org/wiki/Hypergeometric_distribution