Skip to content

API reference

All functions accept scalars or array-likes and broadcast like NumPy ufuncs. lower_tail=False selects R's direct upper-tail algorithm; log=True works on the log scale for d, p and q alike.

Distributions

accudist R notes
dnorm(x, mean=0.0, sd=1.0, log=False, *, out=None) dnorm(x, mean = 0, sd = 1, log = FALSE)
pnorm(q, mean=0.0, sd=1.0, lower_tail=True, log=False, *, out=None) pnorm(q, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)
qnorm(p, mean=0.0, sd=1.0, lower_tail=True, log=False, *, out=None) qnorm(p, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)
rnorm(n, mean=0.0, sd=1.0) rnorm(n, mean = 0, sd = 1) not R's set.seed() stream
dunif(x, min=0.0, max=1.0, log=False, *, out=None) dunif(x, min = 0, max = 1, log = FALSE)
punif(q, min=0.0, max=1.0, lower_tail=True, log=False, *, out=None) punif(q, min = 0, max = 1, lower.tail = TRUE, log.p = FALSE)
qunif(p, min=0.0, max=1.0, lower_tail=True, log=False, *, out=None) qunif(p, min = 0, max = 1, lower.tail = TRUE, log.p = FALSE)
runif(n, min=0.0, max=1.0) runif(n, min = 0, max = 1) not R's set.seed() stream
dgamma(x, shape, rate=None, scale=None, log=False, *, out=None) dgamma(x, shape, rate = 1, scale = 1/rate, log = FALSE) rate or scale, not both
pgamma(q, shape, rate=None, scale=None, lower_tail=True, log=False, *, out=None) pgamma(q, shape, rate = 1, scale = 1/rate, lower.tail = TRUE, log.p = FALSE) rate or scale, not both
qgamma(p, shape, rate=None, scale=None, lower_tail=True, log=False, *, out=None) qgamma(p, shape, rate = 1, scale = 1/rate, lower.tail = TRUE, log.p = FALSE) rate or scale, not both
rgamma(n, shape, rate=None, scale=None) rgamma(n, shape, rate = 1, scale = 1/rate) rate or scale, not both; not R's set.seed() stream
dbeta(x, shape1, shape2, ncp=None, log=False, *, out=None) dbeta(x, shape1, shape2, ncp, log = FALSE) ncp=None -> central algorithm; any value -> non-central
pbeta(q, shape1, shape2, ncp=None, lower_tail=True, log=False, *, out=None) pbeta(q, shape1, shape2, ncp, lower.tail = TRUE, log.p = FALSE) ncp=None -> central algorithm; any value -> non-central
qbeta(p, shape1, shape2, ncp=None, lower_tail=True, log=False, *, out=None) qbeta(p, shape1, shape2, ncp, lower.tail = TRUE, log.p = FALSE) ncp=None -> central algorithm; any value -> non-central
rbeta(n, shape1, shape2, ncp=None) rbeta(n, shape1, shape2, ncp) ncp=None -> central algorithm; any value -> non-central; not R's set.seed() stream
dlnorm(x, meanlog=0.0, sdlog=1.0, log=False, *, out=None) dlnorm(x, meanlog = 0, sdlog = 1, log = FALSE)
plnorm(q, meanlog=0.0, sdlog=1.0, lower_tail=True, log=False, *, out=None) plnorm(q, meanlog = 0, sdlog = 1, lower.tail = TRUE, log.p = FALSE)
qlnorm(p, meanlog=0.0, sdlog=1.0, lower_tail=True, log=False, *, out=None) qlnorm(p, meanlog = 0, sdlog = 1, lower.tail = TRUE, log.p = FALSE)
rlnorm(n, meanlog=0.0, sdlog=1.0) rlnorm(n, meanlog = 0, sdlog = 1) not R's set.seed() stream
dchisq(x, df, ncp=None, log=False, *, out=None) dchisq(x, df, ncp, log = FALSE) ncp=None -> central algorithm; any value -> non-central
pchisq(q, df, ncp=None, lower_tail=True, log=False, *, out=None) pchisq(q, df, ncp, lower.tail = TRUE, log.p = FALSE) ncp=None -> central algorithm; any value -> non-central
qchisq(p, df, ncp=None, lower_tail=True, log=False, *, out=None) qchisq(p, df, ncp, lower.tail = TRUE, log.p = FALSE) ncp=None -> central algorithm; any value -> non-central
rchisq(n, df, ncp=None) rchisq(n, df, ncp) ncp=None -> central algorithm; any value -> non-central; not R's set.seed() stream
df(x, df1, df2, ncp=None, log=False, *, out=None) df(x, df1, df2, ncp, log = FALSE) ncp=None -> central algorithm; any value -> non-central
pf(q, df1, df2, ncp=None, lower_tail=True, log=False, *, out=None) pf(q, df1, df2, ncp, lower.tail = TRUE, log.p = FALSE) ncp=None -> central algorithm; any value -> non-central
qf(p, df1, df2, ncp=None, lower_tail=True, log=False, *, out=None) qf(p, df1, df2, ncp, lower.tail = TRUE, log.p = FALSE) ncp=None -> central algorithm; any value -> non-central
rf(n, df1, df2, ncp=None) rf(n, df1, df2, ncp) ncp=None -> central algorithm; any value -> non-central; not R's set.seed() stream
dt(x, df, ncp=None, log=False, *, out=None) dt(x, df, ncp, log = FALSE) ncp=None -> central algorithm; any value -> non-central
pt(q, df, ncp=None, lower_tail=True, log=False, *, out=None) pt(q, df, ncp, lower.tail = TRUE, log.p = FALSE) ncp=None -> central algorithm; any value -> non-central
qt(p, df, ncp=None, lower_tail=True, log=False, *, out=None) qt(p, df, ncp, lower.tail = TRUE, log.p = FALSE) ncp=None -> central algorithm; any value -> non-central
rt(n, df, ncp=None) rt(n, df, ncp) ncp=None -> central algorithm; any value -> non-central; not R's set.seed() stream
dbinom(x, size, prob, log=False, *, out=None) dbinom(x, size, prob, log = FALSE)
pbinom(q, size, prob, lower_tail=True, log=False, *, out=None) pbinom(q, size, prob, lower.tail = TRUE, log.p = FALSE)
qbinom(p, size, prob, lower_tail=True, log=False, *, out=None) qbinom(p, size, prob, lower.tail = TRUE, log.p = FALSE)
rbinom(n, size, prob) rbinom(n, size, prob) not R's set.seed() stream
dcauchy(x, location=0.0, scale=1.0, log=False, *, out=None) dcauchy(x, location = 0, scale = 1, log = FALSE)
pcauchy(q, location=0.0, scale=1.0, lower_tail=True, log=False, *, out=None) pcauchy(q, location = 0, scale = 1, lower.tail = TRUE, log.p = FALSE)
qcauchy(p, location=0.0, scale=1.0, lower_tail=True, log=False, *, out=None) qcauchy(p, location = 0, scale = 1, lower.tail = TRUE, log.p = FALSE)
rcauchy(n, location=0.0, scale=1.0) rcauchy(n, location = 0, scale = 1) not R's set.seed() stream
dexp(x, rate=1.0, log=False, *, out=None) dexp(x, rate = 1, log = FALSE) C takes scale = 1/rate
pexp(q, rate=1.0, lower_tail=True, log=False, *, out=None) pexp(q, rate = 1, lower.tail = TRUE, log.p = FALSE) C takes scale = 1/rate
qexp(p, rate=1.0, lower_tail=True, log=False, *, out=None) qexp(p, rate = 1, lower.tail = TRUE, log.p = FALSE) C takes scale = 1/rate
rexp(n, rate=1.0) rexp(n, rate = 1) C takes scale = 1/rate; not R's set.seed() stream
dgeom(x, prob, log=False, *, out=None) dgeom(x, prob, log = FALSE)
pgeom(q, prob, lower_tail=True, log=False, *, out=None) pgeom(q, prob, lower.tail = TRUE, log.p = FALSE)
qgeom(p, prob, lower_tail=True, log=False, *, out=None) qgeom(p, prob, lower.tail = TRUE, log.p = FALSE)
rgeom(n, prob) rgeom(n, prob) not R's set.seed() stream
dhyper(x, m, n, k, log=False, *, out=None) dhyper(x, m, n, k, log = FALSE)
phyper(q, m, n, k, lower_tail=True, log=False, *, out=None) phyper(q, m, n, k, lower.tail = TRUE, log.p = FALSE)
qhyper(p, m, n, k, lower_tail=True, log=False, *, out=None) qhyper(p, m, n, k, lower.tail = TRUE, log.p = FALSE)
rhyper(nn, m, n, k) rhyper(nn, m, n, k) not R's set.seed() stream
dnbinom(x, size, prob=None, mu=None, log=False, *, out=None) dnbinom(x, size, prob, mu, log = FALSE) exactly one of prob, mu
pnbinom(q, size, prob=None, mu=None, lower_tail=True, log=False, *, out=None) pnbinom(q, size, prob, mu, lower.tail = TRUE, log.p = FALSE) exactly one of prob, mu
qnbinom(p, size, prob=None, mu=None, lower_tail=True, log=False, *, out=None) qnbinom(p, size, prob, mu, lower.tail = TRUE, log.p = FALSE) exactly one of prob, mu
rnbinom(n, size, prob=None, mu=None) rnbinom(n, size, prob, mu) exactly one of prob, mu; not R's set.seed() stream
dpois(x, lambda_, log=False, *, out=None) dpois(x, lambda, log = FALSE)
ppois(q, lambda_, lower_tail=True, log=False, *, out=None) ppois(q, lambda, lower.tail = TRUE, log.p = FALSE)
qpois(p, lambda_, lower_tail=True, log=False, *, out=None) qpois(p, lambda, lower.tail = TRUE, log.p = FALSE)
rpois(n, lambda_) rpois(n, lambda) not R's set.seed() stream
dweibull(x, shape, scale=1.0, log=False, *, out=None) dweibull(x, shape, scale = 1, log = FALSE)
pweibull(q, shape, scale=1.0, lower_tail=True, log=False, *, out=None) pweibull(q, shape, scale = 1, lower.tail = TRUE, log.p = FALSE)
qweibull(p, shape, scale=1.0, lower_tail=True, log=False, *, out=None) qweibull(p, shape, scale = 1, lower.tail = TRUE, log.p = FALSE)
rweibull(n, shape, scale=1.0) rweibull(n, shape, scale = 1) not R's set.seed() stream
dlogis(x, location=0.0, scale=1.0, log=False, *, out=None) dlogis(x, location = 0, scale = 1, log = FALSE)
plogis(q, location=0.0, scale=1.0, lower_tail=True, log=False, *, out=None) plogis(q, location = 0, scale = 1, lower.tail = TRUE, log.p = FALSE)
qlogis(p, location=0.0, scale=1.0, lower_tail=True, log=False, *, out=None) qlogis(p, location = 0, scale = 1, lower.tail = TRUE, log.p = FALSE)
rlogis(n, location=0.0, scale=1.0) rlogis(n, location = 0, scale = 1) not R's set.seed() stream
dwilcox(x, m, n, log=False, *, out=None) dwilcox(x, m, n, log = FALSE) locked shared table; see free_caches()
pwilcox(q, m, n, lower_tail=True, log=False, *, out=None) pwilcox(q, m, n, lower.tail = TRUE, log.p = FALSE) locked shared table; see free_caches()
qwilcox(p, m, n, lower_tail=True, log=False, *, out=None) qwilcox(p, m, n, lower.tail = TRUE, log.p = FALSE) locked shared table; see free_caches()
rwilcox(nn, m, n) rwilcox(nn, m, n) locked shared table; see free_caches(); not R's set.seed() stream
dsignrank(x, n, log=False, *, out=None) dsignrank(x, n, log = FALSE) locked shared table; see free_caches()
psignrank(q, n, lower_tail=True, log=False, *, out=None) psignrank(q, n, lower.tail = TRUE, log.p = FALSE) locked shared table; see free_caches()
qsignrank(p, n, lower_tail=True, log=False, *, out=None) qsignrank(p, n, lower.tail = TRUE, log.p = FALSE) locked shared table; see free_caches()
rsignrank(nn, n) rsignrank(nn, n) locked shared table; see free_caches(); not R's set.seed() stream
ptukey(q, nmeans, df, nranges=1.0, lower_tail=True, log=False, *, out=None) ptukey(q, nmeans, df, nranges = 1, lower.tail = TRUE, log.p = FALSE) C argument order differs from R's; handled internally
qtukey(p, nmeans, df, nranges=1.0, lower_tail=True, log=False, *, out=None) qtukey(p, nmeans, df, nranges = 1, lower.tail = TRUE, log.p = FALSE) C argument order differs from R's; handled internally

