# Class BinomialDistribution

java.lang.Object
dev.nm.stat.distribution.univariate.BinomialDistribution
All Implemented Interfaces:
ProbabilityDistribution

public class BinomialDistribution extends Object implements ProbabilityDistribution
The binomial distribution is the discrete probability distribution of the number of successes in a sequence of n independent yes/no experiments, each of which yields success with probability p. The binomial distribution is frequently used to model the number of successes in a sample of size n drawn with replacement from a population of size N. For N much larger than n, the binomial distribution is a good approximation of hypergeometric distribution.
• ## Constructor Summary

Constructors
Constructor
Description
BinomialDistribution(int n, double p)
Construct a Binomial distribution.
• ## Method Summary

Modifier and Type
Method
Description
double
cdf(double x)
Gets the cumulative probability F(x) = Pr(X ≤ x).
double
density(double x)
This is the probability mass function.
double
entropy()
Gets the entropy of this distribution.
double
kurtosis()
Gets the excess kurtosis of this distribution.
double
mean()
Gets the mean of this distribution.
double
median()
Gets the median of this distribution.
double
moment(double t)
The moment generating function is the expected value of etX.
double
quantile(double u)
Gets the quantile, the inverse of the cumulative distribution function.
double
skew()
Gets the skewness of this distribution.
double
variance()
Gets the variance of this distribution.

### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ## Constructor Details

• ### BinomialDistribution

public BinomialDistribution(int n, double p)
Construct a Binomial distribution.
Parameters:
n - the number of trials, a natural number
p - the success probability in each trial, [0, 1]
• ## Method Details

• ### mean

public double mean()
Description copied from interface: ProbabilityDistribution
Gets the mean of this distribution.
Specified by:
mean in interface ProbabilityDistribution
Returns:
the mean
• ### median

public double median()
Gets the median of this distribution.

The result is rounded rounded down to an integer.

Specified by:
median in interface ProbabilityDistribution
Returns:
median
• ### variance

public double variance()
Description copied from interface: ProbabilityDistribution
Gets the variance of this distribution.
Specified by:
variance in interface ProbabilityDistribution
Returns:
the variance
• ### skew

public double skew()
Description copied from interface: ProbabilityDistribution
Gets the skewness of this distribution.
Specified by:
skew in interface ProbabilityDistribution
Returns:
the skewness
• ### kurtosis

public double kurtosis()
Description copied from interface: ProbabilityDistribution
Gets the excess kurtosis of this distribution.
Specified by:
kurtosis in interface ProbabilityDistribution
Returns:
the excess kurtosis
• ### cdf

public double cdf(double x)
Gets the cumulative probability F(x) = Pr(X ≤ x).
Specified by:
cdf in interface ProbabilityDistribution
Parameters:
x - the number of success trials, an integer; rounded down to the closest integer if x is not an integer
Returns:
cdf(x)
• ### quantile

public double quantile(double u)
Gets the quantile, the inverse of the cumulative distribution function. It is the value below which random draws from the distribution would fall u×100 percent of the time.

F-1(u) = x, such that
Pr(X ≤ x) = u

This may not always exist.

Uses the Cornish-Fisher Expansion to include a skewness correction to a normal approximation. This gives an initial value which never seems to be off by more than 1 or 2. A search is then conducted of values close to this initial start point.

Specified by:
quantile in interface ProbabilityDistribution
Parameters:
u - a quantile
Returns:
qbinom(u)
• ### density

public double density(double x)
This is the probability mass function.
Specified by:
density in interface ProbabilityDistribution
Parameters:
x - the number of success trials, an integer; rounded down to the closest integer if x is not an integer
Returns:
pmf(x)
• ### entropy

public double entropy()
Description copied from interface: ProbabilityDistribution
Gets the entropy of this distribution.
Specified by:
entropy in interface ProbabilityDistribution
Returns:
the entropy
• ### moment

public double moment(double t)
Description copied from interface: ProbabilityDistribution
The moment generating function is the expected value of etX. That is,
E(etX)
This may not always exist.
Specified by:
moment in interface ProbabilityDistribution
Parameters:
t - t
Returns:
E(exp(tX))