public class BinomialDistribution extends DiscreteDistribution
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 constrast, the hypergeometric distribution describes the number of successes for draws without replacement.
Although Binomial distribtuion 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| 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 |
getN()
Returns the parameter n, the number of experiments.
|
double |
getProb()
Returns the probability of success.
|
double |
logp(int k)
The probability mass function in log scale.
|
double |
mean()
The mean of distribution.
|
int |
npara()
The number of parameters of the 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 |
var()
The variance of distribution.
|
likelihood, logLikelihood, logp, p, quantileinverseTransformSampling, likelihood, logLikelihood, quantile, quantile, rejectionpublic BinomialDistribution(int n,
double p)
p - the probability of success.n - the number of experiments.public double getProb()
public int getN()
public int npara()
Distributionpublic double mean()
Distributionpublic double var()
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()