AndreasMadsen / ttest

Perform the Student's t hypothesis test

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: "BigNum/BigDecimal" interface

mscdex opened this issue · comments

It would be nice to be able to perform calculations on arbitrarily large numbers without having to worry about the limitations of JavaScript's Number (or BigInt for that matter).

That would be really challenging, and by that I mean: you could write peer-reviewed papers on this. The Student-t distribution depends on several mathmathical special functions, these are approximations of mathematical functions that can not be computed exactly. However, they can be approximated to a given precision.

In this case, I use cephes (https://github.com/nearform/node-cephes) that approximates to double precision. In theory, one could choose a more precise representation, fx 128bit doubles. However, one has to choose a precision there will never be such a thing as exact for these functions.

I was mostly concerned about the mean calculations since adding up a number of large values could exceed Number.MAX_SAFE_INTEGER. It would probably be enough to convert the final BigNum/BigDecimal mean value to Number though for compatibility with cephes and other libraries.

There are ways to compute mean and variance numerically stable. See for example Welford's online algorithm. I would be happy to accept a PR in my summary module for that.

I don't think BigInt really solves anything, as it will only work for integers.

Summary 2.0.0 now uses numerically stable algorithms for mean and variance