Skip to content

Instantly share code, notes, and snippets.

@BillFoster
Created February 17, 2012 14:05
Show Gist options
  • Save BillFoster/1853611 to your computer and use it in GitHub Desktop.
Save BillFoster/1853611 to your computer and use it in GitHub Desktop.
replace cdfNormal function in stats extension
//Cumulative Distribution Function of the Normal(0,1) distribution.
//based on "A Note on Approximating the Normal Distribution Function", K. M. Aludaat and M. T. Alodat, Applied Mathematical Sciences 2008
//Better is Abramowitz and Stegun;" Handbook of Mathematical Functions." 1964,(formula: 26.2.17) as implemented below
//var cdfconst = Math.sqrt(Math.PI/8);
math.normalCDF = function(z)
{
var p = 0.2316419;
var a1=0.319381530;
var a2=-0.356563782;
var a3=1.781477937;
var a4=-1.821255978;
var a5= 1.330274429;
var t = 1/(1+p*z);
//return 0.5+0.5*Math.sqrt(1-Math.exp(-cdfconst*z*z));
return 1-math.pdfNormal(z,0,1)*(a1*t+a2*Math.pow(t,2)+a3*Math.pow(t,3)+a4*Math.pow(t,4)+a5*Math.pow(t,5));
}
new funcObj('cdfNormal',[TNum],TNum,math.normalCDF);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment