Skip to content

math.dist

probability distributions: how likely values are, chances of at most a value, the value for a chance, random draws and t-tests

How probable values are for the common distributions, and how to test whether two sets of measurements really differ.

Each distribution has the same set of functions, named after it: one ending in _pdf for how dense the probability is at a value (for counts like the binomial, _pmf is the chance of exactly that count), one ending in _cdf for the chance of a value at most that big, and one ending in _inv that goes the other way, from a chance to the value. Parameters come after the value, and the ones with a usual setting can be left out.

The _inv functions are quantiles, so the value below which 95% of a normal distribution lies is the inverse at 0.95. The random draws take the same parameters as the distribution, and repeat after seed.

Tags: statistics

  • normal_pdf the probability density of a normal distribution at x, how likely values near x are
  • normal_cdf the chance that a normal variable is at most x
  • normal_inv the value that a normal variable falls below with chance p, the reverse of normal_cdf
  • t_pdf the probability density of a Student’s t distribution at x, how likely values near x are
  • t_cdf the chance that a Student’s t variable is at most x
  • t_inv the value that a Student’s t variable falls below with chance p, the reverse of t_cdf
  • chi2_pdf the probability density of a chi-squared distribution at x, how likely values near x are
  • chi2_cdf the chance that a chi-squared variable is at most x
  • chi2_inv the value that a chi-squared variable falls below with chance p, the reverse of chi2_cdf
  • f_pdf the probability density of an F distribution at x, how likely values near x are
  • f_cdf the chance that an F variable is at most x
  • f_inv the value that an F variable falls below with chance p, the reverse of f_cdf
  • exp_pdf the probability density of an exponential distribution at x, how likely values near x are
  • exp_cdf the chance that an exponential variable is at most x
  • exp_inv the value that an exponential variable falls below with chance p, the reverse of exp_cdf
  • gamma_pdf the probability density of a gamma distribution at x, how likely values near x are
  • gamma_cdf the chance that a gamma variable is at most x
  • gamma_inv the value that a gamma variable falls below with chance p, the reverse of gamma_cdf
  • beta_pdf the probability density of a beta distribution at x, how likely values near x are
  • beta_cdf the chance that a beta variable is at most x
  • beta_inv the value that a beta variable falls below with chance p, the reverse of beta_cdf
  • weibull_pdf the probability density of a Weibull distribution at x, how likely values near x are
  • weibull_cdf the chance that a Weibull variable is at most x
  • weibull_inv the value that a Weibull variable falls below with chance p, the reverse of weibull_cdf
  • cauchy_pdf the probability density of a Cauchy distribution at x, how likely values near x are
  • cauchy_cdf the chance that a Cauchy variable is at most x
  • cauchy_inv the value that a Cauchy variable falls below with chance p, the reverse of cauchy_cdf
  • logistic_pdf the probability density of a logistic distribution at x, how likely values near x are
  • logistic_cdf the chance that a logistic variable is at most x
  • logistic_inv the value that a logistic variable falls below with chance p, the reverse of logistic_cdf
  • pareto_pdf the probability density of a Pareto distribution at x, how likely values near x are
  • pareto_cdf the chance that a Pareto variable is at most x
  • pareto_inv the value that a Pareto variable falls below with chance p, the reverse of pareto_cdf
  • rayleigh_pdf the probability density of a Rayleigh distribution at x, how likely values near x are
  • rayleigh_cdf the chance that a Rayleigh variable is at most x
  • rayleigh_inv the value that a Rayleigh variable falls below with chance p, the reverse of rayleigh_cdf
  • binom_pmf the chance of exactly k successes in n tries that each succeed with chance p
  • binom_cdf the chance of at most k successes in n tries that each succeed with chance p
  • binom_inv the fewest successes in n tries with chance p each that are at least as likely as q to be reached, the reverse of binom_cdf
  • poisson_pmf the chance of exactly k events when rate of them are expected on average
  • poisson_cdf the chance of at most k events when rate of them are expected on average
  • poisson_inv the fewest events that are at least as likely as q to be reached when rate are expected, the reverse of poisson_cdf
  • rand_normal a random number from a normal distribution with that mean and sd, or a list of n of them
  • rand_exp a random wait from an exponential distribution with that rate, or a list of n of them
  • rand_poisson a random event count from a Poisson distribution with that rate, or a list of n of them
  • t_test whether two groups of measurements really differ, as a map with t, df and the two-sided p
  • paired_t_test whether paired measurements, like before and after, really differ, as a map with t, df and the two-sided p