Special functions

These keep Rmath's C names, so gammafn sits unambiguously beside dgamma.

accudist R summary
gammafn(x) gamma(x)
lgammafn(x) lgamma(x)
digamma(x) digamma(x)
trigamma(x) trigamma(x)
tetragamma(x) psigamma(x, 2) deprecated in R
pentagamma(x) psigamma(x, 3) deprecated in R
psigamma(x, deriv=0.0) psigamma(x, deriv)
beta(a, b) beta(a, b)
lbeta(a, b) lbeta(a, b)
choose(n, k) choose(n, k)
lchoose(n, k) lchoose(n, k)
bessel_j(x, nu) besselJ(x, nu)
bessel_y(x, nu) besselY(x, nu)
bessel_i(x, nu, expon_scaled=False) besselI(x, nu, expon.scaled)
bessel_k(x, nu, expon_scaled=False) besselK(x, nu, expon.scaled)

Numerical utilities

accudist summary
log1pmx(x) log(1+x) - x, accurate for small x
log1mexp(x) log(1 - exp(-x)), accurate for small and large x
pow1p(x, y) (1 + x)^y, accurate also for
log1pexp(x) log(1 + exp(x)) without overflow
lgamma1p(x) lgamma(1+x), accurate for small x
logspace_add(logx, logy) log(exp(logx) + exp(logy))
logspace_sub(logx, logy) log(exp(logx) - exp(logy))
cospi(x) cos(pi*x), exact at half-integers
sinpi(x) sin(pi*x), exact at integers
tanpi(x) tan(pi*x)
fprec(x, digits) round x to digits significant digits
fround(x, digits) R's round(), banker's rounding
fsign(x, y)
ftrunc(x) truncate toward zero
sign(x) -1, 0, or 1

