NormalDistribution
Represents the normal (Gaussian) distribution, the most widely used continuous probability distribution in statistics.
The normal distribution is symmetric and bell-shaped, centered at the mean mu with spread controlled by the standard deviation sigma. It arises naturally as the limiting distribution of sums of independent random variables (central limit theorem) and is the foundation for many statistical methods including confidence intervals, hypothesis tests, and regression.
About 68% of values fall within one standard deviation of the mean, about 95% within two, and about 99.7% within three. The distribution is fully supported on the entire real line, meaning any real number is a possible outcome, though values far from the mean are exceedingly rare.
The CDF and survival function use the error function for numerical accuracy, and the quantile function uses the inverse error function. Random sampling uses the Box-Muller transform, which converts two uniform random draws into a normally distributed value.
Example:
val dist = NormalDistribution(mu = 100.0, sigma = 15.0)
dist.mean // 100.0
dist.variance // 225.0
dist.pdf(100.0) // 0.0266 (peak density at the mean)
dist.cdf(115.0) // 0.8413 (about 84% of values are below one SD above the mean)
dist.quantile(0.975) // 129.39 (the 97.5th percentile)
dist.sample(Random(42)) // a single random draw from N(100, 15)
// Standard normal (mu=0, sigma=1)
val z = NormalDistribution.STANDARD
z.cdf(1.96) // 0.975