Top Description Constructors Methods
org.apache.commons.math3.stat.inference

public Class BinomialTest

extends Object
Class Inheritance
Imports
org.apache.commons.math3.distribution.BinomialDistribution, org.apache.commons.math3.exception.MathIllegalArgumentException, .MathInternalError, .NotPositiveException, .NullArgumentException, .OutOfRangeException, org.apache.commons.math3.exception.util.LocalizedFormats

Implements binomial test statistics.

Exact test for the statistical significance of deviations from a theoretically expected distribution of observations into two categories.

Since
3.3
See Also
Binomial test (Wikipedia)

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the null hypothesis can be rejected with confidence 1 - alpha
binomialTest
(int
number of trials performed
numberOfTrials
,
int
number of successes observed
numberOfSuccesses
,
double
assumed probability of a single trial under the null hypothesis
probability
,
AlternativeHypothesis
type of hypothesis being evaluated (one- or two-sided)
alternativeHypothesis
,
double
significance level of the test
alpha
)

Returns whether the null hypothesis can be rejected with the given confidence level.

public double

Returns:

p-value
binomialTest
(int
number of trials performed
numberOfTrials
,
int
number of successes observed
numberOfSuccesses
,
double
assumed probability of a single trial under the null hypothesis
probability
,
AlternativeHypothesis
type of hypothesis being evaluated (one- or two-sided)
alternativeHypothesis
)

Returns the observed significance level, or p-value, associated with a Binomial test.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

BinomialTestback to summary
public BinomialTest()

Method Detail

binomialTestback to summary
public boolean binomialTest(int numberOfTrials, int numberOfSuccesses, double probability, AlternativeHypothesis alternativeHypothesis, double alpha)

Returns whether the null hypothesis can be rejected with the given confidence level.

Preconditions:

  • Number of trials must be ≥ 0.
  • Number of successes must be ≥ 0.
  • Number of successes must be ≤ number of trials.
  • Probability must be ≥ 0 and ≤ 1.
Parameters
numberOfTrials:int

number of trials performed

numberOfSuccesses:int

number of successes observed

probability:double

assumed probability of a single trial under the null hypothesis

alternativeHypothesis:AlternativeHypothesis

type of hypothesis being evaluated (one- or two-sided)

alpha:double

significance level of the test

Returns:boolean

true if the null hypothesis can be rejected with confidence 1 - alpha

Exceptions
NotPositiveException:
if numberOfTrials or numberOfSuccesses is negative
OutOfRangeException:
if probability is not between 0 and 1
MathIllegalArgumentException:
if numberOfTrials < numberOfSuccesses or if alternateHypothesis is null.
See Also
AlternativeHypothesis
binomialTestback to summary
public double binomialTest(int numberOfTrials, int numberOfSuccesses, double probability, AlternativeHypothesis alternativeHypothesis)

Returns the observed significance level, or p-value, associated with a Binomial test.

The number returned is the smallest significance level at which one can reject the null hypothesis. The form of the hypothesis depends on alternativeHypothesis.

The 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. For single-sided tests, this value can be directly derived from the Binomial distribution. For the two-sided test, the implementation works as follows: we start by looking at the most extreme cases (0 success and n success where n is the number of trials from the sample) and determine their likelihood. The lower value is added to the p-Value (if both values are equal, both are added). Then we continue with the next extreme value, until we added the value for the actual observed sample.

Preconditions:

  • Number of trials must be ≥ 0.
  • Number of successes must be ≥ 0.
  • Number of successes must be ≤ number of trials.
  • Probability must be ≥ 0 and ≤ 1.

Parameters
numberOfTrials:int

number of trials performed

numberOfSuccesses:int

number of successes observed

probability:double

assumed probability of a single trial under the null hypothesis

alternativeHypothesis:AlternativeHypothesis

type of hypothesis being evaluated (one- or two-sided)

Returns:double

p-value

Exceptions
NotPositiveException:
if numberOfTrials or numberOfSuccesses is negative
OutOfRangeException:
if probability is not between 0 and 1
MathIllegalArgumentException:
if numberOfTrials < numberOfSuccesses or if alternateHypothesis is null.
See Also
AlternativeHypothesis