Class 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 Detail

      • 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 - if numberOfTrials or numberOfSuccesses is negative; probability is not between 0 and 1; or if numberOfTrials < numberOfSuccesses
        See Also:
        with(AlternativeHypothesis)