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

public final Class StatUtils

extends Object
Class Inheritance
Imports
java.util.List, org.apache.commons.math3.exception.MathIllegalArgumentException, .NotPositiveException, .NullArgumentException, .NumberIsTooSmallException, .DimensionMismatchException, .NoDataException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.stat.descriptive.DescriptiveStatistics, .UnivariateStatistic, org.apache.commons.math3.stat.descriptive.moment.GeometricMean, .Mean, .Variance, org.apache.commons.math3.stat.descriptive.rank.Max, .Min, .Percentile, org.apache.commons.math3.stat.descriptive.summary.Product, .Sum, .SumOfLogs, .SumOfSquares

StatUtils provides static methods for computing statistics based on data stored in double[] arrays.

Field Summary

Modifier and TypeField and Description
private static final GeometricMean
GEOMETRIC_MEAN

geometric mean

private static final UnivariateStatistic
MAX

max

private static final UnivariateStatistic
MEAN

mean

private static final UnivariateStatistic
MIN

min

private static final Percentile
PERCENTILE

percentile

private static final UnivariateStatistic
PRODUCT

prod

private static final UnivariateStatistic
SUM

sum

private static final UnivariateStatistic
private static final UnivariateStatistic
private static final Variance
VARIANCE

variance

Constructor Summary

AccessConstructor and Description
private
StatUtils()

Private Constructor

Method Summary

Modifier and TypeMethod and Description
public static double

Returns:

the geometric mean of the values or Double.NaN if the array is empty
geometricMean
(final double[]
the input array
values
)

Returns the geometric mean of the entries in the input array, or Double.NaN if the array is empty.

public static double

Returns:

the geometric mean of the values or Double.NaN if length = 0
geometricMean
(final double[]
the input array
values
,
final int
index of the first array element to include
begin
,
final int
the number of elements to include
length
)

Returns the geometric mean of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

private static double[]

Returns:

array of array of the most frequently occurring element(s) sorted in ascending order.
getMode
(double[]
input data
values
,
final int
index (0-based) of the first array element to include
begin
,
final int
the number of elements to include
length
)

Private helper method.

public static double

Returns:

the maximum of the values or Double.NaN if the array is empty
max
(final double[]
the input array
values
)

Returns the maximum of the entries in the input array, or Double.NaN if the array is empty.

public static double

Returns:

the maximum of the values or Double.NaN if length = 0
max
(final double[]
the input array
values
,
final int
index of the first array element to include
begin
,
final int
the number of elements to include
length
)

Returns the maximum of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

public static double

Returns:

the mean of the values or Double.NaN if the array is empty
mean
(final double[]
the input array
values
)

Returns the arithmetic mean of the entries in the input array, or Double.NaN if the array is empty.

public static double

Returns:

the mean of the values or Double.NaN if length = 0
mean
(final double[]
the input array
values
,
final int
index of the first array element to include
begin
,
final int
the number of elements to include
length
)

Returns the arithmetic mean of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

public static double

Returns:

mean of paired differences
meanDifference
(final double[]
the first array
sample1
,
final double[]
the second array
sample2
)

Returns the mean of the (signed) differences between corresponding elements of the input arrays -- i.e., sum(sample1[i] - sample2[i]) / sample1.length.

public static double

Returns:

the minimum of the values or Double.NaN if the array is empty
min
(final double[]
the input array
values
)

Returns the minimum of the entries in the input array, or Double.NaN if the array is empty.

public static double

Returns:

the minimum of the values or Double.NaN if length = 0
min
(final double[]
the input array
values
,
final int
index of the first array element to include
begin
,
final int
the number of elements to include
length
)

Returns the minimum of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

public static double[]

Returns:

array of array of the most frequently occurring element(s) sorted in ascending order.
mode
(double[]
input data
sample
)

Returns the sample mode(s).

public static double[]

Returns:

array of array of the most frequently occurring element(s) sorted in ascending order.
mode
(double[]
input data
sample
,
final int
index (0-based) of the first array element to include
begin
,
final int
the number of elements to include
length
)

Returns the sample mode(s).

public static double[]

Returns:

normalized (standardized) sample.
normalize
(final double[]
Sample to normalize.
sample
)

Normalize (standardize) the sample, so it is has a mean of 0 and a standard deviation of 1.

public static double

Returns:

the percentile value or Double.NaN if the array is empty
percentile
(final double[]
input array of values
values
,
final double
the percentile value to compute
p
)

Returns an estimate of the pth percentile of the values in the values array.

public static double

Returns:

the percentile value
percentile
(final double[]
array of input values
values
,
final int
the first (0-based) element to include in the computation
begin
,
final int
the number of array elements to include
length
,
final double
the percentile to compute
p
)

Returns an estimate of the pth percentile of the values in the values array, starting with the element in (0-based) position begin in the array and including length values.

public static double

Returns:

the population variance of the values or Double.NaN if the array is empty
populationVariance
(final double[]
the input array
values
)

Returns the population variance of the entries in the input array, or Double.NaN if the array is empty.

public static double

Returns:

the population variance of the values or Double.NaN if length = 0
populationVariance
(final double[]
the input array
values
,
final int
index of the first array element to include
begin
,
final int
the number of elements to include
length
)

Returns the population variance of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

public static double

Returns:

the population variance of the values or Double.NaN if length = 0
populationVariance
(final double[]
the input array
values
,
final double
the precomputed mean value
mean
,
final int
index of the first array element to include
begin
,
final int
the number of elements to include
length
)

Returns the population variance of the entries in the specified portion of the input array, using the precomputed mean value.

public static double

Returns:

the population variance of the values or Double.NaN if the array is empty
populationVariance
(final double[]
the input array
values
,
final double
the precomputed mean value
mean
)

Returns the population variance of the entries in the input array, using the precomputed mean value.

public static double

Returns:

the product of the values or Double.NaN if the array is empty
product
(final double[]
the input array
values
)

Returns the product of the entries in the input array, or Double.NaN if the array is empty.

public static double

Returns:

the product of the values or Double.NaN if length = 0
product
(final double[]
the input array
values
,
final int
index of the first array element to include
begin
,
final int
the number of elements to include
length
)

Returns the product of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

public static double

Returns:

the sum of the values or Double.NaN if the array is empty
sum
(final double[]
array of values to sum
values
)

Returns the sum of the values in the input array, or Double.NaN if the array is empty.

public static double

Returns:

the sum of the values or Double.NaN if length = 0
sum
(final double[]
the input array
values
,
final int
index of the first array element to include
begin
,
final int
the number of elements to include
length
)

Returns the sum of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

public static double

Returns:

sum of paired differences
sumDifference
(final double[]
the first array
sample1
,
final double[]
the second array
sample2
)

Returns the sum of the (signed) differences between corresponding elements of the input arrays -- i.e., sum(sample1[i] - sample2[i]).

public static double

Returns:

the sum of the natural logs of the values or Double.NaN if the array is empty
sumLog
(final double[]
the input array
values
)

Returns the sum of the natural logs of the entries in the input array, or Double.NaN if the array is empty.

public static double

Returns:

the sum of the natural logs of the values or Double.NaN if length = 0
sumLog
(final double[]
the input array
values
,
final int
index of the first array element to include
begin
,
final int
the number of elements to include
length
)

Returns the sum of the natural logs of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

public static double

Returns:

the sum of the squared values or Double.NaN if the array is empty
sumSq
(final double[]
input array
values
)

Returns the sum of the squares of the entries in the input array, or Double.NaN if the array is empty.

public static double

Returns:

the sum of the squares of the values or Double.NaN if length = 0
sumSq
(final double[]
the input array
values
,
final int
index of the first array element to include
begin
,
final int
the number of elements to include
length
)

Returns the sum of the squares of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

public static double

Returns:

the variance of the values or Double.NaN if the array is empty
variance
(final double[]
the input array
values
)

Returns the variance of the entries in the input array, or Double.NaN if the array is empty.

public static double

Returns:

the variance of the values or Double.NaN if length = 0
variance
(final double[]
the input array
values
,
final int
index of the first array element to include
begin
,
final int
the number of elements to include
length
)

Returns the variance of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

public static double

Returns:

the variance of the values or Double.NaN if length = 0
variance
(final double[]
the input array
values
,
final double
the precomputed mean value
mean
,
final int
index of the first array element to include
begin
,
final int
the number of elements to include
length
)

Returns the variance of the entries in the specified portion of the input array, using the precomputed mean value.

public static double

Returns:

