Search code examples
javascriptmathstandard-deviation

How to find the normal distribution in Javascript?


I'm trying to convert a formula from an Excel spreadsheet into an online calculator, the formula specifically is:

=(NORM.S.DIST(2.5467437 + -1.9344945 *B7^( -0.5),1))^2

The problem I'm encountering is that NORM.S.DIST doesn't appear to exist in any Javascript library that I've found. In researching the problem I did find this solution, but it's a C# based one and I don't know how to convert that into Javascript. How do I approach this problem in Javascript?


Solution

  • EDITED:

    This varies from the actual value by less than 0.005:

    function cummulativeNormalDist(x) {
        if(x < 2.2) {
            return .1 * x * (4.4 - x);
        } else if(x < 2.6) {
            return .49;
        } else {
            return .50;
        }
    }
    

    Source: http://mathworld.wolfram.com/NormalDistributionFunction.html