function norminv
norminv(
p: number,
mu?: number,
sigma?: number,
): number

Computes the inverse of the normal cumulative distribution function (CDF).

Returns the inverse CDF (quantile function) for a normal distribution with mean mu and standard deviation sigma at probability p. If mu and sigma are not provided, it defaults to the standard normal distribution (mu = 0, sigma = 1).

Examples

Compute the inverse CDF for standard normal distribution

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

assertEquals(norminv(0.05), -1.6448536127562647);

Compute inverse CDF with custom mean and standard deviation

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

assertEquals(norminv(0.01, 10, 2),  5.347304312449656);

Compute inverse CDF at median (should return mean)

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

assertEquals(norminv(0.5, 5, 1), 5);

Compute inverse CDF for a high probability (should be positive)

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

assertEquals(norminv(0.975, 0, 1), 1.9599639471668915);

Compute inverse CDF for a low probability (should be negative)

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

assertEquals(norminv(0.025, 0, 1), -1.9599639471668922);

Parameters

p: number

The probability value in the range (0,1).

optional
mu: number = 0

The mean of the normal distribution. Defaults to 0.

optional
sigma: number = 1

The standard deviation of the normal distribution. Defaults to 1.

Return Type

number

The inverse CDF (quantile).

Throws

If p is not in the range (0,1) or sigma is not positive.