variance

Computes the variance of the values in this iterable.

Variance measures how far values spread from their mean. Uses Welford's numerically stable single-pass algorithm. Sample variance (default) divides by n-1 (Bessel's correction) for an unbiased estimate; population variance divides by n.

NaN values propagate through the computation (IEEE 754 semantics): if any element is NaN, the result is NaN. Filter NaN values before calling this function if that is not desired.

Example:

listOf(2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0).variance()                         // 4.5714...
listOf(2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0).variance(PopulationKind.POPULATION) // 4.0

Return

the variance of the elements.

Parameters

kind

whether to compute sample or population variance. Defaults to PopulationKind.SAMPLE.


Computes the variance of the values in this array.

Variance measures how far values spread from their mean. Uses Welford's numerically stable single-pass algorithm.

NaN values propagate through the computation (IEEE 754 semantics): if any element is NaN, the result is NaN. Filter NaN values before calling this function if that is not desired.

Example:

doubleArrayOf(2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0).variance() // 4.5714...

Return

the variance of the array elements.

Parameters

kind

whether to compute sample or population variance. Defaults to PopulationKind.SAMPLE.


Computes the variance of the values in this sequence.

The sequence is materialized internally. See DoubleArray.variance for details.

Return

the variance of the elements.

Parameters

kind

whether to compute sample or population variance. Defaults to PopulationKind.SAMPLE.


@JvmName(name = "varianceOfLong")
fun Iterable<Long>.variance(kind: PopulationKind = PopulationKind.SAMPLE): Double(source)

Computes the variance of the Long values.

Values are converted to Double internally. Long values whose absolute value exceeds 2^53 (9,007,199,254,740,992) may lose precision in the least-significant digits.

Example:

listOf(2L, 4L, 4L, 4L, 5L, 5L, 7L, 9L).variance() // 4.5714...

Return

the variance of the Long values as a Double.

Parameters

kind

whether to compute sample or population variance. Defaults to PopulationKind.SAMPLE.


@JvmName(name = "varianceOfInt")
fun Iterable<Int>.variance(kind: PopulationKind = PopulationKind.SAMPLE): Double(source)

Computes the variance of the Int values.

Values are converted to Double internally. The conversion is exact for all Int values.

Example:

listOf(2, 4, 4, 4, 5, 5, 7, 9).variance() // 4.5714...

Return

the variance of the Int values as a Double.

Parameters

kind

whether to compute sample or population variance. Defaults to PopulationKind.SAMPLE.