Defines common probability distributions and their associated functions (pdf, cdf, mean, variance, etc.) in pure Typst.
Warning
This library is still in early development, please use with caution. Typst is not designed for robust statistical use, and built-in functions like calc.binom overflow quickly.
Some of the numerical computations are derived from the Rust statrs crate.
This package is currently not packaged for Typst Universe, but will be once it stabilises a bit more. In the meantime, you can just grab the code directly from here.
#import calc: sqrt, pi
#import "@preview:distro": normal
#{
let Z = normal.new(mean: 0, std: 1)
assert((Z.mean, Z.variance) == (0, 1))
assert(normal.pdf(Z)(0) == 1 / sqrt(2 * pi))
}Please also see the examples folder for more applications.
Since Typst doesn't (currently) support custom objects and methods, you must pass the instance of the distribution variable into the associated pdf or cdf function.
The new function acts as a constructor, validating the paramaters, and returning a dictionary that stores the mean and variance.