normal_pdf(x: num, mean?: num, sd?: num) -> float

the probability density of a normal distribution at x, how likely values near x are

Mean and sd default to 0 and 1, the standard bell curve

1
normal_pdf(0)0.398942
Example outputCtrl+Enter to run

See also normal_cdf, normal_inv

normal_cdf(x: num, mean?: num, sd?: num) -> float

the chance that a normal variable is at most x

1
normal_cdf(1.96)0.975002
Example outputCtrl+Enter to run

See also normal_pdf, normal_inv

normal_inv(p: num, mean?: num, sd?: num) -> float

the value that a normal variable falls below with chance p, the reverse of normal_cdf

1
normal_inv(0.975)1.95996
Example outputCtrl+Enter to run

See also normal_pdf, normal_cdf

t_pdf(x: num, df: num) -> float

the probability density of a Student’s t distribution at x, how likely values near x are

Df is the degrees of freedom

1
t_pdf(0, 5)0.379607
Example outputCtrl+Enter to run

See also t_cdf, t_inv

t_cdf(x: num, df: num) -> float

the chance that a Student’s t variable is at most x

1
t_cdf(2.0, 10)0.963306
Example outputCtrl+Enter to run

See also t_pdf, t_inv

t_inv(p: num, df: num) -> float

the value that a Student’s t variable falls below with chance p, the reverse of t_cdf

1
t_inv(0.975, 10)2.22814
Example outputCtrl+Enter to run

See also t_pdf, t_cdf

chi2_pdf(x: num, df: num) -> float

the probability density of a chi-squared distribution at x, how likely values near x are

Df is the degrees of freedom

1
chi2_pdf(2, 3)0.207554
Example outputCtrl+Enter to run

See also chi2_cdf, chi2_inv

chi2_cdf(x: num, df: num) -> float

the chance that a chi-squared variable is at most x

1
chi2_cdf(3.84, 1)0.949956
Example outputCtrl+Enter to run

See also chi2_pdf, chi2_inv

chi2_inv(p: num, df: num) -> float

the value that a chi-squared variable falls below with chance p, the reverse of chi2_cdf

1
chi2_inv(0.95, 1)3.84146
Example outputCtrl+Enter to run

See also chi2_pdf, chi2_cdf

f_pdf(x: num, d1: num, d2: num) -> float

the probability density of an F distribution at x, how likely values near x are

D1 and d2 are the two degrees of freedom

1
f_pdf(1, 5, 10)0.49548
Example outputCtrl+Enter to run

See also f_cdf, f_inv

f_cdf(x: num, d1: num, d2: num) -> float

the chance that an F variable is at most x

1
f_cdf(3, 5, 10)0.934442
Example outputCtrl+Enter to run

See also f_pdf, f_inv

f_inv(p: num, d1: num, d2: num) -> float

the value that an F variable falls below with chance p, the reverse of f_cdf

1
f_inv(0.95, 5, 10)3.32583
Example outputCtrl+Enter to run

See also f_pdf, f_cdf

exp_pdf(x: num, rate: num) -> float

the probability density of an exponential distribution at x, how likely values near x are

Rate is how many events happen per unit of time, so the mean wait is 1 / rate

1
exp_pdf(1, 2)0.270671
Example outputCtrl+Enter to run

See also exp_cdf, exp_inv

exp_cdf(x: num, rate: num) -> float

the chance that an exponential variable is at most x

1
exp_cdf(1, 2)0.864665
Example outputCtrl+Enter to run

See also exp_pdf, exp_inv

exp_inv(p: num, rate: num) -> float

the value that an exponential variable falls below with chance p, the reverse of exp_cdf

1
exp_inv(0.5, 2)0.346574
Example outputCtrl+Enter to run

See also exp_pdf, exp_cdf

gamma_pdf(x: num, shape: num, rate?: num) -> float

the probability density of a gamma distribution at x, how likely values near x are

Rate defaults to 1

1
gamma_pdf(2, 2)0.270671
Example outputCtrl+Enter to run

See also gamma_cdf, gamma_inv

gamma_cdf(x: num, shape: num, rate?: num) -> float

the chance that a gamma variable is at most x

1
gamma_cdf(2, 3, 2)0.761897
Example outputCtrl+Enter to run

See also gamma_pdf, gamma_inv

gamma_inv(p: num, shape: num, rate?: num) -> float

the value that a gamma variable falls below with chance p, the reverse of gamma_cdf

1
gamma_inv(0.5, 3)2.67406
Example outputCtrl+Enter to run

