variance

Calculates variance for a non-empty array using the current Arith precision model.

import { Arith } from "@teakit/arith";

Arith.variance(["1", "2", "3"]).toString(); // "0.66666666666666666667"
Arith.variance(["1", "2", "3"], { sample: true }).toString(); // "1"

const Short = Arith.clone({ DECIMAL_PLACES: 4 });
Short.variance(["1", "2", "3"]).toString(); // "0.6667"

API Reference

Signature

interface ArithSampleOptions {
  sample?: boolean;
}

Arith.variance(values: readonly ArithValue[], options?: ArithSampleOptions): ArithInstance;

Parameters

ParameterTypeRequiredNotes
valuesreadonly ArithValue[]YesNon-empty array of finite values.
options.samplebooleanNofalse or omitted uses population variance. true uses sample variance.

Returns

Returns sum((x - mean)^2) / denominator, where denominator is n for population variance or n - 1 for sample variance.

Throws

  • Throws if values is not a non-empty array.
  • Throws if any value is non-finite.
  • Throws if sample: true is used with fewer than two values.
  • Throws if options.sample is not boolean when provided.

Agent Contract

FieldValue
Kindstatic method
Canonical namevariance
AliasesNone
Mutates receiverNo
ReturnsArithInstance
Accepts (string, base) overloadNo
Configuration dependenciesDECIMAL_PLACES, ROUNDING_MODE, STRICT
Related methodsstd, mean

Agent Notes

  • Population variance is the default.
  • Pass { sample: true } only for sample variance.