Bespoke wrappers

accudist C symbol why not a plain ufunc
pnorm_both pnorm_both Writes both lower and upper tail through double* out-params; wrapper returns a 2-tuple of arrays. Cannot be a plain ufunc.
lgammafn_sign lgammafn_sign Returns lgamma via return value and the sign via int* out-param; wrapper returns a 2-tuple.
rmultinom rmultinom Fills an int* vector of length K; wrapper returns an (n, K) int array. Requires the RNG lock.
logspace_sum logspace_sum Takes const double* + length. Expose as a reduction over the last axis, not a ufunc.

RNG primitives

accudist summary
unif_rand Marsaglia-MultiCarry uniform on [0,1)
norm_rand standard normal, inversion
exp_rand standard exponential
set_seed install global (I1, I2) state
get_seed read global (I1, I2) state

Deliberately excluded Rmath.h symbols

symbol reason
Rlog1p internal alias of log1p
fmax2 duplicate of numpy.maximum
fmin2 duplicate of numpy.minimum
imax2 trivial integer max
imin2 trivial integer min
R_pow duplicate of numpy.power
R_pow_di duplicate of numpy.power
R_isnancpp internal C++ shim
R_finite duplicate of numpy.isfinite
dpsifn internal engine behind psigamma
bessel_i_ex caller-supplied work array; internal
bessel_j_ex caller-supplied work array; internal
bessel_k_ex caller-supplied work array; internal
bessel_y_ex caller-supplied work array; internal
dbinom_raw internal helper; reachable via accudist.rmath only
dpois_raw internal helper; reachable via accudist.rmath only
Rtanpi R-internal variant of tanpi (returns +-Inf at half-integers instead of NaN); tanpi is exposed
rnbeta declared in Rmath.h but implemented in no .c file; rbeta(..., ncp) is composed from rchisq as R does