the variance of the values or Double.NaN if the array is empty
variance
(final double[]
the input array
values
,
final double
the precomputed mean value
mean
)

Returns the variance of the entries in the input array, using the precomputed mean value.

public static double

Returns:

variance of paired differences
varianceDifference
(final double[]
the first array
sample1
,
final double[]
the second array
sample2
,
double
the mean difference between corresponding entries
meanDifference
)

Returns the variance of the (signed) differences between corresponding elements of the input arrays -- i.e., var(sample1[i] - sample2[i]).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

GEOMETRIC_MEANback to summary
private static final GeometricMean GEOMETRIC_MEAN

geometric mean

MAXback to summary
private static final UnivariateStatistic MAX

max

MEANback to summary
private static final UnivariateStatistic MEAN

mean

MINback to summary
private static final UnivariateStatistic MIN

min

PERCENTILEback to summary
private static final Percentile PERCENTILE

percentile

PRODUCTback to summary
private static final UnivariateStatistic PRODUCT

prod

SUMback to summary
private static final UnivariateStatistic SUM

sum

SUM_OF_LOGSback to summary
private static final UnivariateStatistic SUM_OF_LOGS

sumLog

SUM_OF_SQUARESback to summary
private static final UnivariateStatistic SUM_OF_SQUARES

sumSq

VARIANCEback to summary
private static final Variance VARIANCE

variance

Constructor Detail

StatUtilsback to summary
private StatUtils()

Private Constructor

Method Detail

geometricMeanback to summary
public static double geometricMean(final double[] values) throws MathIllegalArgumentException

Returns the geometric mean of the entries in the input array, or Double.NaN if the array is empty.

Throws IllegalArgumentException if the array is null.

See org.apache.commons.math3.stat.descriptive.moment.GeometricMean for details on the computing algorithm.

Parameters
values:double[]

the input array

Returns:double

the geometric mean of the values or Double.NaN if the array is empty

Exceptions
MathIllegalArgumentException:
if the array is null
geometricMeanback to summary
public static double geometricMean(final double[] values, final int begin, final int length) throws MathIllegalArgumentException

Returns the geometric mean of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

Throws IllegalArgumentException if the array is null.

See org.apache.commons.math3.stat.descriptive.moment.GeometricMean for details on the computing algorithm.

Parameters
values:double[]

the input array

begin:int

index of the first array element to include

length:int

the number of elements to include

Returns:double

the geometric mean of the values or Double.NaN if length = 0

Exceptions
MathIllegalArgumentException:
if the array is null or the array index parameters are not valid
getModeback to summary
private static double[] getMode(double[] values, final int begin, final int length)

Private helper method. Assumes parameters have been validated.

Parameters
values:double[]

input data

begin:int

index (0-based) of the first array element to include

length:int

the number of elements to include

Returns:double[]

array of array of the most frequently occurring element(s) sorted in ascending order.

maxback to summary
public static double max(final double[] values) throws MathIllegalArgumentException

Returns the maximum of the entries in the input array, or Double.NaN if the array is empty.

Throws MathIllegalArgumentException if the array is null.

  • The result is NaN iff all values are NaN (i.e. NaN values have no impact on the value of the statistic).
  • If any of the values equals Double.POSITIVE_INFINITY, the result is Double.POSITIVE_INFINITY.

Parameters
values:double[]

the input array

Returns:double

the maximum of the values or Double.NaN if the array is empty

Exceptions
MathIllegalArgumentException:
if the array is null
maxback to summary
public static double max(final double[] values, final int begin, final int length) throws MathIllegalArgumentException

Returns the maximum of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

Throws MathIllegalArgumentException if the array is null or the array index parameters are not valid.

  • The result is NaN iff all values are NaN (i.e. NaN values have no impact on the value of the statistic).
  • If any of the values equals Double.POSITIVE_INFINITY, the result is Double.POSITIVE_INFINITY.

Parameters
values:double[]

the input array

begin:int

index of the first array element to include

length:int

the number of elements to include

Returns:double

the maximum of the values or Double.NaN if length = 0

Exceptions
MathIllegalArgumentException:
if the array is null or the array index parameters are not valid
meanback to summary
public static double mean(final double[] values) throws MathIllegalArgumentException

Returns the arithmetic mean of the entries in the input array, or Double.NaN if the array is empty.

Throws IllegalArgumentException if the array is null.

