simple-statistics
Version:
27 lines (24 loc) • 815 B
JavaScript
import epsilon from "./epsilon.js";
import inverseErrorFunction from "./inverse_error_function.js";
/**
* The [Probit](http://en.wikipedia.org/wiki/Probit)
* is the inverse of cumulativeStdNormalProbability(),
* and is also known as the normal quantile function.
*
* It returns the number of standard deviations from the mean
* where the p'th quantile of values can be found in a normal distribution.
* So, for example, probit(0.5 + 0.6827/2) ≈ 1 because 68.27% of values are
* normally found within 1 standard deviation above or below the mean.
*
* @param {number} p
* @returns {number} probit
*/
function probit(p) {
if (p === 0) {
p = epsilon;
} else if (p >= 1) {
p = 1 - epsilon;
}
return Math.sqrt(2) * inverseErrorFunction(2 * p - 1);
}
export default probit;