function normcdf
normcdf(
x: number,
mu?: number,
sigma?: number,
): number

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

Calculates the probability that a normally distributed random variable with mean mu and standard deviation sigma is less than or equal to x. If mu and sigma are not provided, it defaults to the standard normal distribution (mu = 0, sigma = 1).

Examples

Compute standard normal CDF at x = 2

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

assertEquals(normcdf(2), 0.9772498701098755);

Compute normal CDF with custom mean and standard deviation

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

assertEquals(normcdf(0, 1, 2), 0.30853751691860176);

Compute normal CDF at the mean (should be close to 0.5)

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

assertEquals(normcdf(10, 10, 3), 0.5);

Compute normal CDF for negative values

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

assertEquals(normcdf(-1.5, 0, 1), 0.06680720195906442);

Compute normal CDF for a very large value (should be close to 1)

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

assertEquals(normcdf(100, 50, 10), 0.9999997133484314);

Parameters

x: number

The value at which to evaluate the CDF

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 cumulative probability for x

Throws

If sigma is not a positive number