See org.apache.commons.math3.stat.descriptive.moment.Mean for details on the computing algorithm.

Parameters
values:double[]

the input array

Returns:double

the mean of the values or Double.NaN if the array is empty

Exceptions
MathIllegalArgumentException:
if the array is null
meanback to summary
public static double mean(final double[] values, final int begin, final int length) throws MathIllegalArgumentException

Returns the arithmetic mean of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

Throws IllegalArgumentException if the array is null.

See org.apache.commons.math3.stat.descriptive.moment.Mean for details on the computing algorithm.

Parameters
values:double[]

the input array

begin:int

index of the first array element to include

length:int

the number of elements to include

Returns:double

the mean of the values or Double.NaN if length = 0

Exceptions
MathIllegalArgumentException:
if the array is null or the array index parameters are not valid
meanDifferenceback to summary
public static double meanDifference(final double[] sample1, final double[] sample2) throws DimensionMismatchException, NoDataException

Returns the mean of the (signed) differences between corresponding elements of the input arrays -- i.e., sum(sample1[i] - sample2[i]) / sample1.length.

Parameters
sample1:double[]

the first array

sample2:double[]

the second array

Returns:double

mean of paired differences

Exceptions
DimensionMismatchException:
if the arrays do not have the same (positive) length.
NoDataException:
if the sample arrays are empty.
minback to summary
public static double min(final double[] values) throws MathIllegalArgumentException

Returns the minimum of the entries in the input array, or Double.NaN if the array is empty.

Throws MathIllegalArgumentException if the array is null.

  • The result is NaN iff all values are NaN (i.e. NaN values have no impact on the value of the statistic).
  • If any of the values equals Double.NEGATIVE_INFINITY, the result is Double.NEGATIVE_INFINITY.

Parameters
values:double[]

the input array

Returns:double

the minimum of the values or Double.NaN if the array is empty

Exceptions
MathIllegalArgumentException:
if the array is null
minback to summary
public static double min(final double[] values, final int begin, final int length) throws MathIllegalArgumentException

Returns the minimum of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

Throws MathIllegalArgumentException if the array is null or the array index parameters are not valid.

  • The result is NaN iff all values are NaN (i.e. NaN values have no impact on the value of the statistic).
  • If any of the values equals Double.NEGATIVE_INFINITY, the result is Double.NEGATIVE_INFINITY.

Parameters
values:double[]

the input array

begin:int

index of the first array element to include

length:int

the number of elements to include

Returns:double

the minimum of the values or Double.NaN if length = 0

Exceptions
MathIllegalArgumentException:
if the array is null or the array index parameters are not valid
modeback to summary
public static double[] mode(double[] sample) throws MathIllegalArgumentException

Returns the sample mode(s). The mode is the most frequently occurring value in the sample. If there is a unique value with maximum frequency, this value is returned as the only element of the output array. Otherwise, the returned array contains the maximum frequency elements in increasing order. For example, if sample is {0, 12, 5, 6, 0, 13, 5, 17}, the returned array will have length two, with 0 in the first element and 5 in the second.

NaN values are ignored when computing the mode - i.e., NaNs will never appear in the output array. If the sample includes only NaNs or has length 0, an empty array is returned.

Parameters
sample:double[]

input data

Returns:double[]

array of array of the most frequently occurring element(s) sorted in ascending order.

Exceptions
MathIllegalArgumentException:
if the indices are invalid or the array is null
Since
3.3
modeback to summary
public static double[] mode(double[] sample, final int begin, final int length)

Returns the sample mode(s). The mode is the most frequently occurring value in the sample. If there is a unique value with maximum frequency, this value is returned as the only element of the output array. Otherwise, the returned array contains the maximum frequency elements in increasing order. For example, if sample is {0, 12, 5, 6, 0, 13, 5, 17}, the returned array will have length two, with 0 in the first element and 5 in the second.

NaN values are ignored when computing the mode - i.e., NaNs will never appear in the output array. If the sample includes only NaNs or has length 0, an empty array is returned.

Parameters
sample:double[]

input data

begin:int

index (0-based) of the first array element to include

length:int

the number of elements to include

Returns:double[]

array of array of the most frequently occurring element(s) sorted in ascending order.

Exceptions
MathIllegalArgumentException:
if the indices are invalid or the array is null
Since
3.3
normalizeback to summary
public static double[] normalize(final double[] sample)

