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

Interquartile range.

Calculates the interquartile range (difference between 75th and 25th percentiles) of arrays or matrices. For matrices, operates along specified dimension.

Examples

IQR of simple array

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

assertEquals(iqr([1, 2, 3, 4, 5]), 2.5);

IQR with larger range

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

assertEquals(iqr([1, 2, 3, 4, 5, 6, 7, 8, 9]), 4.5);

IQR of matrix

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

assertEquals(iqr([[1, 2, 3], [4, 5, 6]]), [1.5, 1.5]);

Parameters

Input array or matrix

optional
dim: 0 | 1

Dimension along which to compute IQR. Default is 0

Return Type

number

Interquartile range values

Throws

When input is invalid

iqr(
x: matrix,
dim?: 0 | 1,
): array

Interquartile range.

Calculates the interquartile range (difference between 75th and 25th percentiles) of arrays or matrices. For matrices, operates along specified dimension.

Examples

IQR of simple array

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

assertEquals(iqr([1, 2, 3, 4, 5]), 2.5);

IQR with larger range

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

assertEquals(iqr([1, 2, 3, 4, 5, 6, 7, 8, 9]), 4.5);

IQR of matrix

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

assertEquals(iqr([[1, 2, 3], [4, 5, 6]]), [1.5, 1.5]);

Parameters

Input array or matrix

optional
dim: 0 | 1

Dimension along which to compute IQR. Default is 0

Return Type

Interquartile range values

Throws

When input is invalid