public class BinomialDistribution extends DiscreteDistribution
n = 1, the binomial distribution is a Bernoulli
distribution. The probability of getting exactly k successes in n trials
is given by the probability mass function:
Pr(K = k) = nCk pk (1-p)n-k
where nCk is n choose k.
It is frequently used to model number of successes in a sample of size n from a population of size N. Since the samples are not independent (this is sampling without replacement), the resulting distribution is a hypergeometric distribution, not a binomial one. However, for N much larger than n, the binomial distribution is a good approximation, and widely used.
Binomial distribution describes the number of successes for draws with replacement. In contrast, the hypergeometric distribution describes the number of successes for draws without replacement.
Although Binomial distribution belongs to exponential family, we don't implement DiscreteExponentialFamily interface here since it is impossible and meaningless to estimate a mixture of Binomial distributions.
HyperGeometricDistribution,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
int |
n
The number of experiments.
|
double |
p
The probability of success.
|
| Constructor and Description |
|---|
BinomialDistribution(int n,
double p)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
double |
cdf(double k)
Cumulative distribution function.
|
double |
entropy()
Shannon entropy of the distribution.
|
int |
length()
The number of parameters of the distribution.
|
double |
logp(int k)
The probability mass function in log scale.
|
double |
mean()
The mean of distribution.
|
double |
p(int k)
The probability mass function.
|
double |
quantile(double p)
The quantile, the probability to the left of quantile is p.
|
double |
rand()
This function generates a random variate with the binomial distribution.
|
double |
sd()
The standard deviation of distribution.
|
java.lang.String |
toString() |
double |
variance()
The variance of distribution.
|
likelihood, logLikelihood, logp, p, quantile, randi, randiinverseTransformSampling, quantile, quantile, rejectionclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitlikelihood, logLikelihood, randpublic final double p
public final int n
public BinomialDistribution(int n,
double p)
p - the probability of success.n - the number of experiments.public int length()
Distributionpublic double mean()
Distributionpublic double variance()
Distributionpublic double sd()
Distributionpublic double entropy()
Distributionpublic java.lang.String toString()
toString in class java.lang.Objectpublic double p(int k)
DiscreteDistributionp in class DiscreteDistributionpublic double logp(int k)
DiscreteDistributionlogp in class DiscreteDistributionpublic double cdf(double k)
Distributionpublic double quantile(double p)
Distributionpublic double rand()