Normalize (standardize) the sample, so it is has a mean of 0 and a standard deviation of 1.

Parameters
sample:double[]

Sample to normalize.

Returns:double[]

normalized (standardized) sample.

Since
2.2
percentileback to summary
public static double percentile(final double[] values, final double p) throws MathIllegalArgumentException

Returns an estimate of the pth percentile of the values in the values array.

  • Returns Double.NaN if values has length 0
  • Returns (for any value of p) values[0] if values has length 1
  • Throws IllegalArgumentException if values is null or p is not a valid quantile value (p must be greater than 0 and less than or equal to 100)

See org.apache.commons.math3.stat.descriptive.rank.Percentile for a description of the percentile estimation algorithm used.

Parameters
values:double[]

input array of values

p:double

the percentile value to compute

Returns:double

the percentile value or Double.NaN if the array is empty

Exceptions
MathIllegalArgumentException:
if values is null or p is invalid
percentileback to summary
public static double percentile(final double[] values, final int begin, final int length, final double p) throws MathIllegalArgumentException

Returns an estimate of the pth percentile of the values in the values array, starting with the element in (0-based) position begin in the array and including length values.

  • Returns Double.NaN if length = 0
  • Returns (for any value of p) values[begin] if length = 1
  • Throws MathIllegalArgumentException if values is null , begin or length is invalid, or p is not a valid quantile value (p must be greater than 0 and less than or equal to 100)

See org.apache.commons.math3.stat.descriptive.rank.Percentile for a description of the percentile estimation algorithm used.

Parameters
values:double[]

array of input values

begin:int

the first (0-based) element to include in the computation

length:int

the number of array elements to include

p:double

the percentile to compute

Returns:double

the percentile value

Exceptions
MathIllegalArgumentException:
if the parameters are not valid or the input array is null
populationVarianceback to summary
public static double populationVariance(final double[] values) throws MathIllegalArgumentException

Returns the population variance of the entries in the input array, or Double.NaN if the array is empty.

See org.apache.commons.math3.stat.descriptive.moment.Variance for details on the formula and computing algorithm.

Returns 0 for a single-value (i.e. length = 1) sample.

Throws MathIllegalArgumentException if the array is null.

Parameters
values:double[]

the input array

Returns:double

the population variance of the values or Double.NaN if the array is empty

Exceptions
MathIllegalArgumentException:
if the array is null
populationVarianceback to summary
public static double populationVariance(final double[] values, final int begin, final int length) throws MathIllegalArgumentException

Returns the population variance of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

See org.apache.commons.math3.stat.descriptive.moment.Variance for details on the computing algorithm.

Returns 0 for a single-value (i.e. length = 1) sample.

Throws MathIllegalArgumentException if the array is null or the array index parameters are not valid.

Parameters
values:double[]

the input array

begin:int

index of the first array element to include

length:int

the number of elements to include

Returns:double

the population variance of the values or Double.NaN if length = 0

Exceptions
MathIllegalArgumentException:
if the array is null or the array index parameters are not valid
populationVarianceback to summary
public static double populationVariance(final double[] values, final double mean, final int begin, final int length) throws MathIllegalArgumentException

Returns the population variance of the entries in the specified portion of the input array, using the precomputed mean value. Returns Double.NaN if the designated subarray is empty.

See org.apache.commons.math3.stat.descriptive.moment.Variance for details on the computing algorithm.

The formula used assumes that the supplied mean value is the arithmetic mean of the sample data, not a known population parameter. This method is supplied only to save computation when the mean has already been computed.

Returns 0 for a single-value (i.e. length = 1) sample.

Throws MathIllegalArgumentException if the array is null or the array index parameters are not valid.

Parameters
values:double[]

the input array

mean:double

the precomputed mean value

begin:int

index of the first array element to include

length:int

the number of elements to include

Returns:double

the population variance of the values or Double.NaN if length = 0

Exceptions
MathIllegalArgumentException:
if the array is null or the array index parameters are not valid
populationVarianceback to summary
public static double populationVariance(final double[] values, final double mean) throws MathIllegalArgumentException

Returns the population variance of the entries in the input array, using the precomputed mean value. Returns Double.NaN if the array is empty.

