Search code examples
javascriptfunctionmathnormalizationnormal-distribution

Quantile/Percent Point/Percentile/Inverse Cumulative Distribution function in JavaScript


Is there a way to calculate the quantile/percent point/percentile/inverse cumulative distribution function of a normal distribution in JavaScript? If so, how? The input is a value beween 0 and 1, and the desired output is the one shown below, where 0 gives -inf, 1 gives inf, and 0.5 gives 0:

ppf plot


Solution

  • I managed to do this by taking ptmalcom's answer to this question for the function erfinv and applying the formula printed here to get the percent point function:

        const ppf = function(x) {
        return Math.sqrt(2) * erfinv(2*x-1)
        }