Skip to main content
Module

x/simplestatistics/src/cumulative_std_normal_probability.js

simple statistics for node & browser javascript
Go to Latest
File
import standardNormalTable from "./standard_normal_table.js";
/** * **[Cumulative Standard Normal Probability](http://en.wikipedia.org/wiki/Standard_normal_table)** * * Since probability tables cannot be * printed for every normal distribution, as there are an infinite variety * of normal distributions, it is common practice to convert a normal to a * standard normal and then use the standard normal table to find probabilities. * * You can use `.5 + .5 * errorFunction(x / Math.sqrt(2))` to calculate the probability * instead of looking it up in a table. * * @param {number} z * @returns {number} cumulative standard normal probability */function cumulativeStdNormalProbability(z) { // Calculate the position of this value. const absZ = Math.abs(z); // Each row begins with a different // significant digit: 0.5, 0.6, 0.7, and so on. Each value in the table // corresponds to a range of 0.01 in the input values, so the value is // multiplied by 100. const index = Math.min( Math.round(absZ * 100), standardNormalTable.length - 1 );
// The index we calculate must be in the table as a positive value, // but we still pay attention to whether the input is positive // or negative, and flip the output value as a last step. if (z >= 0) { return standardNormalTable[index]; } else { // due to floating-point arithmetic, values in the table with // 4 significant figures can nevertheless end up as repeating // fractions when they're computed here. return +(1 - standardNormalTable[index]).toFixed(4); }}
export default cumulativeStdNormalProbability;