See org.apache.commons.math3.stat.descriptive.moment.Variance for details on the computing algorithm.

The formula used assumes that the supplied mean value is the arithmetic mean of the sample data, not a known population parameter. This method is supplied only to save computation when the mean has already been computed.

Returns 0 for a single-value (i.e. length = 1) sample.

Throws MathIllegalArgumentException if the array is null.

Parameters
values:double[]

the input array

mean:double

the precomputed mean value

Returns:double

the population variance of the values or Double.NaN if the array is empty

Exceptions
MathIllegalArgumentException:
if the array is null
productback to summary
public static double product(final double[] values) throws MathIllegalArgumentException

Returns the product of the entries in the input array, or Double.NaN if the array is empty.

Throws IllegalArgumentException if the array is null.

Parameters
values:double[]

the input array

Returns:double

the product of the values or Double.NaN if the array is empty

Exceptions
MathIllegalArgumentException:
if the array is null
productback to summary
public static double product(final double[] values, final int begin, final int length) throws MathIllegalArgumentException

Returns the product of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

Throws IllegalArgumentException if the array is null.

Parameters
values:double[]

the input array

begin:int

index of the first array element to include

length:int

the number of elements to include

Returns:double

the product of the values or Double.NaN if length = 0

Exceptions
MathIllegalArgumentException:
if the array is null or the array index parameters are not valid
sumback to summary
public static double sum(final double[] values) throws MathIllegalArgumentException

Returns the sum of the values in the input array, or Double.NaN if the array is empty.

Throws IllegalArgumentException if the input array is null.

Parameters
values:double[]

array of values to sum

Returns:double

the sum of the values or Double.NaN if the array is empty

Exceptions
MathIllegalArgumentException:
if the array is null
sumback to summary
public static double sum(final double[] values, final int begin, final int length) throws MathIllegalArgumentException

Returns the sum of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

Throws IllegalArgumentException if the array is null.

Parameters
values:double[]

the input array

begin:int

index of the first array element to include

length:int

the number of elements to include

Returns:double

the sum of the values or Double.NaN if length = 0

Exceptions
MathIllegalArgumentException:
if the array is null or the array index parameters are not valid
sumDifferenceback to summary
public static double sumDifference(final double[] sample1, final double[] sample2) throws DimensionMismatchException, NoDataException

Returns the sum of the (signed) differences between corresponding elements of the input arrays -- i.e., sum(sample1[i] - sample2[i]).

Parameters
sample1:double[]

the first array

sample2:double[]

the second array

Returns:double

sum of paired differences

Exceptions
DimensionMismatchException:
if the arrays do not have the same (positive) length.
NoDataException:
if the sample arrays are empty.
sumLogback to summary
public static double sumLog(final double[] values) throws MathIllegalArgumentException

Returns the sum of the natural logs of the entries in the input array, or Double.NaN if the array is empty.

Throws IllegalArgumentException if the array is null.

See org.apache.commons.math3.stat.descriptive.summary.SumOfLogs.

Parameters
values:double[]

the input array

Returns:double

the sum of the natural logs of the values or Double.NaN if the array is empty

Exceptions
MathIllegalArgumentException:
if the array is null
sumLogback to summary
public static double sumLog(final double[] values, final int begin, final int length) throws MathIllegalArgumentException

Returns the sum of the natural logs of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

Throws IllegalArgumentException if the array is null.

See org.apache.commons.math3.stat.descriptive.summary.SumOfLogs.

Parameters
values:double[]

the input array

begin:int

index of the first array element to include

length:int

the number of elements to include

Returns:double

the sum of the natural logs of the values or Double.NaN if length = 0

Exceptions
MathIllegalArgumentException:
if the array is null or the array index parameters are not valid
sumSqback to summary
public static double sumSq(final double[] values) throws MathIllegalArgumentException

Returns the sum of the squares of the entries in the input array, or Double.NaN if the array is empty.

Throws IllegalArgumentException if the array is null.

Parameters
values:double[]

input array

Returns:double

the sum of the squared values or Double.NaN if the array is empty

Exceptions
MathIllegalArgumentException:
if the array is null
sumSqback to summary
public static double sumSq(final double[] values, final int begin, final int length) throws MathIllegalArgumentException

Returns the sum of the squares of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

Throws IllegalArgumentException if the array is null.

Parameters
values:double[]

the input array

begin:int