See also gamma_pdf, gamma_cdf

beta_pdf(x: num, a: num, b: num) -> float

the probability density of a beta distribution at x, how likely values near x are

A and b are the two shape numbers, and x runs from 0 to 1

1
beta_pdf(0.5, 2, 2)1.5
Example outputCtrl+Enter to run

See also beta_cdf, beta_inv

beta_cdf(x: num, a: num, b: num) -> float

the chance that a beta variable is at most x

1
beta_cdf(0.25, 2, 5)0.466064
Example outputCtrl+Enter to run

See also beta_pdf, beta_inv

beta_inv(p: num, a: num, b: num) -> float

the value that a beta variable falls below with chance p, the reverse of beta_cdf

1
beta_inv(0.5, 2, 5)0.26445
Example outputCtrl+Enter to run

See also beta_pdf, beta_cdf

weibull_pdf(x: num, shape: num, scale?: num) -> float

the probability density of a Weibull distribution at x, how likely values near x are

Scale defaults to 1

1
weibull_pdf(1, 1.5)0.551819
Example outputCtrl+Enter to run

See also weibull_cdf, weibull_inv

weibull_cdf(x: num, shape: num, scale?: num) -> float

the chance that a Weibull variable is at most x

1
weibull_cdf(1, 1.5, 2)0.297811
Example outputCtrl+Enter to run

See also weibull_pdf, weibull_inv

weibull_inv(p: num, shape: num, scale?: num) -> float

the value that a Weibull variable falls below with chance p, the reverse of weibull_cdf

1
weibull_inv(0.5, 1.5, 2)1.56644
Example outputCtrl+Enter to run

See also weibull_pdf, weibull_cdf

cauchy_pdf(x: num, loc?: num, scale?: num) -> float

the probability density of a Cauchy distribution at x, how likely values near x are

Loc and scale default to 0 and 1

1
cauchy_pdf(0)0.31831
Example outputCtrl+Enter to run

See also cauchy_cdf, cauchy_inv

cauchy_cdf(x: num, loc?: num, scale?: num) -> float

the chance that a Cauchy variable is at most x

1
cauchy_cdf(1)0.75
Example outputCtrl+Enter to run

See also cauchy_pdf, cauchy_inv

cauchy_inv(p: num, loc?: num, scale?: num) -> float

the value that a Cauchy variable falls below with chance p, the reverse of cauchy_cdf

1
cauchy_inv(0.75)1
Example outputCtrl+Enter to run

See also cauchy_pdf, cauchy_cdf

logistic_pdf(x: num, loc?: num, scale?: num) -> float

the probability density of a logistic distribution at x, how likely values near x are

Loc and scale default to 0 and 1

1
logistic_pdf(0)0.25
Example outputCtrl+Enter to run

See also logistic_cdf, logistic_inv

logistic_cdf(x: num, loc?: num, scale?: num) -> float

the chance that a logistic variable is at most x

1
logistic_cdf(2)0.880797
Example outputCtrl+Enter to run

See also logistic_pdf, logistic_inv

logistic_inv(p: num, loc?: num, scale?: num) -> float

the value that a logistic variable falls below with chance p, the reverse of logistic_cdf

1
logistic_inv(0.9)2.19722
Example outputCtrl+Enter to run

See also logistic_pdf, logistic_cdf

pareto_pdf(x: num, shape: num, scale?: num) -> float

the probability density of a Pareto distribution at x, how likely values near x are

Scale is the smallest possible value and defaults to 1

1
pareto_pdf(2, 3)0.1875
Example outputCtrl+Enter to run

See also pareto_cdf, pareto_inv

pareto_cdf(x: num, shape: num, scale?: num) -> float

the chance that a Pareto variable is at most x

1
pareto_cdf(2, 3)0.875
Example outputCtrl+Enter to run

See also pareto_pdf, pareto_inv

pareto_inv(p: num, shape: num, scale?: num) -> float

the value that a Pareto variable falls below with chance p, the reverse of pareto_cdf

1
pareto_inv(0.5, 3)1.25992
Example outputCtrl+Enter to run

See also pareto_pdf, pareto_cdf

rayleigh_pdf(x: num, scale?: num) -> float

the probability density of a Rayleigh distribution at x, how likely values near x are

Scale defaults to 1

1
rayleigh_pdf(1)0.606531
Example outputCtrl+Enter to run

See also rayleigh_cdf, rayleigh_inv

rayleigh_cdf(x: num, scale?: num) -> float

the chance that a Rayleigh variable is at most x

