quantile

Calculates the value at a q quantile using sorted values and linear interpolation.

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

const values = ["10", "20", "30", "40"];

Arith.quantile(values, "0").toString(); // "10"
Arith.quantile(values, "0.5").toString(); // "25"
Arith.quantile(values, "0.75").toString(); // "32.5"
Arith.quantile(values, "1").toString(); // "40"

API Reference

Signature

Arith.quantile(values: readonly ArithValue[], q: ArithValue): ArithInstance;

Parameters

ParameterTypeRequiredNotes
valuesreadonly ArithValue[]YesNon-empty array of finite values.
qArithValueYesQuantile point in [0, 1].

Returns

Returns sorted[lower] + (sorted[upper] - sorted[lower]) * fraction, where position = (n - 1) * q.

Throws

  • Throws if values is not a non-empty array.
  • Throws if any value is non-finite.
  • Throws if q is non-finite or outside [0, 1].

Agent Contract

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

Agent Notes

  • Use quantile(values, q) rather than percentile; percentile is not a public API.
  • Pass q as a value from 0 through 1, not as 0 through 100.
  • The input array is sorted on a copy.