# FNChygernd

FNChygernd random arrays from the Fisher non central hypergeometric distribution.

## Syntax

• r=FNChygernd(M,K,n,odds)example
• r=FNChygernd(M,K,n,odds, mm)example
• r=FNChygernd(M,K,n,odds, mm,nn)example
• r=FNChygernd(M,K,n,odds, mm,nn,oo)example

## Description

 r =FNChygernd(M, K, n, odds) Generate a random number from Wallenius non central hypergeometric distribution.

 r =FNChygernd(M, K, n, odds, mm) A difficult example which needs to avoid underflow/overflow.

 r =FNChygernd(M, K, n, odds, mm, nn) Generate a matrix of size mmxnn of random number from Fisher non central hypergeometric distribution.

 r =FNChygernd(M, K, n, odds, mm, nn, oo) Generate a 3D array of size mmxnnxoo of random number from Fisher non central hypergeometric distribution.

## Examples

expand all

### Generate a random number from Wallenius non central hypergeometric distribution.

M=80; total number of balls n=10; number of balls taken odds=3; Prob. of red balls vs other color balls K=50; Number of red balls in the urn samplesize=100000; Sample size to extract

edges=(0:(n+1))';
% Generate a random number from the distribution above
x=FNChygernd(M,K,n,odds);
disp(x)

### A difficult example which needs to avoid underflow/overflow.

M=8000; total number of balls n=2000; number of balls taken odds=3; Prob. of red balls vs other color balls K=5000; Number of red balls in the urn Generate an array of size 2x3x5 of random numbers from the distribution above

mm=2;   nn=3; oo=5;
rng(12345)
X=FNChygernd(M,K,n,odds);
disp(X)

### Generate a matrix of size mmxnn of random number from Fisher non central hypergeometric distribution.

M=80; total number of balls n=10; number of balls taken odds=3; Prob. of red balls vs other color balls K=50; Number of red balls in the urn Generate a matrix of size 3x5 of random numbers from the distribution above

mm=3;
nn=5;
X=FNChygernd(M,K,n,odds, mm,nn);
disp(X)

### Generate a 3D array of size mmxnnxoo of random number from Fisher non central hypergeometric distribution.

M=800; total number of balls n=200; number of balls taken odds=3; Prob. of red balls vs other color balls K=500; Number of red balls in the urn Generate an array of size 2x3x5 of random numbers from the distribution above

mm=2;   nn=3; oo=5;
X=FNChygernd(M,K,n,odds, mm,nn,oo);
disp(X)

## Related Examples

expand all

### Comparison density and relatived frequencies based on random numbers.

close all
M=100; % total number of balls
n=10;  % number of balls taken
odds=2; % Prob. of red balls vs other color balls
K=50; % Number of red balls in the urn
samplesize=100000; % Sample size to extract
edges=(0:(n+1))';
% Compute the density
Fpdf=FNChygepdf(edges(1:end-1),M,K,n,odds);
% Generate random numbers
x=FNChygernd(M,K,n,odds,samplesize);
% bar plot of theoretical and relative frequencies
freqANDdens=[(histcounts(x,edges-0.5)/samplesize)' Fpdf];
bar(edges(1:end-1),freqANDdens)
legend(["Theoretical density" "Empirical relative frequency"],'Location','best')
xlabel('Number of successes')

## Input Arguments

### M — Total number of balls in urn before sampling. Scalar.

Data Types: single|double

### K — Initial number of red balls in the urn. Scalar.

Data Types: single|double

### n — Total number of balls sampled. Scalar.

Data Types: single|double

### odds — Probability ratio of red over white balls. Scalar.

Data Types: single|double

### mm — Length of first dimension. Scalar.

Number of rows of the array which contains the random numbers

Example: 3 

Data Types: double

### nn — Length of second dimension. Scalar.

Number of columns of the array which contains the random numbers.

Example: 2 

Data Types: double

### oo — Length of third dimension. Scalar.

Number of 3D slides of the array which contains the random numbers

Example: 5 

Data Types: double

## Output Arguments

### r —Random numnbers. Array of random numbers from the Fisher non central hypergeometric distribution

The size of rr is determined by the optional input parameters mm, nn, oo.

## References

Fog, A. (2008), Calculation Methods for Wallenius' Noncentral Hypergeometric Distribution, "Communications in Statistics - Simulation and Computation", Vol. 37, pp. 258-273.