<< distfun_binopdf Binomial distfun_binostat >>

Distfun >> Distfun > Binomial > distfun_binornd

distfun_binornd

Binomial random numbers

Calling Sequence

R = distfun_binornd(N,pr)
R = distfun_binornd(N,pr,[m,n])
R = distfun_binornd(N,pr,m,n)

Parameters

N :

a n-by-m matrix of doubles , the total number of binomial trials . N belongs to the set {1,2,3,4,.......}

pr :

a n-by-m matrix of doubles, the probability of getting success in a Bernoulli trial. pr in [0,1].

m :

a 1x1 matrix of floating point integers, the number of rows of R

n :

a 1x1 matrix of floating point integers, the number of columns of R

R:

a matrix of doubles, the random numbers, in the set {0,1,2,3,...}.

Description

Generates random variables from the Binomial distribution function.

Any scalar input argument is expanded to a matrix of doubles of the same size as the other input arguments.

If N<=2147483647, the algorithm is based on

Kachitvichyanukul, V. and Schmeiser, B. W. "Binomial Random Variate Generation.", Communications of the ACM, 31, 2 (February, 1988) 216.

If N is larger, then we invert the CDF.

Examples

// Set the initial seed for tests
distfun_seedset(1)

// Check with expanded N
N = [10 100 1000 10000]
pr = 0.1
computed = distfun_binornd(N, pr)
expected = [1 19 98 964]

// Set the initial seed
distfun_seedset(1)
// Check with expanded pr
N =100
pr = [0.1 0.2 0.3 0.4]
computed = distfun_binornd(N, pr)
expected = [9 32 29 38]

// Check R = distfun_binornd(pr,v)
computed = distfun_binornd(100,0.2,[4 5])

//Check mean and variance
N = 1000
pr = 0.3
n = 5000
R = distfun_binornd(N,pr,[1 n]);
RM = mean(R)
RV = variance(R)
[M,V] = distfun_binostat(N,pr)

// Check actual distribution
N=10;
pr=0.7;
K=10000;
R=distfun_binornd(N,pr,1,K);
h=scf();
distfun_inthisto(R);
h.children.children(1).children.background=-2;
x=0:N;
y=distfun_binopdf(x,N,pr);
plot(x,y,"ro-");
xtitle("Binomial Random Numbers","X","Density")
legend(["Empirical","Density"]);

Bibliography

http://en.wikipedia.org/wiki/Binomial_distribution

Authors


Report an issue
<< distfun_binopdf Binomial distfun_binostat >>