cdflib_wasm is a WebAssembly packaging of the cdflib library as it appears in the presto project.
This library contains routines to compute cumulative distribution functions, inverses, and parameters of the distribution for the following set of statistical distributions:
(1) Beta
(2) Binomial
(3) Chi-square
(4) Noncentral Chi-square
(5) F
(6) Noncentral F
(7) Gamma
(8) Negative Binomial
(9) Normal
(10) Poisson
(11) Student's t
(12) Noncentral Student's t
Given values of all but one parameter of a distribution, the other is computed. These calculations are done with C pointers to Doubles.
http://www.netlib.org/random/ dcdflib.c README file
npm install cdflib_wasmFor good practice, cdflib compiles asyncronously by default.
You must therefore wait for the .compiled promise to be resolved.
const CdfLibWrapper = require("cdflib_wasm");
const cdflib = new CdfLibWrapper();
await cdflib.compiled;
cdflib.cdft_1(18, -2.10092204024096);It is possible to syncronously compile cdflib.
const cdflib = new CdfLibWrapper({ compileSync: true });
cdflib.cdft_1(18, -2.10092204024096);| Functions | Documentation |
|---|---|
cdfbet |
Calculates parameters of the beta distribution. |
cdfbin |
Calculates parameters of the binomial distribution. |
cdfchi |
Calculates parameters of the chi-square distribution. |
cdfchn |
Calculates parameters of the non-central chi-square distribution. |
cdff |
Calculates parameters of the F distribution. |
cdffnc |
Calculates parameters of the non-central F distribution. |
cdfgam |
Calculates parameters of the gamma distribution. |
cdfnbn |
Calculates parameters of the negative binomial distribution. |
cdfnor |
Calculates parameters of the normal distribution. |
cdfpoi |
Calculates parameters of the Poisson distribution. |
cdft |
Calculates parameters of the student's t distribution. |
cdftnc |
Calculates parameters of the non-central student's t distribution. |
Calculates any one parameter of the beta distribution given values for the others.
P <--> The integral from 0 to X of the chi-square
distribution.
Input range: [0, 1].
X <--> Upper limit of integration of beta density.
Input range: [0, 1].
Search range: [0, 1]
A <--> The first parameter of the beta density.
Input range: (0, +infinity).
Search range: [1D-100, 1D100]
B <--> The second parameter of the beta density.
Input range: (0, +infinity).
Search range: [1D-100, 1D100]
cdfbet_1 Calculates P from X, A and B
const p = cdflib.cdfbet_1(x, a, b);cdfbet_2 Calculate X from P, A and B
const x = cdflib.cdfbet_2(p, a, b);cdfbet_3 Calculate A from P, X and B
const a = cdflib.cdfbet_3(p, b, x);cdfbet_4 Calculate B from P, X and A
const b = cdflib.cdfbet_4(a, p, x);Calculates any one parameter of the binomial distribution given values for the others.
P <--> The cumulation from 0 to S of the binomial distribution.
(Probablility of S or fewer successes in XN trials each
with probability of success PR.)
Input range: [0, 1].
S <--> The number of successes observed.
Input range: [0, XN]
Search range: [0, XN]
XN <--> The number of binomial trials.
Input range: (0, +infinity).
Search range: [1E-100, 1E100]
PR <--> The probability of success in each binomial trial.
Input range: [0, 1].
Search range: [0, 1]
cdfbin_1 Calculate P from S, XN, PR
const p = cdflib.cdfbin_1(s, xn, pr);cdfbin_2 Calculate S from P, XN, PR
const s = cdflib.cdfbin_2(p, xn, pr);cdfbin_3 Calculate XN from P, S, PR
const xn = cdflib.cdfbin_3(p, s, pr);cdfbin_4 Calculate PR from P, S and XN
const pr = cdflib.cdfbin_4(p, s, xn);Calculates any one parameter of the chi-squared distribution given values for the others.
P <--> The integral from 0 to X of the chi-square
distribution.
Input range: [0, 1].
X <--> Upper limit of integration of the non-central
chi-square distribution.
Input range: [0, +infinity).
Search range: [0, 1E100]
DF <--> Degrees of freedom of the
chi-square distribution.
Input range: (0, +infinity).
Search range: [ 1E-100, 1E100]
cdfchi_1 Calculate P from X and DF
const p = cdflib.cdfchi_1(x, df);cdfchi_2 Calculate X from P and DF
const x = cdflib.cdfchi_2(p, df);cdfchi_3 Calculate DF from P and X
const df = cdflib.cdfchi_3(p, x);Calculates any one parameter of the non-central chi-squared distribution given values for the others.
P <--> The integral from 0 to X of the non-central chi-square
distribution.
Input range: [0, 1-1E-16).
X <--> Upper limit of integration of the non-central
chi-square distribution.
Input range: [0, +infinity).
Search range: [0, 1E100]
DF <--> Degrees of freedom of the non-central
chi-square distribution.
Input range: (0, +infinity).
Search range: [ 1E-100, 1E100]
NC <--> Non-centrality parameter of the non-central
chi-square distribution.
Input range: [0, +infinity).
Search range: [0, 1E4]
Warning The computation time required for this routine is proportional to the noncentrality parameter (NC). Very large values of this parameter can consume immense computer resources. This is why the search range is bounded by 10,000.
cdfchn_1 Calculate P from X and DF
const p = cdflib.cdfchn_1(x, df, nc);cdfchn_2 Calculate X from P, DF and NC
const x = cdflib.cdfchn_2(p, df, nc);cdfchn_3 Calculate DF from P, X and NC
const df = cdflib.cdfchn_3(x, p, nc);cdfchn_4 Calculate NC from P, X and DF
const pnonc = cdflib.cdfchn_4(x, df, p);Calculates any one parameter of the F distribution given values for the others.
P <--> The integral from 0 to F of the f-density.
Input range: [0, 1].
F <--> Upper limit of integration of the f-density.
Input range: [0, +infinity).
Search range: [0, 1E100]
DFN < --> Degrees of freedom of the numerator sum of squares.
Input range: (0, +infinity).
Search range: [ 1E-100, 1E100]
DFD < --> Degrees of freedom of the denominator sum of squares.
Input range: (0, +infinity).
Search range: [ 1E-100, 1E100]
Warning The value of the cumulative F distribution is not necessarily monotone in either degrees of freedom. There thus may be two values that provide a given CDF value. This routine assumes monotonicity and will find an arbitrary one of the two values.
cdff_1 Calculate P from F, DFN and DFD
const p = cdflib.cdff_1(dfc, dfd, f);cdff_2 Calculate F from P, DFN and DFD
const f = cdflib.cdff_2(dfn, dfd, p);cdff_3 Calculate DFN from P, F and DFD
const dfn = cdflib.cdff_3(p, dfd, f);cdff_4 Calculate DFD from P, F and DFN
const dfd = cdflib.cdff_4(dfn, p, f);Calculates any one parameter of the Non-central F distribution given values for the others.
P <--> The integral from 0 to F of the non-central f-density.
Input range: [0, 1-1E-16).
F <--> Upper limit of integration of the non-central f-density.
Input range: [0, +infinity).
Search range: [0, 1E100]
DFN < --> Degrees of freedom of the numerator sum of squares.
Input range: (0, +infinity).
Search range: [ 1E-100, 1E100]
DFD < --> Degrees of freedom of the denominator sum of squares.
Must be in range: (0, +infinity).
Input range: (0, +infinity).
Search range: [ 1E-100, 1E100]
NC <-> The non-centrality parameter
Input range: [0, infinity)
Search range: [0, 1E4]
Warning
The computation time required for this routine is proportional to the noncentrality parameter (PNONC). Very large values of this parameter can consume immense computer resources. This is why the search range is bounded by 10,000.
Warning
The value of the cumulative noncentral F distribution is not necessarily monotone in either degrees of freedom. There thus may be two values that provide a given CDF value. This routine assumes monotonicity and will find an arbitrary one of the two values.
cdffnc_1 Calculate P from F, DFN, DFD and NC
const p = cdflib.cdffnc_1(dfc, dfd, nc, f);cdffnc_2 Calculate F from P, DFN, DFD and NC
const f = cdflib.cdffnc_2(dfn, dfd, nc, p);cdffnc_3 Calculate DFN from P, F, DFD and NC
const dfn = cdflib.cdffnc_3(p, dfd, nc, f);cdffnc_4 Calculate DFD from P, F, DFN and NC
const dfd = cdflib.cdffnc_4(dfn, p, nc, f);cdffnc_5 Calculate NC from P, F, DFN and DFD
const pnonc = cdflib.cdffnc_5(dfn, dfd, p, f);Calculates any one parameter of the gamma distribution given values for the others.
P <--> The integral from 0 to X of the gamma density.
Input range: [0, 1].
X <--> The upper limit of integration of the gamma density.
Input range: [0, +infinity).
Search range: [0, 1E100]
SHAPE <--> The shape parameter of the gamma density.
Input range: (0, +infinity).
Search range: [1E-100, 1E100]
SCALE <--> The scale parameter of the gamma density.
Input range: (0, +infinity).
Search range: (1E-100, 1E100]
cdfgam_1 Calculate P from X, SHAPE and SCALE
const p = cdflib.cdfgam_1(scale, shape, x);cdfgam_2 Calculate X from P, SHAPE and SCALE
const x = cdflib.cdfgam_2(scale, shape, p);cdfgam_3 Calculate SHAPE from P, X and SCALE
const shape = cdflib.cdfgam_3(scale, p, x);cdfgam_4 Calculate SCALE from P, X and SHAPE
const scale = cdflib.cdfgam_4(p, shape, x);Calculates any one parameter of the negative binomial distribution given values for the others.
The cumulative negative binomial distribution returns the probability that there will be F or fewer failures before the XNth success in binomial trials each of which has probability of success PR.
The individual term of the negative binomial is the probability of
S failures before XN successes and is
Choose(S, XN+S-1) * PR^(XN) * (1-PR)^S
P <--> The cumulation from 0 to S of the negative
binomial distribution.
Input range: [0, 1].
S <--> The upper limit of cumulation of the binomial distribution.
There are F or fewer failures before the XNth success.
Input range: [0, +infinity).
Search range: [0, 1E100]
XN <--> The number of successes.
Input range: [0, +infinity).
Search range: [0, 1E100]
PR <--> The probability of success in each binomial trial.
Input range: [0, 1].
Search range: [0, 1].
cdfnbn_1 Calculate P from S, XN, PR
const p = cdflib.cdfnbn_1(s, xn, pr);cdfnbn_2 Calculate S from P, XN, PR
const s = cdflib.cdfnbn_2(p, xn, pr);cdfnbn_3 Calculate XN from P, S, PR
const xn = cdflib.cdfnbn_3(s, p, pr);cdfnbn_4 Calculate PR from P, S and XN
const pr = cdflib.cdfnbn_4(s, p, xn);Calculates any one parameter of the normal distribution given values for the others.
P <--> The integral from -infinity to X of the normal density.
Input range: (0, 1].
X < --> Upper limit of integration of the normal-density.
Input range: ( -infinity, +infinity)
MEAN <--> The mean of the normal density.
Input range: (-infinity, +infinity)
STD <--> Standard Deviation of the normal density.
Input range: (0, +infinity).
Note
The normal density is proportional to
exp( - 0.5 * (( X - MEAN)/STD)**2)
cdfnor_1 Calculate P from X, MEAN and STD
const p = cdflib.cdfnor_1(mean, std, x);cdfnor_2 Calculate X from P, MEAN and STD
const x = cdflib.cdfnor_2(mean, p, std);cdfnor_3 Calculate MEAN from P, X and STD
const mean = cdflib.cdfnor_3(p, std, x);cdfnor_4 Calculate STD from P, X and MEAN
const sd = cdflib.cdfnor_4(mean, p, x);Calculates any one parameter of the Poisson distribution given values for the others.
P <--> The cumulation from 0 to S of the poisson density.
Input range: [0, 1].
S <--> Upper limit of cumulation of the Poisson.
Input range: [0, +infinity).
Search range: [0, 1E100]
XLAM <--> Mean of the Poisson distribution.
Input range: [0, +infinity).
Search range: [0, 1E100]
cdfpoi_1 Calculate P from S and XLAM
const p = cdflib.cdfpoi_1(s, xlam);cdfpoi_2 Calculate A from P and XLAM
const a = cdflib.cdfpoi_2(p, xlam);cdfpoi_3 Calculate XLAM from P and S
const xlam = cdflib.cdfpoi_3(p, s);Calculates any one parameter of the student's t distribution given values for the others.
P <--> The integral from -infinity to t of the t-density.
Input range: (0, 1].
T <--> Upper limit of integration of the t-density.
Input range: ( -infinity, +infinity).
Search range: [ -1E100, 1E100 ]
DF <--> Degrees of freedom of the t-distribution.
Input range: (0 , +infinity).
Search range: [1e-100, 1E10]
cdft_1 Calculate P from T and DF
const p = cdflib.cdft_1(df, t);cdft_2 Calculate T from P and DF
const t = cdflib.cdft_2(p, df);cdft_3 Calculate DF from P and T
const df = cdflib.cdft_3(p, t);Calculates any one parameter of the non-central student's t distribution given values for the others.
P <--> The integral from -infinity to t of the noncentral t-den
Input range: (0, 1].
T <--> Upper limit of integration of the noncentral t-density.
Input range: ( -infinity, +infinity).
Search range: [ -1E100, 1E100 ]
DF <--> Degrees of freedom of the noncentral t-distribution.
Input range: (0 , +infinity).
Search range: [1e-100, 1E10]
NC <--> Noncentrality parameter of the noncentral t-distribution.
Input range: [-infinity , +infinity).
Search range: [-1e4, 1E4]
cdftnc_1 Calculate P from T, DF, NC
const p = cdflib.cdftnc_1(df, nc, t);cdftnc_2 Calculate T from P, DF, NC
const t = cdflib.cdftnc_2(df, nc, p);cdftnc_3 Calculate DF from P, NC, T
const df = cdflib.cdftnc_3(p, nc, t);cdftnc_4 Calculate NC from P, DF, T
const pnonc = cdflib.cdftnc_4(df, p, t);- presto for the cdflib C source
- node-cephes which I heavily borrow the wasm packaging from.