Module: rstats

JavaScript port of Rmath functions.

These functions have been directly ported from the Rmath library, found in the R source code repository under R-source/src/include/Rmath.h. Most of the code should look almost identical to the C code, with minor changes to adapt to features present in C but not in JS.

Test cases were ported from R-source/tests/d-p-q-r-tests.R. We additionally wrote other test cases over a range of parameter values and edge cases. These cases are found in our test suite in test/unit/rstats.js.

Author:
  • Matthew Flickinger
  • Ryan Welch
License:
  • LGPL-2.1
Source:

Methods

(static) dchisq(x, df, give_log) → {number|*}

The chi-squared density function.

Parameters:
Name Type Description
x
df
give_log
Source:
Returns:
Type
number | *

(static) dgamma(x, shape, scale, give_log) → {number|*}

The gamma density function.

Parameters:
Name Type Description
x
shape
scale
give_log
Source:
Returns:
Type
number | *

(static) pchisq(x, df, ncp, lower_tail, log_p)

The chi-squared cumulative distribution function.

Supports the non-centrality parameter ncp.

Parameters:
Name Type Description
x number

Value.

df number

Degrees of freedom.

ncp number

Non-centrality parameter.

lower_tail boolean

Return cumulative probability from lower tail?

log_p boolean

Return log probability

Source:

(static) qchisq(p, df, lower_tail, log_p) → {*|number}

Inverse CDF / quantile function for chi-squared distribution.

Parameters:
Name Type Description
p
df
lower_tail
log_p
Source:
Returns:
Type
* | number

(static) qgamma(p, alpha, scale, lower_tail, log_p) → {*|number|number|*}

Inverse CDF / quantile function of gamma distribution.

Parameters:
Name Type Description
p
alpha
scale
lower_tail
log_p
Source:
Returns:
Type
* | number | number | *

(inner) dbeta(x, shape1, shape2, log) → {number}

The beta density function.

The non-central beta distribution parameter is not implemented currently.

Parameters:
Name Type Description
x number

Value.

shape1 number

The first shape parameter, or "alpha."

shape2 number

The second shape parameter, or "beta."

log boolean

Should the result be returned in log scale.

Source:
Returns:

Probability density evaluated at x.

Type
number

(inner) pnorm(x, mu, sigma, lower_tail, give_log)

The normal cumulative distribution function.

Parameters:
Name Type Description
x number

Value.

mu number

Mean of the normal distribution.

sigma number

Standard deviation of the normal distribution.

lower_tail boolean

Should the cumulative probability returned be calculated as the lower tail?

give_log boolean

Return log probability

Source:

(inner) R_Q_P01_boundaries()

Note this has changed from the R implementation which was a C macro. You should wrap this in a try catch, like: try { boundaries(...) } catch (e) { return e; }

Source:

(inner) R_Q_P01_check()

See warning for R_Q_P01_boundaries (this function should be wrapped in try/catch.)

Source: