Distributions
The CSharpNumerics.Statistics.Distributions namespace provides probability distributions with a common IDistribution interface.
using CSharpNumerics.Statistics.Distributions;
using CSharpNumerics.Statistics.Random;
π Available Distributionsβ
| Distribution | Class | Parameters |
|---|---|---|
| Uniform | UniformDistribution | |
| Normal | NormalDistribution | |
| Exponential | ExponentialDistribution | |
| Poisson | PoissonDistribution | |
| Bernoulli | BernoulliDistribution | |
| Binomial | BinomialDistribution | |
| Student's t | StudentTDistribution | (degrees of freedom) |
| Chi-squared | ChiSquaredDistribution | (degrees of freedom) |
| F | FDistribution | (degrees of freedom) |
Every distribution exposes Mean, Variance, StandardDeviation, Pdf(x), Cdf(x), Sample(rng) and Samples(rng, count).
π Normal Distributionβ
var normal = new NormalDistribution(mu: 100, sigma: 15);
double pdf = normal.Pdf(100); // peak value
double cdf = normal.Cdf(115); // P(X β€ 115) β 0.8413
double q = normal.InverseCdf(0.95); // z such that P(X β€ z) = 0.95
var rng = new RandomGenerator(42);
double[] samples = normal.Samples(rng, 10_000);
π― Poisson Distributionβ
var poisson = new PoissonDistribution(lambda: 3.0);
double pmf = poisson.Pdf(2); // P(X = 2)
double cumul = poisson.Cdf(4); // P(X β€ 4)
πͺ Binomial Distributionβ
var binomial = new BinomialDistribution(n: 10, p: 0.3);
// PMF sums to 1
double total = Enumerable.Range(0, 11).Sum(k => binomial.Pdf(k));
π Student's t, Chi-squared & F Distributionsβ
Used by the hypothesis testing methods, but can also be used directly:
var t = new StudentTDistribution(degreesOfFreedom: 29);
double pTwoTail = t.TwoTailedPValue(2.045); // two-tailed p-value
double quantile = t.InverseCdf(0.975); // critical value
var chi2 = new ChiSquaredDistribution(degreesOfFreedom: 5);
double pUpper = chi2.UpperTailPValue(11.07); // P(X β₯ 11.07)
var f = new FDistribution(d1: 3, d2: 20);
double pF = f.UpperTailPValue(3.10); // P(F β₯ 3.10)