function prctile
prctile(
x: array,
p: number,
dim?: 0 | 1,
): number

Percentiles of a sample.

Calculates the p-th percentile of values in an array or matrix. Uses linear interpolation between data points for accurate percentile calculation.

Examples

50th percentile (median)

import { assertEquals } from "jsr:@std/assert";

assertEquals(prctile([1, 2, 3, 4, 5], 50), 3);

25th percentile

import { assertEquals } from "jsr:@std/assert";

assertEquals(prctile([1, 2, 3, 4], 25), 1.5);

75th percentile

import { assertEquals } from "jsr:@std/assert";

assertEquals(prctile([1, 2, 3, 4, 5], 75), 4.25);

Parameters

Input array or matrix

p: number

Percentile value in range [0,100]

optional
dim: 0 | 1

Dimension along which to compute percentiles. Default is 0

Return Type

number

Percentile values

Throws

When percentile is outside valid range [0,100]

prctile(
x: matrix,
p: number,
dim?: 0 | 1,
): array

Percentiles of a sample.

Calculates the p-th percentile of values in an array or matrix. Uses linear interpolation between data points for accurate percentile calculation.

Examples

50th percentile (median)

import { assertEquals } from "jsr:@std/assert";

assertEquals(prctile([1, 2, 3, 4, 5], 50), 3);

25th percentile

import { assertEquals } from "jsr:@std/assert";

assertEquals(prctile([1, 2, 3, 4], 25), 1.5);

75th percentile

import { assertEquals } from "jsr:@std/assert";

assertEquals(prctile([1, 2, 3, 4, 5], 75), 4.25);

Parameters

Input array or matrix

p: number

Percentile value in range [0,100]

optional
dim: 0 | 1

Dimension along which to compute percentiles. Default is 0

Return Type

Percentile values

Throws

When percentile is outside valid range [0,100]

prctile(
x: array,
p: number,
dim: 0 | 1,
): number

Percentiles of a sample.

Calculates the p-th percentile of values in an array or matrix. Uses linear interpolation between data points for accurate percentile calculation.

Examples

50th percentile (median)

import { assertEquals } from "jsr:@std/assert";

assertEquals(prctile([1, 2, 3, 4, 5], 50), 3);

25th percentile

import { assertEquals } from "jsr:@std/assert";

assertEquals(prctile([1, 2, 3, 4], 25), 1.5);

75th percentile

import { assertEquals } from "jsr:@std/assert";

assertEquals(prctile([1, 2, 3, 4, 5], 75), 4.25);

Parameters

Input array or matrix

p: number

Percentile value in range [0,100]

dim: 0 | 1

Dimension along which to compute percentiles. Default is 0

Return Type

number

Percentile values

Throws

When percentile is outside valid range [0,100]

prctile(
x: matrix,
p: number,
dim: 0 | 1,
): array

Percentiles of a sample.

Calculates the p-th percentile of values in an array or matrix. Uses linear interpolation between data points for accurate percentile calculation.

Examples

50th percentile (median)

import { assertEquals } from "jsr:@std/assert";

assertEquals(prctile([1, 2, 3, 4, 5], 50), 3);

25th percentile

import { assertEquals } from "jsr:@std/assert";

assertEquals(prctile([1, 2, 3, 4], 25), 1.5);

75th percentile

import { assertEquals } from "jsr:@std/assert";

assertEquals(prctile([1, 2, 3, 4, 5], 75), 4.25);

Parameters

Input array or matrix

p: number

Percentile value in range [0,100]

dim: 0 | 1

Dimension along which to compute percentiles. Default is 0

Return Type

Percentile values

Throws

When percentile is outside valid range [0,100]

prctile(
p: number,
dim?: 0 | 1,
): number | array

Percentiles of a sample.

Calculates the p-th percentile of values in an array or matrix. Uses linear interpolation between data points for accurate percentile calculation.

Examples

50th percentile (median)

import { assertEquals } from "jsr:@std/assert";

assertEquals(prctile([1, 2, 3, 4, 5], 50), 3);

25th percentile

import { assertEquals } from "jsr:@std/assert";

assertEquals(prctile([1, 2, 3, 4], 25), 1.5);

75th percentile

import { assertEquals } from "jsr:@std/assert";

assertEquals(prctile([1, 2, 3, 4, 5], 75), 4.25);

Parameters

Input array or matrix

p: number

Percentile value in range [0,100]

optional
dim: 0 | 1

Dimension along which to compute percentiles. Default is 0

Return Type

number | array

Percentile values

Throws

When percentile is outside valid range [0,100]

prctile(
p: number,
dim: 0 | 1,
): number | array

Percentiles of a sample.

Calculates the p-th percentile of values in an array or matrix. Uses linear interpolation between data points for accurate percentile calculation.

Examples

50th percentile (median)

import { assertEquals } from "jsr:@std/assert";

assertEquals(prctile([1, 2, 3, 4, 5], 50), 3);

25th percentile

import { assertEquals } from "jsr:@std/assert";

assertEquals(prctile([1, 2, 3, 4], 25), 1.5);

75th percentile

import { assertEquals } from "jsr:@std/assert";

assertEquals(prctile([1, 2, 3, 4, 5], 75), 4.25);

Parameters

Input array or matrix

p: number

Percentile value in range [0,100]

dim: 0 | 1

Dimension along which to compute percentiles. Default is 0

Return Type

number | array

Percentile values

Throws

When percentile is outside valid range [0,100]