UNPKG

distriprob

Version:

A library for calculating the PDF, CDFs, and quantile function values of common probability distributions

299 lines (298 loc) 11.6 kB
"use strict"; const _normal = require("./impls/normal"); const studentsT = require("./impls/studentsT"); const chiSquared = require("./impls/chiSquared"); const fDist = require("./impls/fDist"); const binom = require("./impls/binomial"); const _poisson = require("./impls/poisson"); const hypergeo = require("./impls/hypergeometric"); const _gamma = require("./impls/gamma"); const exp = require("./impls/exponential"); const _uniform = require("./impls/uniform"); const _beta = require("./impls/beta"); exports.uniform = { pdf: function (x, lowerSupportBound, upperSupportBound) { return _uniform.pdf(x, lowerSupportBound, upperSupportBound); }, cdf: function (x, lowerSupportBound, upperSupportBound, lowerTail = true) { return _uniform.cdf(x, lowerSupportBound, upperSupportBound, lowerTail); }, quantile: function (x, lowerSupportBound, upperSupportBound, lowerTail = true) { return _uniform.quantile(x, lowerSupportBound, upperSupportBound, lowerTail); }, random: function (n, lowerSupportBound, upperSupportBound, seed) { return _uniform.random(n, lowerSupportBound, upperSupportBound, seed); }, pdfSync: function (x, lowerSupportBound, upperSupportBound) { return _uniform.pdfSync(x, lowerSupportBound, upperSupportBound); }, cdfSync: function (x, lowerSupportBound, upperSupportBound, lowerTail = true) { return _uniform.cdfSync(x, lowerSupportBound, upperSupportBound, lowerTail); }, quantileSync: function (x, lowerSupportBound, upperSupportBound, lowerTail = true) { return _uniform.quantileSync(x, lowerSupportBound, upperSupportBound, lowerTail); }, randomSync: function (n, lowerSupportBound, upperSupportBound, seed) { return _uniform.randomSync(n, lowerSupportBound, upperSupportBound, seed); } }; exports.normal = { pdf: function (x, mu, sigma) { return _normal.pdf(x, mu, sigma); }, cdf: function (x, mu, sigma, lowerTail = true) { return _normal.cdf(x, mu, sigma, lowerTail); }, quantile: function (p, mu, sigma, lowerTail = true) { return _normal.quantile(p, mu, sigma, lowerTail); }, random: function (n, mu, sigma, seed) { return _normal.random(n, mu, sigma, seed); }, pdfSync: function (x, mu, sigma) { return _normal.pdfSync(x, mu, sigma); }, cdfSync: function (x, mu, sigma, lowerTail = true) { return _normal.cdfSync(x, mu, sigma, lowerTail); }, quantileSync: function (p, mu, sigma, lowerTail = true) { return _normal.quantileSync(p, mu, sigma, lowerTail); }, randomSync: function (n, mu, sigma, seed) { return _normal.randomSync(n, mu, sigma, seed); }, }; exports.t = { pdf: function (x, degreesOfFreedom) { return studentsT.pdf(x, degreesOfFreedom); }, cdf: function (x, degreesOfFreedom, lowerTail = true) { return studentsT.cdf(x, degreesOfFreedom, lowerTail); }, quantile: function (p, degreesOfFreedom, lowerTail = true) { return studentsT.quantile(p, degreesOfFreedom, lowerTail); }, random: function (n, degreesOfFreedom, seed) { return studentsT.random(n, degreesOfFreedom, seed); }, pdfSync: function (x, degreesOfFreedom) { return studentsT.pdfSync(x, degreesOfFreedom); }, cdfSync: function (x, degreesOfFreedom, lowerTail = true) { return studentsT.cdfSync(x, degreesOfFreedom, lowerTail); }, quantileSync: function (p, degreesOfFreedom, lowerTail = true) { return studentsT.quantileSync(p, degreesOfFreedom, lowerTail); }, randomSync: function (n, degreesOfFreedom, seed) { return studentsT.randomSync(n, degreesOfFreedom, seed); } }; exports.chi2 = { pdf: function (x, degreesOfFreedom) { return chiSquared.pdf(x, degreesOfFreedom); }, cdf: function (x, degreesOfFreedom, lowerTail = true) { return chiSquared.cdf(x, degreesOfFreedom, lowerTail); }, quantile: function (p, degreesOfFreedom, lowerTail = true) { return chiSquared.quantile(p, degreesOfFreedom, lowerTail); }, random: function (n, degreesOfFreedom, seed) { return chiSquared.random(n, degreesOfFreedom, seed); }, pdfSync: function (x, degreesOfFreedom) { return chiSquared.pdfSync(x, degreesOfFreedom); }, cdfSync: function (x, degreesOfFreedom, lowerTail = true) { return chiSquared.cdfSync(x, degreesOfFreedom, lowerTail); }, quantileSync: function (p, degreesOfFreedom, lowerTail = true) { return chiSquared.quantileSync(p, degreesOfFreedom, lowerTail); }, randomSync: function (n, degreesOfFreedom, seed) { return chiSquared.randomSync(n, degreesOfFreedom, seed); } }; exports.F = { pdf: function (x, dof1, dof2) { return fDist.pdf(x, dof1, dof2); }, cdf: function (x, dof1, dof2, lowerTail = true) { return fDist.cdf(x, dof1, dof2, lowerTail); }, quantile: function (p, dof1, dof2, lowerTail = true) { return fDist.quantile(p, dof1, dof2, lowerTail); }, random: function (n, dof1, dof2, seed) { return fDist.random(n, dof1, dof2, seed); }, pdfSync: function (x, dof1, dof2) { return fDist.pdfSync(x, dof1, dof2); }, cdfSync: function (x, dof1, dof2, lowerTail = true) { return fDist.cdfSync(x, dof1, dof2, lowerTail); }, quantileSync: function (p, dof1, dof2, lowerTail = true) { return fDist.quantileSync(p, dof1, dof2, lowerTail); }, randomSync: function (n, dof1, dof2, seed) { return fDist.randomSync(n, dof1, dof2, seed); } }; exports.exponential = { pdf: function (x, lambda) { return exp.pdf(x, lambda); }, cdf: function (x, lambda, lowerTail = true) { return exp.cdf(x, lambda, lowerTail); }, quantile: function (p, lambda, lowerTail = true) { return exp.quantile(p, lambda, lowerTail); }, random: function (n, lambda, seed) { return exp.random(n, lambda, seed); }, pdfSync: function (x, lambda) { return exp.pdfSync(x, lambda); }, cdfSync: function (x, lambda, lowerTail = true) { return exp.cdfSync(x, lambda, lowerTail); }, quantileSync: function (p, lambda, lowerTail = true) { return exp.quantileSync(p, lambda, lowerTail); }, randomSync: function (n, lambda, seed) { return exp.randomSync(n, lambda, seed); } }; exports.gamma = { pdf: function (x, shape, scale) { return _gamma.pdf(x, shape, scale); }, cdf: function (x, shape, scale, lowerTail = true) { return _gamma.cdf(x, shape, scale, lowerTail); }, quantile: function (p, shape, scale, lowerTail = true) { return _gamma.quantile(p, shape, scale, lowerTail); }, random: function (n, shape, scale, seed) { return _gamma.random(n, shape, scale, seed); }, pdfSync: function (x, shape, scale) { return _gamma.pdfSync(x, shape, scale); }, cdfSync: function (x, shape, scale, lowerTail = true) { return _gamma.cdfSync(x, shape, scale, lowerTail); }, quantileSync: function (p, shape, scale, lowerTail = true) { return _gamma.quantileSync(p, shape, scale, lowerTail); }, randomSync: function (n, shape, scale, seed) { return _gamma.randomSync(n, shape, scale, seed); } }; exports.beta = { pdf: function (x, alpha, beta) { return _beta.pdf(x, alpha, beta); }, cdf: function (x, alpha, beta, lowerTail = true) { return _beta.cdf(x, alpha, beta, lowerTail); }, quantile: function (x, alpha, beta, lowerTail = true) { return _beta.quantile(x, alpha, beta, lowerTail); }, random: function (n, alpha, beta, seed) { return _beta.random(n, alpha, beta, seed); }, pdfSync: function (x, alpha, beta) { return _beta.pdfSync(x, alpha, beta); }, cdfSync: function (x, alpha, beta, lowerTail = true) { return _beta.cdfSync(x, alpha, beta, lowerTail); }, quantileSync: function (x, alpha, beta, lowerTail = true) { return _beta.quantileSync(x, alpha, beta, lowerTail); }, randomSync: function (n, alpha, beta, seed) { return _beta.randomSync(n, alpha, beta, seed); } }; exports.binomial = { pdf: function (k, trials, probSuccess) { return binom.pmf(k, trials, probSuccess); }, cdf: function (k, trials, probSuccess, lowerTail = true) { return binom.cdf(k, trials, probSuccess, lowerTail); }, quantile: function (p, trials, probSuccess, lowerTail = true) { return binom.quantile(p, trials, probSuccess, lowerTail); }, random: function (n, trials, probSuccess, seed) { return binom.random(n, trials, probSuccess, seed); }, pdfSync: function (k, trials, probSuccess) { return binom.pmfSync(k, trials, probSuccess); }, cdfSync: function (k, trials, probSuccess, lowerTail = true) { return binom.cdfSync(k, trials, probSuccess, lowerTail); }, quantileSync: function (p, trials, probSuccess, lowerTail = true) { return binom.quantileSync(p, trials, probSuccess, lowerTail); }, randomSync: function (n, trials, probSuccess, seed) { return binom.randomSync(n, trials, probSuccess, seed); } }; exports.poisson = { pdf: function (k, lambda) { return _poisson.pmf(k, lambda); }, cdf: function (k, lambda, lowerTail = true) { return _poisson.cdf(k, lambda, lowerTail); }, quantile: function (p, lambda, lowerTail = true) { return _poisson.quantile(p, lambda, lowerTail); }, random: function (n, lambda, seed) { return _poisson.random(n, lambda, seed); }, pdfSync: function (k, lambda) { return _poisson.pmfSync(k, lambda); }, cdfSync: function (k, lambda, lowerTail = true) { return _poisson.cdfSync(k, lambda, lowerTail); }, quantileSync: function (p, lambda, lowerTail = true) { return _poisson.quantileSync(p, lambda, lowerTail); }, randomSync: function (n, lambda, seed) { return _poisson.randomSync(n, lambda, seed); } }; exports.hypergeometric = { pdf: function (sampleSuccesses, draws, successPop, totalPop) { return hypergeo.pmf(sampleSuccesses, draws, successPop, totalPop); }, cdf: function (sampleSuccesses, draws, successPop, totalPop, lowerTail = true) { return hypergeo.cdf(sampleSuccesses, draws, successPop, totalPop, lowerTail); }, quantile: function (p, draws, successPop, totalPop, lowerTail = true) { return hypergeo.quantile(p, draws, successPop, totalPop, lowerTail); }, random: function (n, draws, successPop, totalPop, seed) { return hypergeo.random(n, draws, successPop, totalPop, seed); }, pdfSync: function (sampleSuccesses, draws, successPop, totalPop) { return hypergeo.pmfSync(sampleSuccesses, draws, successPop, totalPop); }, cdfSync: function (sampleSuccesses, draws, successPop, totalPop, lowerTail = true) { return hypergeo.cdfSync(sampleSuccesses, draws, successPop, totalPop, lowerTail); }, quantileSync: function (p, draws, successPop, totalPop, lowerTail = true) { return hypergeo.quantileSync(p, draws, successPop, totalPop, lowerTail); }, randomSync: function (n, draws, successPop, totalPop, seed) { return hypergeo.randomSync(n, draws, successPop, totalPop, seed); } };