Java Statistical Classes

jsc.distributions
Class Binomial

java.lang.Object
  |
  +--jsc.distributions.AbstractDistribution
        |
        +--jsc.distributions.AbstractDiscreteDistribution
              |
              +--jsc.distributions.Binomial
All Implemented Interfaces:
Distribution

public class Binomial
extends AbstractDiscreteDistribution

This class represents a binomial distribution.

Version:
1.0
Author:
A. J. Bertie.

Field Summary
 
Fields inherited from class jsc.distributions.AbstractDiscreteDistribution
maxValue, minValue
 
Fields inherited from class jsc.distributions.AbstractDistribution
rand
 
Constructor Summary
Binomial(long n, double p)
          Create a binomial distribution with parameters n and p.
 
Method Summary
 double cdf(double x)
          Returns the value of the cumulative density function at a variate-value x.
 long getN()
           
 double getP()
           
 double inverseCdf(double prob)
          Returns the inverse of binomial distribution.
 double mean()
          Returns true indicating that the distribution is discrete.
 double pdf(double x)
          Returns the value of the probability mass function at variate-value x.
 double random()
          Returns as a double number an integer value that is a random variate-value drawn from the binomial distribution.
 void setN(long n)
          Change the "number of trials" parameter.
 void setP(double p)
          Change the "probability of success" parameter.
 String toString()
           
 double variance()
          Return variance of the distribution.
 
Methods inherited from class jsc.distributions.AbstractDiscreteDistribution
getMaximumPdf, getMaxValue, getMinValue, isDiscrete, moment, moment
 
Methods inherited from class jsc.distributions.AbstractDistribution
sd, setSeed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Binomial

public Binomial(long n,
                double p)
Create a binomial distribution with parameters n and p.

Parameters:
n - the "number of trials" parameter; must be greater than 0.
p - the "probability of success" parameter; must be greater than 0 and less than 1.
Throws:
IllegalArgumentException - if n less than 1.
IllegalArgumentException - if p not in (0,1).
Method Detail

cdf

public double cdf(double x)
Returns the value of the cumulative density function at a variate-value x.

Specified by:
cdf in interface Distribution
Overrides:
cdf in class AbstractDiscreteDistribution
Parameters:
x - a variate-value; must be in [0,n].
Returns:
the value of the cumulative density function at x.
Throws:
IllegalArgumentException - if x less than 0 or greater than n.

getN

public long getN()
Returns:
the "number of trials" parameter.

getP

public double getP()
Returns:
the "probability of success" parameter.

inverseCdf

public double inverseCdf(double prob)
Returns the inverse of binomial distribution. Given a probability, returns the smallest integer value of x such that Prob(X <= x) >= prob is true.

Specified by:
inverseCdf in interface Distribution
Overrides:
inverseCdf in class AbstractDiscreteDistribution
Parameters:
prob - the value of the probability; must be in [0,1].
Returns:
the variate-value x.
Throws:
IllegalArgumentException - if prob is less than 0 or greater than 1.

mean

public double mean()
Returns true indicating that the distribution is discrete.

Specified by:
mean in interface Distribution
Overrides:
mean in class AbstractDiscreteDistribution
Returns:
true.

pdf

public double pdf(double x)
Returns the value of the probability mass function at variate-value x. Returns zero if x is not a valid variate-value.

Specified by:
pdf in interface Distribution
Specified by:
pdf in class AbstractDiscreteDistribution
Parameters:
x - a variate-value.
Returns:
the value of the pmf at x if x is in [0,n]; otherwise returns 0.

random

public double random()
Returns as a double number an integer value that is a random variate-value drawn from the binomial distribution.

Specified by:
random in interface Distribution
Overrides:
random in class AbstractDistribution
Returns:
the random variate-value.

setN

public void setN(long n)
Change the "number of trials" parameter.

Parameters:
n - the "number of trials" parameter; must be greater than 0.
Throws:
IllegalArgumentException - if n less than 1.

setP

public void setP(double p)
Change the "probability of success" parameter.

Parameters:
p - the "probability of success" parameter; must be greater than 0 and less than 1.
Throws:
IllegalArgumentException - if p not in (0,1).

toString

public String toString()
Overrides:
toString in class Object

variance

public double variance()
Description copied from class: AbstractDiscreteDistribution
Return variance of the distribution. Note that this method calculates the mean by calling mean(); so if the mean is already calculated, it is more efficient to call moment(2,mean) than use this method. The variance is usually known in terms of the distribution's parameters, so this method should be overridden.

Specified by:
variance in interface Distribution
Overrides:
variance in class AbstractDiscreteDistribution
Returns:
the variance of the distribution.

Java Statistical Classes

Copyright © Andrew James Bertie, 2005, all rights reserved. Updated 12th Aug 2005