Removed trailing spaces.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1060449 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
24bd2a8ec1
commit
6ad3d5edf1
|
@ -226,7 +226,7 @@ public abstract class AbstractContinuousDistribution
|
||||||
* @return lower bound of the support (might be Double.NEGATIVE_INFINITY)
|
* @return lower bound of the support (might be Double.NEGATIVE_INFINITY)
|
||||||
*/
|
*/
|
||||||
public abstract double getSupportLowerBound();
|
public abstract double getSupportLowerBound();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access the upper bound of the support.
|
* Access the upper bound of the support.
|
||||||
*
|
*
|
||||||
|
|
|
@ -35,16 +35,16 @@ public abstract class AbstractDistribution
|
||||||
|
|
||||||
/** Cached numerical mean */
|
/** Cached numerical mean */
|
||||||
private double numericalMean = Double.NaN;
|
private double numericalMean = Double.NaN;
|
||||||
|
|
||||||
/** Whether or not the numerical mean has been calculated */
|
/** Whether or not the numerical mean has been calculated */
|
||||||
private boolean numericalMeanIsCalculated = false;
|
private boolean numericalMeanIsCalculated = false;
|
||||||
|
|
||||||
/** Cached numerical variance */
|
/** Cached numerical variance */
|
||||||
private double numericalVariance = Double.NaN;
|
private double numericalVariance = Double.NaN;
|
||||||
|
|
||||||
/** Whether or not the numerical variance has been calculated */
|
/** Whether or not the numerical variance has been calculated */
|
||||||
private boolean numericalVarianceIsCalculated = false;
|
private boolean numericalVarianceIsCalculated = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
|
@ -77,18 +77,18 @@ public abstract class AbstractDistribution
|
||||||
}
|
}
|
||||||
return cumulativeProbability(x1) - cumulativeProbability(x0);
|
return cumulativeProbability(x1) - cumulativeProbability(x0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this method to actually calculate the mean for the
|
* Use this method to actually calculate the mean for the
|
||||||
* specific distribution. Use {@link #getNumericalMean()}
|
* specific distribution. Use {@link #getNumericalMean()}
|
||||||
* (which implements caching) to actually get the mean.
|
* (which implements caching) to actually get the mean.
|
||||||
*
|
*
|
||||||
* @return the mean or Double.NaN if it's not defined
|
* @return the mean or Double.NaN if it's not defined
|
||||||
*/
|
*/
|
||||||
protected abstract double calculateNumericalMean();
|
protected abstract double calculateNumericalMean();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this method to get the numerical value of the mean of this
|
* Use this method to get the numerical value of the mean of this
|
||||||
* distribution.
|
* distribution.
|
||||||
*
|
*
|
||||||
* @return the mean or Double.NaN if it's not defined
|
* @return the mean or Double.NaN if it's not defined
|
||||||
|
@ -101,22 +101,22 @@ public abstract class AbstractDistribution
|
||||||
|
|
||||||
return numericalMean;
|
return numericalMean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this method to actually calculate the variance for the
|
* Use this method to actually calculate the variance for the
|
||||||
* specific distribution. Use {@link #getNumericalVariance()}
|
* specific distribution. Use {@link #getNumericalVariance()}
|
||||||
* (which implements caching) to actually get the variance.
|
* (which implements caching) to actually get the variance.
|
||||||
*
|
*
|
||||||
* @return the variance or Double.NaN if it's not defined
|
* @return the variance or Double.NaN if it's not defined
|
||||||
*/
|
*/
|
||||||
protected abstract double calculateNumericalVariance();
|
protected abstract double calculateNumericalVariance();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this method to get the numerical value of the variance of this
|
* Use this method to get the numerical value of the variance of this
|
||||||
* distribution.
|
* distribution.
|
||||||
*
|
*
|
||||||
* @return the variance (possibly Double.POSITIVE_INFINITY as
|
* @return the variance (possibly Double.POSITIVE_INFINITY as
|
||||||
* for certain cases in {@link TDistributionImpl}) or
|
* for certain cases in {@link TDistributionImpl}) or
|
||||||
* Double.NaN if it's not defined
|
* Double.NaN if it's not defined
|
||||||
*/
|
*/
|
||||||
public double getNumericalVariance() {
|
public double getNumericalVariance() {
|
||||||
|
@ -124,40 +124,40 @@ public abstract class AbstractDistribution
|
||||||
numericalVariance = calculateNumericalVariance();
|
numericalVariance = calculateNumericalVariance();
|
||||||
numericalVarianceIsCalculated = true;
|
numericalVarianceIsCalculated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return numericalVariance;
|
return numericalVariance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this method to get information about whether the lower bound
|
* Use this method to get information about whether the lower bound
|
||||||
* of the support is inclusive or not.
|
* of the support is inclusive or not.
|
||||||
*
|
*
|
||||||
* @return whether the lower bound of the support is inclusive or not
|
* @return whether the lower bound of the support is inclusive or not
|
||||||
*/
|
*/
|
||||||
public abstract boolean isSupportLowerBoundInclusive();
|
public abstract boolean isSupportLowerBoundInclusive();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this method to get information about whether the upper bound
|
* Use this method to get information about whether the upper bound
|
||||||
* of the support is inclusive or not.
|
* of the support is inclusive or not.
|
||||||
*
|
*
|
||||||
* @return whether the upper bound of the support is inclusive or not
|
* @return whether the upper bound of the support is inclusive or not
|
||||||
*/
|
*/
|
||||||
public abstract boolean isSupportUpperBoundInclusive();
|
public abstract boolean isSupportUpperBoundInclusive();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this method to get information about whether the support is connected,
|
* Use this method to get information about whether the support is connected,
|
||||||
* i.e. whether all values between the lower and upper bound of the support
|
* i.e. whether all values between the lower and upper bound of the support
|
||||||
* is included in the support.
|
* is included in the support.
|
||||||
*
|
*
|
||||||
* For {@link AbstractIntegerDistribution} the support is discrete, so
|
* For {@link AbstractIntegerDistribution} the support is discrete, so
|
||||||
* if this is true, then the support is
|
* if this is true, then the support is
|
||||||
* {lower bound, lower bound + 1, ..., upper bound}.
|
* {lower bound, lower bound + 1, ..., upper bound}.
|
||||||
*
|
*
|
||||||
* For {@link AbstractContinuousDistribution} the support is continuous, so
|
* For {@link AbstractContinuousDistribution} the support is continuous, so
|
||||||
* if this is true, then the support is the interval
|
* if this is true, then the support is the interval
|
||||||
* [lower bound, upper bound]
|
* [lower bound, upper bound]
|
||||||
* where the limits are inclusive or not according to
|
* where the limits are inclusive or not according to
|
||||||
* {@link #isSupportLowerBoundInclusive()} and {@link #isSupportUpperBoundInclusive()}
|
* {@link #isSupportLowerBoundInclusive()} and {@link #isSupportUpperBoundInclusive()}
|
||||||
* (in the example both are true). If both are false, then the support is the interval
|
* (in the example both are true). If both are false, then the support is the interval
|
||||||
* (lower bound, upper bound)
|
* (lower bound, upper bound)
|
||||||
*
|
*
|
||||||
|
|
|
@ -290,42 +290,42 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution
|
||||||
* @return the domain value upper bound, i.e. {@code P(X < 'upper bound') > p}.
|
* @return the domain value upper bound, i.e. {@code P(X < 'upper bound') > p}.
|
||||||
*/
|
*/
|
||||||
protected abstract int getDomainUpperBound(double p);
|
protected abstract int getDomainUpperBound(double p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access the lower bound of the support.
|
* Access the lower bound of the support.
|
||||||
*
|
*
|
||||||
* @return lower bound of the support (Integer.MIN_VALUE for negative infinity)
|
* @return lower bound of the support (Integer.MIN_VALUE for negative infinity)
|
||||||
*/
|
*/
|
||||||
public abstract int getSupportLowerBound();
|
public abstract int getSupportLowerBound();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access the upper bound of the support.
|
* Access the upper bound of the support.
|
||||||
*
|
*
|
||||||
* @return upper bound of the support (Integer.MAX_VALUE for positive infinity)
|
* @return upper bound of the support (Integer.MAX_VALUE for positive infinity)
|
||||||
*/
|
*/
|
||||||
public abstract int getSupportUpperBound();
|
public abstract int getSupportUpperBound();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this method to get information about whether the lower bound
|
* Use this method to get information about whether the lower bound
|
||||||
* of the support is inclusive or not. For discrete support,
|
* of the support is inclusive or not. For discrete support,
|
||||||
* only true here is meaningful.
|
* only true here is meaningful.
|
||||||
*
|
*
|
||||||
* @return true (always but at Integer.MIN_VALUE because of the nature of discrete support)
|
* @return true (always but at Integer.MIN_VALUE because of the nature of discrete support)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isSupportLowerBoundInclusive() {
|
public boolean isSupportLowerBoundInclusive() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this method to get information about whether the upper bound
|
* Use this method to get information about whether the upper bound
|
||||||
* of the support is inclusive or not. For discrete support,
|
* of the support is inclusive or not. For discrete support,
|
||||||
* only true here is meaningful.
|
* only true here is meaningful.
|
||||||
*
|
*
|
||||||
* @return true (always but at Integer.MAX_VALUE because of the nature of discrete support)
|
* @return true (always but at Integer.MAX_VALUE because of the nature of discrete support)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isSupportUpperBoundInclusive() {
|
public boolean isSupportUpperBoundInclusive() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,7 +187,7 @@ public class BetaDistributionImpl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The lower bound of the support is always 0 no matter the parameters.
|
* The lower bound of the support is always 0 no matter the parameters.
|
||||||
*
|
*
|
||||||
* @return lower bound of the support (always 0)
|
* @return lower bound of the support (always 0)
|
||||||
|
@ -199,7 +199,7 @@ public class BetaDistributionImpl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The upper bound of the support is always 1 no matter the parameters.
|
* The upper bound of the support is always 1 no matter the parameters.
|
||||||
*
|
*
|
||||||
* @return upper bound of the support (always 1)
|
* @return upper bound of the support (always 1)
|
||||||
|
@ -211,8 +211,8 @@ public class BetaDistributionImpl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For first shape parameter <code>s1</code> and
|
* For first shape parameter <code>s1</code> and
|
||||||
* second shape parameter <code>s2</code>, the mean is
|
* second shape parameter <code>s2</code>, the mean is
|
||||||
* <code>s1 / (s1 + s2)</code>
|
* <code>s1 / (s1 + s2)</code>
|
||||||
*
|
*
|
||||||
|
@ -226,9 +226,9 @@ public class BetaDistributionImpl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For first shape parameter <code>s1</code> and
|
* For first shape parameter <code>s1</code> and
|
||||||
* second shape parameter <code>s2</code>,
|
* second shape parameter <code>s2</code>,
|
||||||
* the variance is
|
* the variance is
|
||||||
* <code>[ s1 * s2 ] / [ (s1 + s2)^2 * (s1 + s2 + 1) ]</code>
|
* <code>[ s1 * s2 ] / [ (s1 + s2)^2 * (s1 + s2 + 1) ]</code>
|
||||||
*
|
*
|
||||||
|
@ -237,7 +237,7 @@ public class BetaDistributionImpl
|
||||||
@Override
|
@Override
|
||||||
protected double calculateNumericalVariance() {
|
protected double calculateNumericalVariance() {
|
||||||
final double a = getAlpha();
|
final double a = getAlpha();
|
||||||
final double b = getBeta();
|
final double b = getBeta();
|
||||||
final double alphabetasum = a + b;
|
final double alphabetasum = a + b;
|
||||||
return (a * b) / ((alphabetasum * alphabetasum) * (alphabetasum + 1));
|
return (a * b) / ((alphabetasum * alphabetasum) * (alphabetasum + 1));
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,8 +167,8 @@ public class BinomialDistributionImpl extends AbstractIntegerDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The lower bound of the support is always 0 no matter the number of trials
|
* The lower bound of the support is always 0 no matter the number of trials
|
||||||
* and probability parameter.
|
* and probability parameter.
|
||||||
*
|
*
|
||||||
* @return lower bound of the support (always 0)
|
* @return lower bound of the support (always 0)
|
||||||
|
@ -177,10 +177,10 @@ public class BinomialDistributionImpl extends AbstractIntegerDistribution
|
||||||
public int getSupportLowerBound() {
|
public int getSupportLowerBound() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The upper bound of the support is the number of trials.
|
* The upper bound of the support is the number of trials.
|
||||||
*
|
*
|
||||||
* @return upper bound of the support (equal to number of trials)
|
* @return upper bound of the support (equal to number of trials)
|
||||||
|
@ -192,8 +192,8 @@ public class BinomialDistributionImpl extends AbstractIntegerDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For <code>n</code> number of trials and
|
* For <code>n</code> number of trials and
|
||||||
* probability parameter <code>p</code>, the mean is
|
* probability parameter <code>p</code>, the mean is
|
||||||
* <code>n * p</code>
|
* <code>n * p</code>
|
||||||
*
|
*
|
||||||
|
@ -206,8 +206,8 @@ public class BinomialDistributionImpl extends AbstractIntegerDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For <code>n</code> number of trials and
|
* For <code>n</code> number of trials and
|
||||||
* probability parameter <code>p</code>, the variance is
|
* probability parameter <code>p</code>, the variance is
|
||||||
* <code>n * p * (1 - p)</code>
|
* <code>n * p * (1 - p)</code>
|
||||||
*
|
*
|
||||||
|
|
|
@ -163,7 +163,7 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access the domain value upper bound, based on <code>p</code>, used to
|
* Access the domain value upper bound, based on <code>p</code>, used to
|
||||||
|
@ -223,8 +223,8 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The lower bound of the support is always negative infinity no matter
|
* The lower bound of the support is always negative infinity no matter
|
||||||
* the parameters.
|
* the parameters.
|
||||||
*
|
*
|
||||||
* @return lower bound of the support (always Double.NEGATIVE_INFINITY)
|
* @return lower bound of the support (always Double.NEGATIVE_INFINITY)
|
||||||
|
@ -236,8 +236,8 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The upper bound of the support is always positive infinity no matter
|
* The upper bound of the support is always positive infinity no matter
|
||||||
* the parameters.
|
* the parameters.
|
||||||
*
|
*
|
||||||
* @return upper bound of the support (always Double.POSITIVE_INFINITY)
|
* @return upper bound of the support (always Double.POSITIVE_INFINITY)
|
||||||
|
@ -249,7 +249,7 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The mean is always undefined no matter the parameters.
|
* The mean is always undefined no matter the parameters.
|
||||||
*
|
*
|
||||||
* @return mean (always Double.NaN)
|
* @return mean (always Double.NaN)
|
||||||
|
@ -261,7 +261,7 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The variance is always undefined no matter the parameters.
|
* The variance is always undefined no matter the parameters.
|
||||||
*
|
*
|
||||||
* @return variance (always Double.NaN)
|
* @return variance (always Double.NaN)
|
||||||
|
|
|
@ -196,8 +196,8 @@ public class ChiSquaredDistributionImpl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The lower bound of the support is always 0 no matter the
|
* The lower bound of the support is always 0 no matter the
|
||||||
* degrees of freedom.
|
* degrees of freedom.
|
||||||
*
|
*
|
||||||
* @return lower bound of the support (always 0)
|
* @return lower bound of the support (always 0)
|
||||||
|
@ -209,8 +209,8 @@ public class ChiSquaredDistributionImpl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The upper bound of the support is always positive infinity no matter the
|
* The upper bound of the support is always positive infinity no matter the
|
||||||
* degrees of freedom.
|
* degrees of freedom.
|
||||||
*
|
*
|
||||||
* @return upper bound of the support (always Double.POSITIVE_INFINITY)
|
* @return upper bound of the support (always Double.POSITIVE_INFINITY)
|
||||||
|
@ -222,7 +222,7 @@ public class ChiSquaredDistributionImpl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For <code>k</code> degrees of freedom, the mean is
|
* For <code>k</code> degrees of freedom, the mean is
|
||||||
* <code>k</code>
|
* <code>k</code>
|
||||||
*
|
*
|
||||||
|
@ -235,7 +235,7 @@ public class ChiSquaredDistributionImpl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For <code>k</code> degrees of freedom, the variance is
|
* For <code>k</code> degrees of freedom, the variance is
|
||||||
* <code>2 * k</code>
|
* <code>2 * k</code>
|
||||||
*
|
*
|
||||||
|
|
|
@ -52,55 +52,55 @@ public interface Distribution {
|
||||||
* @throws IllegalArgumentException if <code>x0 > x1</code>
|
* @throws IllegalArgumentException if <code>x0 > x1</code>
|
||||||
*/
|
*/
|
||||||
double cumulativeProbability(double x0, double x1) throws MathException;
|
double cumulativeProbability(double x0, double x1) throws MathException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this method to get the numerical value of the mean of this
|
* Use this method to get the numerical value of the mean of this
|
||||||
* distribution.
|
* distribution.
|
||||||
*
|
*
|
||||||
* @return the mean or Double.NaN if it's not defined
|
* @return the mean or Double.NaN if it's not defined
|
||||||
*/
|
*/
|
||||||
double getNumericalMean();
|
double getNumericalMean();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this method to get the numerical value of the variance of this
|
* Use this method to get the numerical value of the variance of this
|
||||||
* distribution.
|
* distribution.
|
||||||
*
|
*
|
||||||
* @return the variance (possibly Double.POSITIVE_INFINITY as
|
* @return the variance (possibly Double.POSITIVE_INFINITY as
|
||||||
* for certain cases in {@link TDistributionImpl}) or
|
* for certain cases in {@link TDistributionImpl}) or
|
||||||
* Double.NaN if it's not defined
|
* Double.NaN if it's not defined
|
||||||
*/
|
*/
|
||||||
double getNumericalVariance();
|
double getNumericalVariance();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this method to get information about whether the lower bound
|
* Use this method to get information about whether the lower bound
|
||||||
* of the support is inclusive or not.
|
* of the support is inclusive or not.
|
||||||
*
|
*
|
||||||
* @return whether the lower bound of the support is inclusive or not
|
* @return whether the lower bound of the support is inclusive or not
|
||||||
*/
|
*/
|
||||||
boolean isSupportLowerBoundInclusive();
|
boolean isSupportLowerBoundInclusive();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this method to get information about whether the upper bound
|
* Use this method to get information about whether the upper bound
|
||||||
* of the support is inclusive or not.
|
* of the support is inclusive or not.
|
||||||
*
|
*
|
||||||
* @return whether the upper bound of the support is inclusive or not
|
* @return whether the upper bound of the support is inclusive or not
|
||||||
*/
|
*/
|
||||||
boolean isSupportUpperBoundInclusive();
|
boolean isSupportUpperBoundInclusive();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this method to get information about whether the support is connected,
|
* Use this method to get information about whether the support is connected,
|
||||||
* i.e. whether all values between the lower and upper bound of the support
|
* i.e. whether all values between the lower and upper bound of the support
|
||||||
* is included in the support.
|
* is included in the support.
|
||||||
*
|
*
|
||||||
* For {@link AbstractIntegerDistribution} the support is discrete, so
|
* For {@link AbstractIntegerDistribution} the support is discrete, so
|
||||||
* if this is true, then the support is
|
* if this is true, then the support is
|
||||||
* {lower bound, lower bound + 1, ..., upper bound}.
|
* {lower bound, lower bound + 1, ..., upper bound}.
|
||||||
*
|
*
|
||||||
* For {@link AbstractContinuousDistribution} the support is continuous, so
|
* For {@link AbstractContinuousDistribution} the support is continuous, so
|
||||||
* if this is true, then the support is the interval
|
* if this is true, then the support is the interval
|
||||||
* [lower bound, upper bound]
|
* [lower bound, upper bound]
|
||||||
* where the limits are inclusive or not according to
|
* where the limits are inclusive or not according to
|
||||||
* {@link #isSupportLowerBoundInclusive()} and {@link #isSupportUpperBoundInclusive()}
|
* {@link #isSupportLowerBoundInclusive()} and {@link #isSupportUpperBoundInclusive()}
|
||||||
* (in the example both are true). If both are false, then the support is the interval
|
* (in the example both are true). If both are false, then the support is the interval
|
||||||
* (lower bound, upper bound)
|
* (lower bound, upper bound)
|
||||||
*
|
*
|
||||||
|
|
|
@ -225,7 +225,7 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The lower bound of the support is always 0 no matter the mean parameter.
|
* The lower bound of the support is always 0 no matter the mean parameter.
|
||||||
*
|
*
|
||||||
* @return lower bound of the support (always 0)
|
* @return lower bound of the support (always 0)
|
||||||
|
@ -237,8 +237,8 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The upper bound of the support is always positive infinity
|
* The upper bound of the support is always positive infinity
|
||||||
* no matter the mean parameter.
|
* no matter the mean parameter.
|
||||||
*
|
*
|
||||||
* @return upper bound of the support (always Double.POSITIVE_INFINITY)
|
* @return upper bound of the support (always Double.POSITIVE_INFINITY)
|
||||||
|
@ -250,7 +250,7 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For mean parameter <code>k</code>, the mean is
|
* For mean parameter <code>k</code>, the mean is
|
||||||
* <code>k</code>
|
* <code>k</code>
|
||||||
*
|
*
|
||||||
|
@ -263,7 +263,7 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For mean parameter <code>k</code>, the variance is
|
* For mean parameter <code>k</code>, the variance is
|
||||||
* <code>k^2</code>
|
* <code>k^2</code>
|
||||||
*
|
*
|
||||||
|
|
|
@ -235,10 +235,10 @@ public class FDistributionImpl
|
||||||
protected double getSolverAbsoluteAccuracy() {
|
protected double getSolverAbsoluteAccuracy() {
|
||||||
return solverAbsoluteAccuracy;
|
return solverAbsoluteAccuracy;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The lower bound of the support is always 0 no matter the parameters.
|
* The lower bound of the support is always 0 no matter the parameters.
|
||||||
*
|
*
|
||||||
* @return lower bound of the support (always 0)
|
* @return lower bound of the support (always 0)
|
||||||
|
@ -250,8 +250,8 @@ public class FDistributionImpl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The upper bound of the support is always positive infinity
|
* The upper bound of the support is always positive infinity
|
||||||
* no matter the parameters.
|
* no matter the parameters.
|
||||||
*
|
*
|
||||||
* @return upper bound of the support (always Double.POSITIVE_INFINITY)
|
* @return upper bound of the support (always Double.POSITIVE_INFINITY)
|
||||||
|
@ -263,8 +263,8 @@ public class FDistributionImpl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For denominator degrees of freedom parameter <code>b</code>,
|
* For denominator degrees of freedom parameter <code>b</code>,
|
||||||
* the mean is
|
* the mean is
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>if <code>b > 2</code> then <code>b / (b - 2)</code></li>
|
* <li>if <code>b > 2</code> then <code>b / (b - 2)</code></li>
|
||||||
|
@ -272,27 +272,27 @@ public class FDistributionImpl
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @return {@inheritDoc}
|
* @return {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected double calculateNumericalMean() {
|
protected double calculateNumericalMean() {
|
||||||
final double denominatorDF = getDenominatorDegreesOfFreedom();
|
final double denominatorDF = getDenominatorDegreesOfFreedom();
|
||||||
|
|
||||||
if (denominatorDF > 2) {
|
if (denominatorDF > 2) {
|
||||||
return denominatorDF / (denominatorDF - 2);
|
return denominatorDF / (denominatorDF - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Double.NaN;
|
return Double.NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For numerator degrees of freedom parameter <code>a</code>
|
* For numerator degrees of freedom parameter <code>a</code>
|
||||||
* and denominator degrees of freedom parameter <code>b</code>,
|
* and denominator degrees of freedom parameter <code>b</code>,
|
||||||
* the variance is
|
* the variance is
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>
|
* <li>
|
||||||
* if <code>b > 4</code> then
|
* if <code>b > 4</code> then
|
||||||
* <code>[ 2 * b^2 * (a + b - 2) ] / [ a * (b - 2)^2 * (b - 4) ]</code>
|
* <code>[ 2 * b^2 * (a + b - 2) ] / [ a * (b - 2)^2 * (b - 4) ]</code>
|
||||||
* </li>
|
* </li>
|
||||||
* <li>else <code>undefined</code>
|
* <li>else <code>undefined</code>
|
||||||
|
@ -307,12 +307,12 @@ public class FDistributionImpl
|
||||||
if (denominatorDF > 4) {
|
if (denominatorDF > 4) {
|
||||||
final double numeratorDF = getNumeratorDegreesOfFreedom();
|
final double numeratorDF = getNumeratorDegreesOfFreedom();
|
||||||
final double denomDFMinusTwo = denominatorDF - 2;
|
final double denomDFMinusTwo = denominatorDF - 2;
|
||||||
|
|
||||||
return ( 2 * (denominatorDF * denominatorDF) * (numeratorDF + denominatorDF - 2) ) /
|
return ( 2 * (denominatorDF * denominatorDF) * (numeratorDF + denominatorDF - 2) ) /
|
||||||
( (numeratorDF * (denomDFMinusTwo * denomDFMinusTwo) * (denominatorDF - 4)) );
|
( (numeratorDF * (denomDFMinusTwo * denomDFMinusTwo) * (denominatorDF - 4)) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return Double.NaN;
|
return Double.NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -240,7 +240,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The lower bound of the support is always 0 no matter the parameters.
|
* The lower bound of the support is always 0 no matter the parameters.
|
||||||
*
|
*
|
||||||
* @return lower bound of the support (always 0)
|
* @return lower bound of the support (always 0)
|
||||||
|
@ -252,8 +252,8 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The upper bound of the support is always positive infinity
|
* The upper bound of the support is always positive infinity
|
||||||
* no matter the parameters.
|
* no matter the parameters.
|
||||||
*
|
*
|
||||||
* @return upper bound of the support (always Double.POSITIVE_INFINITY)
|
* @return upper bound of the support (always Double.POSITIVE_INFINITY)
|
||||||
|
@ -265,8 +265,8 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For shape parameter <code>alpha</code> and scale
|
* For shape parameter <code>alpha</code> and scale
|
||||||
* parameter <code>beta</code>, the mean is
|
* parameter <code>beta</code>, the mean is
|
||||||
* <code>alpha * beta</code>
|
* <code>alpha * beta</code>
|
||||||
*
|
*
|
||||||
|
@ -279,8 +279,8 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For shape parameter <code>alpha</code> and scale
|
* For shape parameter <code>alpha</code> and scale
|
||||||
* parameter <code>beta</code>, the variance is
|
* parameter <code>beta</code>, the variance is
|
||||||
* <code>alpha * beta^2</code>
|
* <code>alpha * beta^2</code>
|
||||||
*
|
*
|
||||||
|
@ -288,7 +288,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected double calculateNumericalVariance() {
|
protected double calculateNumericalVariance() {
|
||||||
final double b = getBeta();
|
final double b = getBeta();
|
||||||
return getAlpha() * b * b;
|
return getAlpha() * b * b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -287,10 +287,10 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For population size <code>N</code>,
|
* For population size <code>N</code>,
|
||||||
* number of successes <code>m</code>, and
|
* number of successes <code>m</code>, and
|
||||||
* sample size <code>n</code>,
|
* sample size <code>n</code>,
|
||||||
* the lower bound of the support is
|
* the lower bound of the support is
|
||||||
* <code>max(0, n + m - N)</code>
|
* <code>max(0, n + m - N)</code>
|
||||||
*
|
*
|
||||||
|
@ -298,15 +298,15 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getSupportLowerBound() {
|
public int getSupportLowerBound() {
|
||||||
return FastMath.max(0,
|
return FastMath.max(0,
|
||||||
getSampleSize() + getNumberOfSuccesses() - getPopulationSize());
|
getSampleSize() + getNumberOfSuccesses() - getPopulationSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For number of successes <code>m</code> and
|
* For number of successes <code>m</code> and
|
||||||
* sample size <code>n</code>,
|
* sample size <code>n</code>,
|
||||||
* the upper bound of the support is
|
* the upper bound of the support is
|
||||||
* <code>min(m, n)</code>
|
* <code>min(m, n)</code>
|
||||||
*
|
*
|
||||||
|
@ -319,9 +319,9 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For population size <code>N</code>,
|
* For population size <code>N</code>,
|
||||||
* number of successes <code>m</code>, and
|
* number of successes <code>m</code>, and
|
||||||
* sample size <code>n</code>, the mean is
|
* sample size <code>n</code>, the mean is
|
||||||
* <code>n * m / N</code>
|
* <code>n * m / N</code>
|
||||||
*
|
*
|
||||||
|
@ -334,9 +334,9 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For population size <code>N</code>,
|
* For population size <code>N</code>,
|
||||||
* number of successes <code>m</code>, and
|
* number of successes <code>m</code>, and
|
||||||
* sample size <code>n</code>, the variance is
|
* sample size <code>n</code>, the variance is
|
||||||
* <code>[ n * m * (N - n) * (N - m) ] / [ N^2 * (N - 1) ]</code>
|
* <code>[ n * m * (N - n) * (N - m) ] / [ N^2 * (N - 1) ]</code>
|
||||||
*
|
*
|
||||||
|
|
|
@ -244,8 +244,8 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The lower bound of the support is always negative infinity
|
* The lower bound of the support is always negative infinity
|
||||||
* no matter the parameters.
|
* no matter the parameters.
|
||||||
*
|
*
|
||||||
* @return lower bound of the support (always Double.NEGATIVE_INFINITY)
|
* @return lower bound of the support (always Double.NEGATIVE_INFINITY)
|
||||||
|
@ -257,8 +257,8 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The upper bound of the support is always positive infinity
|
* The upper bound of the support is always positive infinity
|
||||||
* no matter the parameters.
|
* no matter the parameters.
|
||||||
*
|
*
|
||||||
* @return upper bound of the support (always Double.POSITIVE_INFINITY)
|
* @return upper bound of the support (always Double.POSITIVE_INFINITY)
|
||||||
|
@ -270,7 +270,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For mean parameter <code>mu</code>, the mean is <code>mu</code>
|
* For mean parameter <code>mu</code>, the mean is <code>mu</code>
|
||||||
*
|
*
|
||||||
* @return {@inheritDoc}
|
* @return {@inheritDoc}
|
||||||
|
@ -282,8 +282,8 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For standard deviation parameter <code>s</code>,
|
* For standard deviation parameter <code>s</code>,
|
||||||
* the variance is <code>s^2</code>
|
* the variance is <code>s^2</code>
|
||||||
*
|
*
|
||||||
* @return {@inheritDoc}
|
* @return {@inheritDoc}
|
||||||
|
|
|
@ -168,7 +168,7 @@ public class PascalDistributionImpl extends AbstractIntegerDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The lower bound of the support is always 0 no matter the parameters.
|
* The lower bound of the support is always 0 no matter the parameters.
|
||||||
*
|
*
|
||||||
* @return lower bound of the support (always 0)
|
* @return lower bound of the support (always 0)
|
||||||
|
@ -180,10 +180,10 @@ public class PascalDistributionImpl extends AbstractIntegerDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The upper bound of the support is always positive infinity
|
* The upper bound of the support is always positive infinity
|
||||||
* no matter the parameters. Positive infinity is symbolised
|
* no matter the parameters. Positive infinity is symbolised
|
||||||
* by <code>Integer.MAX_VALUE</code> together with
|
* by <code>Integer.MAX_VALUE</code> together with
|
||||||
* {@link #isSupportUpperBoundInclusive()} being <code>false</code>
|
* {@link #isSupportUpperBoundInclusive()} being <code>false</code>
|
||||||
*
|
*
|
||||||
* @return upper bound of the support (always <code>Integer.MAX_VALUE</code> for positive infinity)
|
* @return upper bound of the support (always <code>Integer.MAX_VALUE</code> for positive infinity)
|
||||||
|
@ -195,8 +195,8 @@ public class PascalDistributionImpl extends AbstractIntegerDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For number of successes <code>r</code> and
|
* For number of successes <code>r</code> and
|
||||||
* probability of success <code>p</code>, the mean is
|
* probability of success <code>p</code>, the mean is
|
||||||
* <code>( r * p ) / ( 1 - p )</code>
|
* <code>( r * p ) / ( 1 - p )</code>
|
||||||
*
|
*
|
||||||
|
@ -211,8 +211,8 @@ public class PascalDistributionImpl extends AbstractIntegerDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For number of successes <code>r</code> and
|
* For number of successes <code>r</code> and
|
||||||
* probability of success <code>p</code>, the mean is
|
* probability of success <code>p</code>, the mean is
|
||||||
* <code>( r * p ) / ( 1 - p )^2</code>
|
* <code>( r * p ) / ( 1 - p )^2</code>
|
||||||
*
|
*
|
||||||
|
@ -225,7 +225,7 @@ public class PascalDistributionImpl extends AbstractIntegerDistribution
|
||||||
final double pInv = 1 - p;
|
final double pInv = 1 - p;
|
||||||
return ( r * p ) / (pInv * pInv);
|
return ( r * p ) / (pInv * pInv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -233,7 +233,7 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The lower bound of the support is always 0 no matter the mean parameter.
|
* The lower bound of the support is always 0 no matter the mean parameter.
|
||||||
*
|
*
|
||||||
* @return lower bound of the support (always 0)
|
* @return lower bound of the support (always 0)
|
||||||
|
@ -245,9 +245,9 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The upper bound of the support is positive infinity,
|
* The upper bound of the support is positive infinity,
|
||||||
* regardless of the parameter values. There is no integer infinity,
|
* regardless of the parameter values. There is no integer infinity,
|
||||||
* so this method returns <code>Integer.MAX_VALUE</code> and
|
* so this method returns <code>Integer.MAX_VALUE</code> and
|
||||||
* {@link #isSupportUpperBoundInclusive()} returns <code>true</code>.
|
* {@link #isSupportUpperBoundInclusive()} returns <code>true</code>.
|
||||||
*
|
*
|
||||||
|
@ -260,7 +260,7 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For mean parameter <code>p</code>, the mean is <code>p</code>
|
* For mean parameter <code>p</code>, the mean is <code>p</code>
|
||||||
*
|
*
|
||||||
* @return {@inheritDoc}
|
* @return {@inheritDoc}
|
||||||
|
@ -272,7 +272,7 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For mean parameter <code>p</code>, the variance is <code>p</code>
|
* For mean parameter <code>p</code>, the variance is <code>p</code>
|
||||||
*
|
*
|
||||||
* @return {@inheritDoc}
|
* @return {@inheritDoc}
|
||||||
|
@ -281,7 +281,7 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
|
||||||
protected double calculateNumericalVariance() {
|
protected double calculateNumericalVariance() {
|
||||||
return getMean();
|
return getMean();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -202,8 +202,8 @@ public class TDistributionImpl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The lower bound of the support is always negative infinity
|
* The lower bound of the support is always negative infinity
|
||||||
* no matter the parameters.
|
* no matter the parameters.
|
||||||
*
|
*
|
||||||
* @return lower bound of the support (always Double.NEGATIVE_INFINITY)
|
* @return lower bound of the support (always Double.NEGATIVE_INFINITY)
|
||||||
|
@ -215,8 +215,8 @@ public class TDistributionImpl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The upper bound of the support is always positive infinity
|
* The upper bound of the support is always positive infinity
|
||||||
* no matter the parameters.
|
* no matter the parameters.
|
||||||
*
|
*
|
||||||
* @return upper bound of the support (always Double.POSITIVE_INFINITY)
|
* @return upper bound of the support (always Double.POSITIVE_INFINITY)
|
||||||
|
@ -228,7 +228,7 @@ public class TDistributionImpl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For degrees of freedom parameter df, the mean is
|
* For degrees of freedom parameter df, the mean is
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>if <code>df > 1</code> then <code>0</code></li>
|
* <li>if <code>df > 1</code> then <code>0</code></li>
|
||||||
|
@ -240,17 +240,17 @@ public class TDistributionImpl
|
||||||
@Override
|
@Override
|
||||||
protected double calculateNumericalMean() {
|
protected double calculateNumericalMean() {
|
||||||
final double df = getDegreesOfFreedom();
|
final double df = getDegreesOfFreedom();
|
||||||
|
|
||||||
if (df > 1) {
|
if (df > 1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Double.NaN;
|
return Double.NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For degrees of freedom parameter df, the variance is
|
* For degrees of freedom parameter df, the variance is
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>if <code>df > 2</code> then <code>df / (df - 2)</code> </li>
|
* <li>if <code>df > 2</code> then <code>df / (df - 2)</code> </li>
|
||||||
|
@ -262,7 +262,7 @@ public class TDistributionImpl
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected double calculateNumericalVariance() {
|
protected double calculateNumericalVariance() {
|
||||||
final double df = getDegreesOfFreedom();
|
final double df = getDegreesOfFreedom();
|
||||||
|
|
||||||
if (df > 2) {
|
if (df > 2) {
|
||||||
return df / (df - 2);
|
return df / (df - 2);
|
||||||
|
@ -271,7 +271,7 @@ public class TDistributionImpl
|
||||||
if (df > 1 && df <= 2) {
|
if (df > 1 && df <= 2) {
|
||||||
return Double.POSITIVE_INFINITY;
|
return Double.POSITIVE_INFINITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Double.NaN;
|
return Double.NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -219,7 +219,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The lower bound of the support is always 0 no matter the parameters.
|
* The lower bound of the support is always 0 no matter the parameters.
|
||||||
*
|
*
|
||||||
* @return lower bound of the support (always 0)
|
* @return lower bound of the support (always 0)
|
||||||
|
@ -231,8 +231,8 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The upper bound of the support is always positive infinity
|
* The upper bound of the support is always positive infinity
|
||||||
* no matter the parameters.
|
* no matter the parameters.
|
||||||
*
|
*
|
||||||
* @return upper bound of the support (always Double.POSITIVE_INFINITY)
|
* @return upper bound of the support (always Double.POSITIVE_INFINITY)
|
||||||
|
@ -244,7 +244,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The mean is <code>scale * Gamma(1 + (1 / shape))</code>
|
* The mean is <code>scale * Gamma(1 + (1 / shape))</code>
|
||||||
* where <code>Gamma(...)</code> is the Gamma-function
|
* where <code>Gamma(...)</code> is the Gamma-function
|
||||||
*
|
*
|
||||||
|
@ -260,9 +260,9 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The variance is
|
* The variance is
|
||||||
* <code>scale^2 * Gamma(1 + (2 / shape)) - mean^2</code>
|
* <code>scale^2 * Gamma(1 + (2 / shape)) - mean^2</code>
|
||||||
* where <code>Gamma(...)</code> is the Gamma-function
|
* where <code>Gamma(...)</code> is the Gamma-function
|
||||||
*
|
*
|
||||||
* @return {@inheritDoc}
|
* @return {@inheritDoc}
|
||||||
|
@ -273,7 +273,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
|
||||||
final double sc = getScale();
|
final double sc = getScale();
|
||||||
final double mn = getNumericalMean();
|
final double mn = getNumericalMean();
|
||||||
|
|
||||||
return (sc * sc) *
|
return (sc * sc) *
|
||||||
FastMath.exp(Gamma.logGamma(1 + (2 / sh))) -
|
FastMath.exp(Gamma.logGamma(1 + (2 / sh))) -
|
||||||
(mn * mn);
|
(mn * mn);
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,19 +150,19 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The lower bound of the support is always 1 no matter the parameters.
|
* The lower bound of the support is always 1 no matter the parameters.
|
||||||
*
|
*
|
||||||
* @return lower bound of the support (always 1)
|
* @return lower bound of the support (always 1)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getSupportLowerBound() {
|
public int getSupportLowerBound() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* The upper bound of the support is the number of elements
|
* The upper bound of the support is the number of elements
|
||||||
*
|
*
|
||||||
* @return upper bound of the support
|
* @return upper bound of the support
|
||||||
|
@ -174,11 +174,11 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For number of elements N and exponent s, the mean is
|
* For number of elements N and exponent s, the mean is
|
||||||
* <code>Hs1 / Hs</code> where
|
* <code>Hs1 / Hs</code> where
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li><code>Hs1 = generalizedHarmonic(N, s - 1)</code></li>
|
* <li><code>Hs1 = generalizedHarmonic(N, s - 1)</code></li>
|
||||||
* <li><code>Hs = generalizedHarmonic(N, s)</code></li>
|
* <li><code>Hs = generalizedHarmonic(N, s)</code></li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
|
@ -188,7 +188,7 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
|
||||||
protected double calculateNumericalMean() {
|
protected double calculateNumericalMean() {
|
||||||
final int N = getNumberOfElements();
|
final int N = getNumberOfElements();
|
||||||
final double s = getExponent();
|
final double s = getExponent();
|
||||||
|
|
||||||
final double Hs1 = generalizedHarmonic(N, s - 1);
|
final double Hs1 = generalizedHarmonic(N, s - 1);
|
||||||
final double Hs = generalizedHarmonic(N, s);
|
final double Hs = generalizedHarmonic(N, s);
|
||||||
|
|
||||||
|
@ -197,22 +197,22 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* For number of elements N and exponent s, the mean is
|
* For number of elements N and exponent s, the mean is
|
||||||
* <code>(Hs2 / Hs) - (Hs1^2 / Hs^2)</code> where
|
* <code>(Hs2 / Hs) - (Hs1^2 / Hs^2)</code> where
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li><code>Hs2 = generalizedHarmonic(N, s - 2)</code></li>
|
* <li><code>Hs2 = generalizedHarmonic(N, s - 2)</code></li>
|
||||||
* <li><code>Hs1 = generalizedHarmonic(N, s - 1)</code></li>
|
* <li><code>Hs1 = generalizedHarmonic(N, s - 1)</code></li>
|
||||||
* <li><code>Hs = generalizedHarmonic(N, s)</code></li>
|
* <li><code>Hs = generalizedHarmonic(N, s)</code></li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @return {@inheritDoc}
|
* @return {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected double calculateNumericalVariance() {
|
protected double calculateNumericalVariance() {
|
||||||
final int N = getNumberOfElements();
|
final int N = getNumberOfElements();
|
||||||
final double s = getExponent();
|
final double s = getExponent();
|
||||||
|
|
||||||
final double Hs2 = generalizedHarmonic(N, s - 2);
|
final double Hs2 = generalizedHarmonic(N, s - 2);
|
||||||
final double Hs1 = generalizedHarmonic(N, s - 1);
|
final double Hs1 = generalizedHarmonic(N, s - 1);
|
||||||
final double Hs = generalizedHarmonic(N, s);
|
final double Hs = generalizedHarmonic(N, s);
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class Erf {
|
||||||
* <p>This implementation computes erf(x) using the
|
* <p>This implementation computes erf(x) using the
|
||||||
* {@link Gamma#regularizedGammaP(double, double, double, int) regularized gamma function},
|
* {@link Gamma#regularizedGammaP(double, double, double, int) regularized gamma function},
|
||||||
* following <a href="http://mathworld.wolfram.com/Erf.html"> Erf</a>, equation (3)</p>
|
* following <a href="http://mathworld.wolfram.com/Erf.html"> Erf</a>, equation (3)</p>
|
||||||
*
|
*
|
||||||
* <p>The value returned is always between -1 and 1 (inclusive). If {@code abs(x) > 40}, then
|
* <p>The value returned is always between -1 and 1 (inclusive). If {@code abs(x) > 40}, then
|
||||||
* {@code erf(x)} is indistinguishable from either 1 or -1 as a double, so the appropriate extreme
|
* {@code erf(x)} is indistinguishable from either 1 or -1 as a double, so the appropriate extreme
|
||||||
* value is returned.</p>
|
* value is returned.</p>
|
||||||
|
@ -61,7 +61,7 @@ public class Erf {
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Returns the complementary error function</p>
|
* <p>Returns the complementary error function</p>
|
||||||
* <p>erfc(x) = 2/√π <sub>x</sub>∫<sup>∞</sup> e<sup>-t<sup>2</sup></sup>dt <br/>
|
* <p>erfc(x) = 2/√π <sub>x</sub>∫<sup>∞</sup> e<sup>-t<sup>2</sup></sup>dt <br/>
|
||||||
|
@ -70,11 +70,11 @@ public class Erf {
|
||||||
* <p>This implementation computes erfc(x) using the
|
* <p>This implementation computes erfc(x) using the
|
||||||
* {@link Gamma#regularizedGammaQ(double, double, double, int) regularized gamma function},
|
* {@link Gamma#regularizedGammaQ(double, double, double, int) regularized gamma function},
|
||||||
* following <a href="http://mathworld.wolfram.com/Erf.html"> Erf</a>, equation (3).</p>
|
* following <a href="http://mathworld.wolfram.com/Erf.html"> Erf</a>, equation (3).</p>
|
||||||
*
|
*
|
||||||
* <p>The value returned is always between 0 and 2 (inclusive). If {@code abs(x) > 40}, then
|
* <p>The value returned is always between 0 and 2 (inclusive). If {@code abs(x) > 40}, then
|
||||||
* {@code erf(x)} is indistinguishable from either 0 or 2 as a double, so the appropriate extreme
|
* {@code erf(x)} is indistinguishable from either 0 or 2 as a double, so the appropriate extreme
|
||||||
* value is returned.</p>
|
* value is returned.</p>
|
||||||
*
|
*
|
||||||
* @param x the value
|
* @param x the value
|
||||||
* @return the complementary error function erfc(x)
|
* @return the complementary error function erfc(x)
|
||||||
* @throws MathException if the algorithm fails to converge
|
* @throws MathException if the algorithm fails to converge
|
||||||
|
|
|
@ -243,9 +243,9 @@ public class Frequency implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of values in the frequency table.
|
* Returns the number of values in the frequency table.
|
||||||
*
|
*
|
||||||
* @return the number of unique values that have been added to the frequency table.
|
* @return the number of unique values that have been added to the frequency table.
|
||||||
* @see #valuesIterator()
|
* @see #valuesIterator()
|
||||||
*/
|
*/
|
||||||
public int getUniqueCount(){
|
public int getUniqueCount(){
|
||||||
return freqTable.keySet().size();
|
return freqTable.keySet().size();
|
||||||
|
|
|
@ -126,7 +126,7 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable {
|
||||||
/**
|
/**
|
||||||
* Construct a DescriptiveStatistics instance with an infinite window
|
* Construct a DescriptiveStatistics instance with an infinite window
|
||||||
* and the initial data values in double[] initialDoubleArray.
|
* and the initial data values in double[] initialDoubleArray.
|
||||||
* If initialDoubleArray is null, then this constructor corresponds to
|
* If initialDoubleArray is null, then this constructor corresponds to
|
||||||
* DescriptiveStatistics()
|
* DescriptiveStatistics()
|
||||||
*
|
*
|
||||||
* @param initialDoubleArray the initial double[].
|
* @param initialDoubleArray the initial double[].
|
||||||
|
@ -136,7 +136,7 @@ public class DescriptiveStatistics implements StatisticalSummary, Serializable {
|
||||||
eDA = new ResizableDoubleArray(initialDoubleArray);
|
eDA = new ResizableDoubleArray(initialDoubleArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy constructor. Construct a new DescriptiveStatistics instance that
|
* Copy constructor. Construct a new DescriptiveStatistics instance that
|
||||||
* is a copy of original.
|
* is a copy of original.
|
||||||
|
|
|
@ -160,7 +160,7 @@ public class StatisticalSummaryValues implements Serializable,
|
||||||
result = result * 31 + MathUtils.hash(getVariance());
|
result = result * 31 + MathUtils.hash(getVariance());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a text report displaying values of statistics.
|
* Generates a text report displaying values of statistics.
|
||||||
* Each statistic is displayed on a separate line.
|
* Each statistic is displayed on a separate line.
|
||||||
|
|
|
@ -20,7 +20,7 @@ import org.apache.commons.math.MathException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface for Mann-Whitney U test (also called Wilcoxon rank-sum test).
|
* An interface for Mann-Whitney U test (also called Wilcoxon rank-sum test).
|
||||||
*
|
*
|
||||||
* @version $Revision$ $Date$
|
* @version $Revision$ $Date$
|
||||||
*/
|
*/
|
||||||
public interface MannWhitneyUTest {
|
public interface MannWhitneyUTest {
|
||||||
|
@ -46,7 +46,7 @@ public interface MannWhitneyUTest {
|
||||||
* <li>The observations are at least ordinal (continuous are also ordinal).</li>
|
* <li>The observations are at least ordinal (continuous are also ordinal).</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param x
|
* @param x
|
||||||
* the first sample
|
* the first sample
|
||||||
* @param y
|
* @param y
|
||||||
|
@ -76,7 +76,7 @@ public interface MannWhitneyUTest {
|
||||||
* <li>The observations are at least ordinal (continuous are also ordinal).</li>
|
* <li>The observations are at least ordinal (continuous are also ordinal).</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param x
|
* @param x
|
||||||
* the first sample
|
* the first sample
|
||||||
* @param y
|
* @param y
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.apache.commons.math.util.FastMath;
|
||||||
/**
|
/**
|
||||||
* An implementation of the Mann-Whitney U test (also called Wilcoxon rank-sum
|
* An implementation of the Mann-Whitney U test (also called Wilcoxon rank-sum
|
||||||
* test).
|
* test).
|
||||||
*
|
*
|
||||||
* @version $Revision$ $Date$
|
* @version $Revision$ $Date$
|
||||||
*/
|
*/
|
||||||
public class MannWhitneyUTestImpl implements MannWhitneyUTest {
|
public class MannWhitneyUTestImpl implements MannWhitneyUTest {
|
||||||
|
@ -45,7 +45,7 @@ public class MannWhitneyUTestImpl implements MannWhitneyUTest {
|
||||||
/**
|
/**
|
||||||
* Create a test instance using the given strategies for NaN's and ties.
|
* Create a test instance using the given strategies for NaN's and ties.
|
||||||
* Only use this if you are sure of what you are doing.
|
* Only use this if you are sure of what you are doing.
|
||||||
*
|
*
|
||||||
* @param nanStrategy
|
* @param nanStrategy
|
||||||
* specifies the strategy that should be used for Double.NaN's
|
* specifies the strategy that should be used for Double.NaN's
|
||||||
* @param tiesStrategy
|
* @param tiesStrategy
|
||||||
|
@ -58,7 +58,7 @@ public class MannWhitneyUTestImpl implements MannWhitneyUTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that the provided arrays fulfills the assumptions.
|
* Ensures that the provided arrays fulfills the assumptions.
|
||||||
*
|
*
|
||||||
* @param x
|
* @param x
|
||||||
* @param y
|
* @param y
|
||||||
* @throws IllegalArgumentException
|
* @throws IllegalArgumentException
|
||||||
|
@ -96,7 +96,7 @@ public class MannWhitneyUTestImpl implements MannWhitneyUTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* @param x
|
* @param x
|
||||||
* the first sample
|
* the first sample
|
||||||
* @param y
|
* @param y
|
||||||
|
@ -148,7 +148,7 @@ public class MannWhitneyUTestImpl implements MannWhitneyUTest {
|
||||||
*/
|
*/
|
||||||
private double calculateAsymptoticPValue(final double Umin, final int n1,
|
private double calculateAsymptoticPValue(final double Umin, final int n1,
|
||||||
final int n2) throws MathException {
|
final int n2) throws MathException {
|
||||||
|
|
||||||
final int n1n2prod = n1 * n2;
|
final int n1n2prod = n1 * n2;
|
||||||
|
|
||||||
// http://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U#Normal_approximation
|
// http://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U#Normal_approximation
|
||||||
|
@ -167,9 +167,9 @@ public class MannWhitneyUTestImpl implements MannWhitneyUTest {
|
||||||
* Ties give rise to biased variance at the moment. See e.g. <a
|
* Ties give rise to biased variance at the moment. See e.g. <a
|
||||||
* href="http://mlsc.lboro.ac.uk/resources/statistics/Mannwhitney.pdf"
|
* href="http://mlsc.lboro.ac.uk/resources/statistics/Mannwhitney.pdf"
|
||||||
* >http://mlsc.lboro.ac.uk/resources/statistics/Mannwhitney.pdf</a>.
|
* >http://mlsc.lboro.ac.uk/resources/statistics/Mannwhitney.pdf</a>.
|
||||||
*
|
*
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* @param x
|
* @param x
|
||||||
* the first sample
|
* the first sample
|
||||||
* @param y
|
* @param y
|
||||||
|
@ -184,13 +184,13 @@ public class MannWhitneyUTestImpl implements MannWhitneyUTest {
|
||||||
throws IllegalArgumentException, MathException {
|
throws IllegalArgumentException, MathException {
|
||||||
|
|
||||||
ensureDataConformance(x, y);
|
ensureDataConformance(x, y);
|
||||||
|
|
||||||
final double Umax = mannWhitneyU(x, y);
|
final double Umax = mannWhitneyU(x, y);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* It can be shown that U1 + U2 = n1 * n2
|
* It can be shown that U1 + U2 = n1 * n2
|
||||||
*/
|
*/
|
||||||
final double Umin = x.length * y.length - Umax;
|
final double Umin = x.length * y.length - Umax;
|
||||||
|
|
||||||
return calculateAsymptoticPValue(Umin, x.length, y.length);
|
return calculateAsymptoticPValue(Umin, x.length, y.length);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import org.apache.commons.math.MathException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface for Wilcoxon signed-rank test.
|
* An interface for Wilcoxon signed-rank test.
|
||||||
*
|
*
|
||||||
* @version $Revision$ $Date$
|
* @version $Revision$ $Date$
|
||||||
*/
|
*/
|
||||||
public interface WilcoxonSignedRankTest {
|
public interface WilcoxonSignedRankTest {
|
||||||
|
@ -51,7 +51,7 @@ public interface WilcoxonSignedRankTest {
|
||||||
* meaningful.</li>
|
* meaningful.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param x
|
* @param x
|
||||||
* the first sample
|
* the first sample
|
||||||
* @param y
|
* @param y
|
||||||
|
@ -86,7 +86,7 @@ public interface WilcoxonSignedRankTest {
|
||||||
* meaningful.</li>
|
* meaningful.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param x
|
* @param x
|
||||||
* the first sample
|
* the first sample
|
||||||
* @param y
|
* @param y
|
||||||
|
|
|
@ -25,7 +25,7 @@ import org.apache.commons.math.util.FastMath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of the Wilcoxon signed-rank test.
|
* An implementation of the Wilcoxon signed-rank test.
|
||||||
*
|
*
|
||||||
* @version $Revision$ $Date$
|
* @version $Revision$ $Date$
|
||||||
*/
|
*/
|
||||||
public class WilcoxonSignedRankTestImpl implements WilcoxonSignedRankTest {
|
public class WilcoxonSignedRankTestImpl implements WilcoxonSignedRankTest {
|
||||||
|
@ -44,7 +44,7 @@ public class WilcoxonSignedRankTestImpl implements WilcoxonSignedRankTest {
|
||||||
/**
|
/**
|
||||||
* Create a test instance using the given strategies for NaN's and ties.
|
* Create a test instance using the given strategies for NaN's and ties.
|
||||||
* Only use this if you are sure of what you are doing.
|
* Only use this if you are sure of what you are doing.
|
||||||
*
|
*
|
||||||
* @param nanStrategy
|
* @param nanStrategy
|
||||||
* specifies the strategy that should be used for Double.NaN's
|
* specifies the strategy that should be used for Double.NaN's
|
||||||
* @param tiesStrategy
|
* @param tiesStrategy
|
||||||
|
@ -57,7 +57,7 @@ public class WilcoxonSignedRankTestImpl implements WilcoxonSignedRankTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that the provided arrays fulfills the assumptions.
|
* Ensures that the provided arrays fulfills the assumptions.
|
||||||
*
|
*
|
||||||
* @param x
|
* @param x
|
||||||
* @param y
|
* @param y
|
||||||
* @throws IllegalArgumentException
|
* @throws IllegalArgumentException
|
||||||
|
@ -86,7 +86,7 @@ public class WilcoxonSignedRankTestImpl implements WilcoxonSignedRankTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates y[i] - x[i] for all i
|
* Calculates y[i] - x[i] for all i
|
||||||
*
|
*
|
||||||
* @param x
|
* @param x
|
||||||
* @param y
|
* @param y
|
||||||
* @throws IllegalArgumentException
|
* @throws IllegalArgumentException
|
||||||
|
@ -106,7 +106,7 @@ public class WilcoxonSignedRankTestImpl implements WilcoxonSignedRankTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates |z[i]| for all i
|
* Calculates |z[i]| for all i
|
||||||
*
|
*
|
||||||
* @param z
|
* @param z
|
||||||
* @throws IllegalArgumentException
|
* @throws IllegalArgumentException
|
||||||
* if assumptions are not met
|
* if assumptions are not met
|
||||||
|
@ -133,7 +133,7 @@ public class WilcoxonSignedRankTestImpl implements WilcoxonSignedRankTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* @param x
|
* @param x
|
||||||
* the first sample
|
* the first sample
|
||||||
* @param y
|
* @param y
|
||||||
|
@ -144,7 +144,7 @@ public class WilcoxonSignedRankTestImpl implements WilcoxonSignedRankTest {
|
||||||
*/
|
*/
|
||||||
public double wilcoxonSignedRank(final double[] x, final double[] y)
|
public double wilcoxonSignedRank(final double[] x, final double[] y)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
|
|
||||||
ensureDataConformance(x, y);
|
ensureDataConformance(x, y);
|
||||||
|
|
||||||
// throws IllegalArgumentException if x and y are not correctly
|
// throws IllegalArgumentException if x and y are not correctly
|
||||||
|
@ -171,12 +171,12 @@ public class WilcoxonSignedRankTestImpl implements WilcoxonSignedRankTest {
|
||||||
/**
|
/**
|
||||||
* Algorithm inspired by
|
* Algorithm inspired by
|
||||||
* http://www.fon.hum.uva.nl/Service/Statistics/Signed_Rank_Algorihms.html#C
|
* http://www.fon.hum.uva.nl/Service/Statistics/Signed_Rank_Algorihms.html#C
|
||||||
* by Rob van Son, Institute of Phonetic Sciences & IFOTT,
|
* by Rob van Son, Institute of Phonetic Sciences & IFOTT,
|
||||||
* University of Amsterdam
|
* University of Amsterdam
|
||||||
*
|
*
|
||||||
* @param Wmax largest Wilcoxon signed rank value
|
* @param Wmax largest Wilcoxon signed rank value
|
||||||
* @param N number of subjects (corresponding to x.length)
|
* @param N number of subjects (corresponding to x.length)
|
||||||
* @return two-sided exact p-value
|
* @return two-sided exact p-value
|
||||||
*/
|
*/
|
||||||
private double calculateExactPValue(final double Wmax, final int N) {
|
private double calculateExactPValue(final double Wmax, final int N) {
|
||||||
|
|
||||||
|
@ -208,22 +208,22 @@ public class WilcoxonSignedRankTestImpl implements WilcoxonSignedRankTest {
|
||||||
*/
|
*/
|
||||||
return 2 * ((double) largerRankSums) / ((double) m);
|
return 2 * ((double) largerRankSums) / ((double) m);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Wmin smallest Wilcoxon signed rank value
|
* @param Wmin smallest Wilcoxon signed rank value
|
||||||
* @param N number of subjects (corresponding to x.length)
|
* @param N number of subjects (corresponding to x.length)
|
||||||
* @return two-sided asymptotic p-value
|
* @return two-sided asymptotic p-value
|
||||||
* @throws MathException if an error occurs computing the p-value
|
* @throws MathException if an error occurs computing the p-value
|
||||||
*/
|
*/
|
||||||
private double calculateAsymptoticPValue(final double Wmin, final int N) throws MathException {
|
private double calculateAsymptoticPValue(final double Wmin, final int N) throws MathException {
|
||||||
|
|
||||||
final double ES = (double) (N * (N + 1)) / 4.0;
|
final double ES = (double) (N * (N + 1)) / 4.0;
|
||||||
|
|
||||||
/* Same as (but saves computations):
|
/* Same as (but saves computations):
|
||||||
* final double VarW = ((double) (N * (N + 1) * (2*N + 1))) / 24;
|
* final double VarW = ((double) (N * (N + 1) * (2*N + 1))) / 24;
|
||||||
*/
|
*/
|
||||||
final double VarS = ES * ((double) (2 * N + 1) / 6.0);
|
final double VarS = ES * ((double) (2 * N + 1) / 6.0);
|
||||||
|
|
||||||
// - 0.5 is a continuity correction
|
// - 0.5 is a continuity correction
|
||||||
final double z = (Wmin - ES - 0.5) / FastMath.sqrt(VarS);
|
final double z = (Wmin - ES - 0.5) / FastMath.sqrt(VarS);
|
||||||
|
|
||||||
|
@ -234,7 +234,7 @@ public class WilcoxonSignedRankTestImpl implements WilcoxonSignedRankTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* @param x
|
* @param x
|
||||||
* the first sample
|
* the first sample
|
||||||
* @param y
|
* @param y
|
||||||
|
@ -251,16 +251,16 @@ public class WilcoxonSignedRankTestImpl implements WilcoxonSignedRankTest {
|
||||||
public double wilcoxonSignedRankTest(final double[] x, final double[] y,
|
public double wilcoxonSignedRankTest(final double[] x, final double[] y,
|
||||||
boolean exactPValue) throws IllegalArgumentException,
|
boolean exactPValue) throws IllegalArgumentException,
|
||||||
MathException {
|
MathException {
|
||||||
|
|
||||||
ensureDataConformance(x, y);
|
ensureDataConformance(x, y);
|
||||||
|
|
||||||
final int N = x.length;
|
final int N = x.length;
|
||||||
final double Wmax = wilcoxonSignedRank(x, y);
|
final double Wmax = wilcoxonSignedRank(x, y);
|
||||||
|
|
||||||
if (exactPValue && N > 30) {
|
if (exactPValue && N > 30) {
|
||||||
throw new IllegalArgumentException("Exact test can only be made for N <= 30.");
|
throw new IllegalArgumentException("Exact test can only be made for N <= 30.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exactPValue) {
|
if (exactPValue) {
|
||||||
return calculateExactPValue(Wmax, N);
|
return calculateExactPValue(Wmax, N);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -187,7 +187,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
|
||||||
numElements = initialArray.length;
|
numElements = initialArray.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Create a ResizableArray with the specified initial capacity
|
* Create a ResizableArray with the specified initial capacity
|
||||||
|
@ -302,7 +302,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
|
||||||
contract();
|
contract();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds several element to the end of this expandable array.
|
* Adds several element to the end of this expandable array.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue