lua-sci icon indicating copy to clipboard operation
lua-sci copied to clipboard

Add a cdf() and ppf() method to sci.dist

Open aktau opened this issue 5 years ago • 0 comments

We currently only have pdf (https://scilua.org/sci_dist.html):

y = sd:pdf(x)
Returns the value of the probability density function (for continuous distributions) or of the mass probability function (for discrete distributions) computed at x for sd. The domain of this function is the real line.

But I would like to calculate confidence intervals using the Beta distrbution:

dist = require('sci.dist')
local d = dist.beta(5,17)
print(d:ppf(0.05), d:ppf(0.95))

Example equivalent currently possible with scipy:

>>> from scipy.stats import beta
>>> print(beta.ppf([0.05, 0.95], 5, 17))
[0.09884353 0.38440811]

This seems to be based on the cephes C library. E.g.: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.btdtri.html#scipy.special.btdtri

For this I'd need the latter of:

y = sd:cdf(x): the cumulative distribution function at x (find x for cdf(y) = x)
y = sd:ppf(x): the inverse of the cumulative distribution function at x (find x for cdf(x) = y)

aktau avatar Feb 19 '21 15:02 aktau