Routines (alphabetical) > Routines: V > VARIANCE

# VARIANCE

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

## 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, STDDEV, SKEWNESS