trimmedVariance

fun DoubleArray.trimmedVariance(proportion: Double, kind: PopulationKind = SAMPLE): Double(source)

Computes the variance of the values after removing a fraction from each tail.

The trimmed variance sorts the data, discards the lowest and highest proportion of values, and computes the variance of the remaining middle portion using Welford's numerically stable algorithm. This makes it more robust to outliers than the regular variance. A proportion of 0.0 gives the ordinary variance.

Example:

doubleArrayOf(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0).trimmedVariance(0.1) // 6.0

Return

the variance of the remaining values after trimming.

Parameters

proportion

the fraction of values to remove from each tail, in [0.0, 0.5). For example, 0.1 removes the lowest 10% and highest 10%.

kind

whether to compute sample or population variance. Defaults to PopulationKind.SAMPLE, which divides by n-1 (Bessel's correction) where n is the count after trimming.

See also


fun Iterable<Double>.trimmedVariance(proportion: Double, kind: PopulationKind = SAMPLE): Double(source)

Computes the variance of the values after removing a fraction from each tail.

The trimmed variance sorts the data, discards the lowest and highest proportion of values, and computes the variance of the remaining middle portion. This makes it more robust to outliers than the regular variance. A proportion of 0.0 gives the ordinary variance.

Example:

listOf(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0).trimmedVariance(0.1) // 6.0

Return

the variance of the remaining values after trimming.

Parameters

proportion

the fraction of values to remove from each tail, in [0.0, 0.5). For example, 0.1 removes the lowest 10% and highest 10%.

kind

whether to compute sample or population variance. Defaults to PopulationKind.SAMPLE, which divides by n-1 (Bessel's correction) where n is the count after trimming.

See also


fun Sequence<Double>.trimmedVariance(proportion: Double, kind: PopulationKind = SAMPLE): Double(source)

Computes the variance of the values after removing a fraction from each tail.

The trimmed variance sorts the data, discards the lowest and highest proportion of values, and computes the variance of the remaining middle portion. This makes it more robust to outliers than the regular variance. A proportion of 0.0 gives the ordinary variance.

Example:

sequenceOf(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0).trimmedVariance(0.1) // 6.0

Return

the variance of the remaining values after trimming.

Parameters

proportion

the fraction of values to remove from each tail, in [0.0, 0.5). For example, 0.1 removes the lowest 10% and highest 10%.

kind

whether to compute sample or population variance. Defaults to PopulationKind.SAMPLE, which divides by n-1 (Bessel's correction) where n is the count after trimming.

See also