Class BinomialTest
- java.lang.Object
-
- org.apache.commons.statistics.inference.BinomialTest
-
public final class BinomialTest extends Object
Implements binomial test statistics.Performs an exact test for the statistical significance of deviations from a theoretically expected distribution of observations into two categories.
- Since:
- 1.1
- See Also:
- Binomial test (Wikipedia)
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SignificanceResult
test(int numberOfTrials, int numberOfSuccesses, double probability)
Performs a binomial test about the probability of success \( \pi \).BinomialTest
with(AlternativeHypothesis v)
Return an instance with the configured alternative hypothesis.static BinomialTest
withDefaults()
Return an instance using the default options.
-
-
-
Method Detail
-
withDefaults
public static BinomialTest withDefaults()
Return an instance using the default options.- Returns:
- default instance
-
with
public BinomialTest with(AlternativeHypothesis v)
Return an instance with the configured alternative hypothesis.- Parameters:
v
- Value.- Returns:
- an instance
-
test
public SignificanceResult test(int numberOfTrials, int numberOfSuccesses, double probability)
Performs a binomial test about the probability of success \( \pi \).The null hypothesis is \( H_0:\pi=\pi_0 \) where \( \pi_0 \) is between 0 and 1.
The probability of observing \( k \) successes from \( n \) trials with a given probability of success \( p \) is:
\[ \Pr(X=k)=\binom{n}{k}p^k(1-p)^{n-k} \]
The test is defined by the
AlternativeHypothesis
.To test \( \pi < \pi_0 \) (less than):
\[ p = \sum_{i=0}^k\Pr(X=i)=\sum_{i=0}^k\binom{n}{i}\pi_0^i(1-\pi_0)^{n-i} \]
To test \( \pi > \pi_0 \) (greater than):
\[ p = \sum_{i=0}^k\Pr(X=i)=\sum_{i=k}^n\binom{n}{i}\pi_0^i(1-\pi_0)^{n-i} \]
To test \( \pi \ne \pi_0 \) (two-sided) requires finding all \( i \) such that \( \mathcal{I}=\{i:\Pr(X=i)\leq \Pr(X=k)\} \) and compute the sum:
\[ p = \sum_{i\in\mathcal{I}}\Pr(X=i)=\sum_{i\in\mathcal{I}}\binom{n}{i}\pi_0^i(1-\pi_0)^{n-i} \]
The two-sided p-value represents the likelihood of getting a result at least as extreme as the sample, given the provided
probability
of success on a single trial.The test statistic is equal to the estimated proportion \( \frac{k}{n} \).
- Parameters:
numberOfTrials
- Number of trials performed.numberOfSuccesses
- Number of successes observed.probability
- Assumed probability of a single trial under the null hypothesis.- Returns:
- test result
- Throws:
IllegalArgumentException
- ifnumberOfTrials
ornumberOfSuccesses
is negative;probability
is not between 0 and 1; or ifnumberOfTrials < numberOfSuccesses
- See Also:
with(AlternativeHypothesis)
-
-