The VARIANCE function uses IDL's MOMENT function to compute the unbiased sample variance of an n-element vector.

Tip: You may want to use the RUNNING_STATS function instead, which avoids overflow for large values, is significantly faster, uses less memory, and also allows you to combine calculations for data sets that do not fit into memory.

Examples


; Define the n-element vector of sample data:
x = [1, 1, 1, 2, 5]
                
; Compute the variance:
result = VARIANCE(x)
PRINT, result

IDL prints:

3.00000

Syntax


Result = VARIANCE( X  [, DIMENSION=value] [, /DOUBLE] [, /NAN] )

Return Value


Returns the floating-point or double-precision statistical variance of the input vector.

Arguments


X

An n-element, floating-point or double-precision vector.

Keywords


DIMENSION

Set this keyword to a scalar indicating the dimension across which to calculate the variance. If this keyword is not present or is zero, then the variance is computed across all dimensions of the input array. If this keyword is present, then the variance is only calculated only across a single dimension. In this case the result is an array with one less dimension than the input.

DOUBLE

If this keyword is set, VARIANCE performs its computations in double precision arithmetic and returns a double precision result. If this keyword is not set, the computations and result depend upon the type of the input data (integer and float data return float results, while double data returns double results).

NAN

Set this keyword to cause the routine to check for occurrences of the IEEE floating-point values NaN or Infinity in the input data. Elements with the value NaN or Infinity are treated as missing data.

Version History


5.1

Introduced

8.0

Added DIMENSION keyword

See Also


KURTOSIS, MEAN, MEANABSDEV, MOMENT, RUNNING_STATS, STDDEV, SKEWNESS