1
rayleigh_cdf(1, 2)0.117503
Example outputCtrl+Enter to run

See also rayleigh_pdf, rayleigh_inv

rayleigh_inv(p: num, scale?: num) -> float

the value that a Rayleigh variable falls below with chance p, the reverse of rayleigh_cdf

1
rayleigh_inv(0.5, 2)2.35482
Example outputCtrl+Enter to run

See also rayleigh_pdf, rayleigh_cdf

binom_pmf(k: int, n: int, p: num) -> float

the chance of exactly k successes in n tries that each succeed with chance p

1
binom_pmf(5, 10, 0.5)0.246094
Example outputCtrl+Enter to run

See also binom_cdf, binom_inv

binom_cdf(k: int, n: int, p: num) -> float

the chance of at most k successes in n tries that each succeed with chance p

1
binom_cdf(3, 10, 0.5)0.171875
Example outputCtrl+Enter to run

See also binom_pmf, binom_inv

binom_inv(q: num, n: int, p: num) -> int

the fewest successes in n tries with chance p each that are at least as likely as q to be reached, the reverse of binom_cdf

1
binom_inv(0.5, 10, 0.5)5
Example outputCtrl+Enter to run

See also binom_pmf, binom_cdf

poisson_pmf(k: int, rate: num) -> float

the chance of exactly k events when rate of them are expected on average

1
poisson_pmf(2, 3)0.224042
Example outputCtrl+Enter to run

See also poisson_cdf, poisson_inv

poisson_cdf(k: int, rate: num) -> float

the chance of at most k events when rate of them are expected on average

1
poisson_cdf(2, 3)0.42319
Example outputCtrl+Enter to run

See also poisson_pmf, poisson_inv

poisson_inv(q: num, rate: num) -> int

the fewest events that are at least as likely as q to be reached when rate are expected, the reverse of poisson_cdf

1
poisson_inv(0.5, 3)3
Example outputCtrl+Enter to run

See also poisson_pmf, poisson_cdf

rand_normal(mean: num, sd: num, n?: int) -> float|list

a random number from a normal distribution with that mean and sd, or a list of n of them

1
rand_normal(100, 15)74.4071
2
rand_normal(0, 1, 3)[1.52739, -0.644269, -1.03496]
Example outputCtrl+Enter to run

Tags: random

See also normal_pdf, normal_cdf, normal_inv

rand_exp(rate: num, n?: int) -> float|list

a random wait from an exponential distribution with that rate, or a list of n of them

1
rand_exp(2)1.73979
2
rand_exp(0.5, 3)[3.98627, 5.12684, 0.638952]
Example outputCtrl+Enter to run

Tags: random

See also exp_pdf, exp_cdf, exp_inv

rand_poisson(rate: num, n?: int) -> float|list

a random event count from a Poisson distribution with that rate, or a list of n of them

1
rand_poisson(4)3
2
rand_poisson(2.5, 3)[3, 6, 3]
Example outputCtrl+Enter to run

Tags: random

See also poisson_pmf, poisson_cdf, poisson_inv

t_test(xs: list, ys: list) -> map

whether two groups of measurements really differ, as a map with t, df and the two-sided p

Welch’s test, which doesn’t assume the groups spread equally. A small p, like under 0.05, means a difference this big would be rare by chance alone

1
t_test([5.1, 4.9, 5.6, 5.8, 5.0], [6.1, 6.4, 5.9, 6.8, 6.2]){t: -4.27179, df: 7.83306, p: 0.00285238}
Example outputCtrl+Enter to run

See also paired_t_test, t_cdf

paired_t_test(xs: list, ys: list) -> map

whether paired measurements, like before and after, really differ, as a map with t, df and the two-sided p

The lists must be the same length, with item i of each from the same subject

1
paired_t_test([200, 190, 210, 205], [195, 185, 207, 198]){t: 6.12372, df: 3, p: 0.00875441}
Example outputCtrl+Enter to run

See also t_test, t_cdf

1
# the share of a bell curve within 1.96 deviations
2
normal_cdf(1.96) - normal_cdf(-1.96)0.950004
3
# the 95% cutoff for a t distribution with 10 degrees of freedom
4
t_inv(0.975, 10)2.22814
5
# heads in 10 fair coin tosses, at most 3
6
binom_cdf(3, 10, 0.5)0.171875
7
# do these two groups differ?
8
t_test([5.1, 4.9, 5.6, 5.8, 5.0], [6.1, 6.4, 5.9, 6.8, 6.2]).p0.00285238
Example outputCtrl+Enter to run

Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.