@PublicationReference(author="Eric Weisstein", title="Beta Binomial Distribution", type=WebPage, year=2010, url="http://mathworld.wolfram.com/BetaBinomialDistribution.html") public class BetaBinomialDistribution extends AbstractClosedFormIntegerDistribution implements ClosedFormDiscreteUnivariateDistribution<java.lang.Number>, EstimableDistribution<java.lang.Number,BetaBinomialDistribution>
Modifier and Type | Class and Description |
---|---|
static class |
BetaBinomialDistribution.CDF
CDF of BetaBinomialDistribution
|
static class |
BetaBinomialDistribution.MomentMatchingEstimator
Estimates the parameters of a Beta-binomial distribution using the matching
of moments, not maximum likelihood.
|
static class |
BetaBinomialDistribution.PMF
PMF of the BetaBinomialDistribution
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_N
Default n, 1.
|
static double |
DEFAULT_SCALE
Default scale, 1.0.
|
static double |
DEFAULT_SHAPE
Default shape, 1.0.
|
protected int |
n
Number of observations, similar to the Binomial N,
must be greater than zero
|
protected double |
scale
Scale, similar to the beta parameter scale, must be greater than zero
|
protected double |
shape
Shape, similar to the beta parameter shape, must be greater than zero
|
Constructor and Description |
---|
BetaBinomialDistribution()
Creates a new instance of BetaBinomialDistribution
|
BetaBinomialDistribution(BetaBinomialDistribution other)
Copy constructor
|
BetaBinomialDistribution(int n,
double shape,
double scale)
Creates a new instance of BetaBinomialDistribution
|
Modifier and Type | Method and Description |
---|---|
BetaBinomialDistribution |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
void |
convertFromVector(Vector parameters)
Converts the object from a Vector of parameters.
|
Vector |
convertToVector()
Converts the object to a vector.
|
BetaBinomialDistribution.CDF |
getCDF()
Gets the CDF of a scalar distribution.
|
IntegerSpan |
getDomain()
Returns an object that allows an iteration through the domain
(x-axis, independent variable) of the Distribution
|
int |
getDomainSize()
Gets the size of the domain.
|
BetaBinomialDistribution.MomentMatchingEstimator |
getEstimator()
Gets an estimator associated with this distribution.
|
java.lang.Integer |
getMaxSupport()
Gets the minimum support (domain or input) of the distribution.
|
java.lang.Number |
getMean()
Gets the arithmetic mean, or "first central moment" or "expectation",
of the distribution.
|
double |
getMeanAsDouble()
Gets the mean of the distribution as a double.
|
java.lang.Integer |
getMinSupport()
Gets the minimum support (domain or input) of the distribution.
|
int |
getN()
Getter for n
|
BetaBinomialDistribution.PMF |
getProbabilityFunction()
Gets the distribution function associated with this Distribution,
either the PDF or PMF.
|
double |
getScale()
Getter for scale
|
double |
getShape()
Getter for shape
|
double |
getVariance()
Gets the variance of the distribution.
|
int |
sampleAsInt(java.util.Random random)
Draws a single random sample from the distribution as an int.
|
void |
sampleInto(java.util.Random random,
int[] output,
int start,
int length)
Samples values from this distribution as an array of ints.
|
void |
sampleInto(java.util.Random random,
int sampleCount,
java.util.Collection<? super java.lang.Number> output)
Draws multiple random samples from the distribution and puts the result
into the given collection.
|
void |
setN(int n)
Setter for n
|
void |
setScale(double scale)
Setter for scale
|
void |
setShape(double shape)
Setter for shape
|
sampleAsInts
sample, sample
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
sample, sample
public static final double DEFAULT_SHAPE
public static final double DEFAULT_SCALE
public static final int DEFAULT_N
protected int n
protected double shape
protected double scale
public BetaBinomialDistribution()
public BetaBinomialDistribution(int n, double shape, double scale)
shape
- Shape, similar to the beta parameter shape, must be greater than zeroscale
- Scale, similar to the beta parameter scale, must be greater than zeron
- Number of observations, similar to the Binomial N,
must be greater than zeropublic BetaBinomialDistribution(BetaBinomialDistribution other)
other
- BetaBinomialDistribution to copypublic BetaBinomialDistribution clone()
AbstractCloneableSerializable
Object
class and
removes the exception that it throws. Its default behavior is to
automatically create a clone of the exact type of object that the
clone is called on and to copy all primitives but to keep all references,
which means it is a shallow copy.
Extensions of this class may want to override this method (but call
super.clone()
to implement a "smart copy". That is, to target
the most common use case for creating a copy of the object. Because of
the default behavior being a shallow copy, extending classes only need
to handle fields that need to have a deeper copy (or those that need to
be reset). Some of the methods in ObjectUtil
may be helpful in
implementing a custom clone method.
Note: The contract of this method is that you must use
super.clone()
as the basis for your implementation.clone
in interface Vectorizable
clone
in interface CloneableSerializable
clone
in class AbstractClosedFormUnivariateDistribution<java.lang.Number>
public double getShape()
public void setShape(double shape)
shape
- Shape, similar to the beta parameter shape, must be greater than zeropublic double getScale()
public void setScale(double scale)
scale
- Scale, similar to the beta parameter scale, must be greater than zeropublic int getN()
public void setN(int n)
n
- Number of observations, similar to the Binomial N,
must be greater than zeropublic java.lang.Number getMean()
DistributionWithMean
getMean
in interface DistributionWithMean<java.lang.Number>
public double getMeanAsDouble()
UnivariateDistribution
getMeanAsDouble
in interface UnivariateDistribution<java.lang.Number>
public void sampleInto(java.util.Random random, int sampleCount, java.util.Collection<? super java.lang.Number> output)
Distribution
sampleInto
in interface Distribution<java.lang.Number>
random
- Random number generator to use.sampleCount
- The number of samples to draw. Cannot be negative.output
- The collection to add the samples into.public int sampleAsInt(java.util.Random random)
IntegerDistribution
sampleAsInt
in interface IntegerDistribution
random
- The random number generator to use.public void sampleInto(java.util.Random random, int[] output, int start, int length)
IntegerDistribution
sampleInto
in interface IntegerDistribution
sampleInto
in class AbstractClosedFormIntegerDistribution
random
- Random number generator to use.output
- The array to write the result into. Cannot be null.start
- The offset in the array to start writing at. Cannot be negative.length
- The number of values to sample. Cannot be negative.public BetaBinomialDistribution.CDF getCDF()
UnivariateDistribution
getCDF
in interface ClosedFormUnivariateDistribution<java.lang.Number>
getCDF
in interface UnivariateDistribution<java.lang.Number>
public Vector convertToVector()
Vectorizable
convertToVector
in interface Vectorizable
public void convertFromVector(Vector parameters)
Vectorizable
convertFromVector
in interface Vectorizable
parameters
- The parameters to incorporate.public java.lang.Integer getMinSupport()
UnivariateDistribution
getMinSupport
in interface UnivariateDistribution<java.lang.Number>
public java.lang.Integer getMaxSupport()
UnivariateDistribution
getMaxSupport
in interface UnivariateDistribution<java.lang.Number>
public double getVariance()
UnivariateDistribution
getVariance
in interface UnivariateDistribution<java.lang.Number>
public IntegerSpan getDomain()
DiscreteDistribution
getDomain
in interface DiscreteDistribution<java.lang.Number>
public int getDomainSize()
DiscreteDistribution
getDomainSize
in interface DiscreteDistribution<java.lang.Number>
public BetaBinomialDistribution.PMF getProbabilityFunction()
ComputableDistribution
getProbabilityFunction
in interface ComputableDistribution<java.lang.Number>
getProbabilityFunction
in interface DiscreteDistribution<java.lang.Number>
public BetaBinomialDistribution.MomentMatchingEstimator getEstimator()
EstimableDistribution
getEstimator
in interface EstimableDistribution<java.lang.Number,BetaBinomialDistribution>