pub fn variance<I, T: Numeric>(data: I) -> T where
    I: Iterator<Item = T>, 
Expand description

Computes the variance of the values in an iterator, consuming the iterator.

Variance is defined as expected value of of the squares of the zero mean data. It captures how much data varies from its mean, ie the spread of the data.

This function does not perform Bessel’s correction

Variance may also be computed as the mean of each squared datapoint minus the square of the mean of the data. Although this method would allow for a streaming implementation the wikipedia page cautions: “This equation should not be used for computations using floating point arithmetic because it suffers from catastrophic cancellation if the two components of the equation are similar in magnitude”.

Panics

If the iterator is empty. This function will also fail if the length of the iterator or sum of all the values in the iterator exceeds the maximum number the type can represent.