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

Quartiles of a sample.

Calculates the three quartiles (Q1, Q2, Q3) which divide the data into four equal parts. Q1 is the 25th percentile, Q2 is the median (50th percentile), and Q3 is the 75th percentile.

Examples

Simple quartiles

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

assertEquals(quartile([1, 2, 3, 4, 5]), [1.75, 3, 4.25]);

Even number of elements

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

assertEquals(quartile([1, 2, 3, 4]), [1.5, 2.5, 3.5]);

Quartiles provide Q1, Q2 (median), Q3

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

assertEquals(quartile([10, 20, 30, 40]), [15, 25, 35]);

Parameters

Input array or matrix

optional
dim: 0 | 1

Dimension along which to compute quartiles. Default is 0

Return Type

Array containing [Q1, Q2, Q3] values

Throws

When input is invalid

quartile(
x: matrix,
dim?: 0 | 1,
): matrix

Quartiles of a sample.

Calculates the three quartiles (Q1, Q2, Q3) which divide the data into four equal parts. Q1 is the 25th percentile, Q2 is the median (50th percentile), and Q3 is the 75th percentile.

Examples

Simple quartiles

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

assertEquals(quartile([1, 2, 3, 4, 5]), [1.75, 3, 4.25]);

Even number of elements

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

assertEquals(quartile([1, 2, 3, 4]), [1.5, 2.5, 3.5]);

Quartiles provide Q1, Q2 (median), Q3

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

assertEquals(quartile([10, 20, 30, 40]), [15, 25, 35]);

Parameters

Input array or matrix

optional
dim: 0 | 1

Dimension along which to compute quartiles. Default is 0

Return Type

Array containing [Q1, Q2, Q3] values

Throws

When input is invalid