Notebooks · lib/stats/dist
Probability distributions in standard form
Fourteen continuous and five discrete families, each in SciPy's standard
form (loc 0, scale 1; vp.stats applies loc and scale in Python) with SciPy's
shape parameters. dist_value(fam, what, x, s1, s2, s3) evaluates one of
PDF LOGPDF CDF SF PPF ISF
of family fam at one point; the family and the function are the named
codes below. Each tail is computed directly (SF is never 1 - CDF where the
CDF is near 1), through the functions of lib/stats/special.viv:
- normal and lognormal:
ndtr,ndtri; - Student t, F, beta:
betainc,betainccand their inverses, with the argument (x^2 / (df + x^2) or df / (df + x^2) for t) chosen so that the smaller one is passed; - chi-squared and gamma:
gammainc,gammainccand their inverses; the gamma density is Loader'sdpois_raw(as R's dgamma); - exponential, Weibull, Cauchy, logistic, uniform, Laplace, Pareto: closed forms with
log1pandexpm1where they lose digits otherwise; - binomial, Poisson, negative binomial: Loader's saddle-point terms for the mass (R's dbinom, dpois, dnbinom) and the incomplete beta or gamma function for the tails; geometric in closed form; hypergeometric as R's dhyper (three binomial terms) with the tails summed from the far end. Discrete quantiles are the smallest k with CDF(k) >= p, searched from the normal approximation.
dist_sample(fam, s1, s2, s3, n, seed): n draws by inversion, PPF of the
uniforms np.random.default_rng(seed).random(n) gives (lib/nprandom's PCG64,
bit for bit), so a seed gives the same draws in every engine and in Python.
Used with from stats.dist import ....
Look inside this program
- Atlas
The program’s map: every function and which calls which.
There’s no recorded run of this program yet.
Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.