index of the first array element to include

length:int

the number of elements to include

Returns:double

the sum of the squares of the values or Double.NaN if length = 0

Exceptions
MathIllegalArgumentException:
if the array is null or the array index parameters are not valid
varianceback to summary
public static double variance(final double[] values) throws MathIllegalArgumentException

Returns the variance of the entries in the input array, or Double.NaN if the array is empty.

This method returns the bias-corrected sample variance (using n - 1 in the denominator). Use populationVariance(double[]) for the non-bias-corrected population variance.

See org.apache.commons.math3.stat.descriptive.moment.Variance for details on the computing algorithm.

Returns 0 for a single-value (i.e. length = 1) sample.

Throws MathIllegalArgumentException if the array is null.

Parameters
values:double[]

the input array

Returns:double

the variance of the values or Double.NaN if the array is empty

Exceptions
MathIllegalArgumentException:
if the array is null
varianceback to summary
public static double variance(final double[] values, final int begin, final int length) throws MathIllegalArgumentException

Returns the variance of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.

This method returns the bias-corrected sample variance (using n - 1 in the denominator). Use populationVariance(double[], int, int) for the non-bias-corrected population variance.

See org.apache.commons.math3.stat.descriptive.moment.Variance for details on the computing algorithm.

Returns 0 for a single-value (i.e. length = 1) sample.

Throws MathIllegalArgumentException if the array is null or the array index parameters are not valid.

Parameters
values:double[]

the input array

begin:int

index of the first array element to include

length:int

the number of elements to include

Returns:double

the variance of the values or Double.NaN if length = 0

Exceptions
MathIllegalArgumentException:
if the array is null or the array index parameters are not valid
varianceback to summary
public static double variance(final double[] values, final double mean, final int begin, final int length) throws MathIllegalArgumentException

Returns the variance of the entries in the specified portion of the input array, using the precomputed mean value. Returns Double.NaN if the designated subarray is empty.

This method returns the bias-corrected sample variance (using n - 1 in the denominator). Use populationVariance(double[], double, int, int) for the non-bias-corrected population variance.

See org.apache.commons.math3.stat.descriptive.moment.Variance for details on the computing algorithm.

The formula used assumes that the supplied mean value is the arithmetic mean of the sample data, not a known population parameter. This method is supplied only to save computation when the mean has already been computed.

Returns 0 for a single-value (i.e. length = 1) sample.

Throws MathIllegalArgumentException if the array is null or the array index parameters are not valid.

Parameters
values:double[]

the input array

mean:double

the precomputed mean value

begin:int

index of the first array element to include

length:int

the number of elements to include

Returns:double

the variance of the values or Double.NaN if length = 0

Exceptions
MathIllegalArgumentException:
if the array is null or the array index parameters are not valid
varianceback to summary
public static double variance(final double[] values, final double mean) throws MathIllegalArgumentException

Returns the variance of the entries in the input array, using the precomputed mean value. Returns Double.NaN if the array is empty.

This method returns the bias-corrected sample variance (using n - 1 in the denominator). Use populationVariance(double[], double) for the non-bias-corrected population variance.

See org.apache.commons.math3.stat.descriptive.moment.Variance for details on the computing algorithm.

The formula used assumes that the supplied mean value is the arithmetic mean of the sample data, not a known population parameter. This method is supplied only to save computation when the mean has already been computed.

Returns 0 for a single-value (i.e. length = 1) sample.

Throws MathIllegalArgumentException if the array is null.

Parameters
values:double[]

the input array

mean:double

the precomputed mean value

Returns:double

the variance of the values or Double.NaN if the array is empty

Exceptions
MathIllegalArgumentException:
if the array is null
varianceDifferenceback to summary
public static double varianceDifference(final double[] sample1, final double[] sample2, double meanDifference) throws DimensionMismatchException, NumberIsTooSmallException

Returns the variance of the (signed) differences between corresponding elements of the input arrays -- i.e., var(sample1[i] - sample2[i]).

Parameters
sample1:double[]

the first array

sample2:double[]

the second array

meanDifference:double

the mean difference between corresponding entries

Returns:double

variance of paired differences

Exceptions
DimensionMismatchException:
if the arrays do not have the same length.
NumberIsTooSmallException:
if the arrays length is less than 2.
See Also
meanDifference(double[], double[])