Can't seem to get a result from this JavaScript math formula. Have added it as a JavaScript item to a button in an HTML5 test pub (plus put in some test number values for variables), published as HTML5 to test, but no result.
Must be scripting it incorrectly?
JavaScript (based on math formula found online-see posting:
viewtopic.php?f=4&t=4573&p=20872&hilit=probit#p20872- for normalizing statistical data):
Code:
function NORMSINV(p)
{
var a = new Array(-3.969683028665376e+01, 2.209460984245205e+02,
-2.759285104469687e+02, 1.383577518672690e+02,
-3.066479806614716e+01, 2.506628277459239e+00);
var b = new Array(-5.447609879822406e+01, 1.615858368580409e+02,
-1.556989798598866e+02, 6.680131188771972e+01,
-1.328068155288572e+01 );
var c = new Array(-7.784894002430293e-03, -3.223964580411365e-01,
-2.400758277161838e+00, -2.549732539343734e+00,
4.374664141464968e+00, 2.938163982698783e+00);
var d = new Array (7.784695709041462e-03, 3.224671290700398e-01,
2.445134137142996e+00, 3.754408661907416e+00);
var plow = 0.02425;
var phigh = 1 - plow;
if ( p < plow ) {
var q = Math.sqrt(-2*Math.log(p));
return (((((c[0]*q+c[1])*q+c[2])*q+c[3])*q+c[4])*q+c[5]) /
((((d[0]*q+d[1])*q+d[2])*q+d[3])*q+1);
}
if ( phigh < p ) {
var q = Math.sqrt(-2*Math.log(1-p));
return -(((((c[0]*q+c[1])*q+c[2])*q+c[3])*q+c[4])*q+c[5]) /
((((d[0]*q+d[1])*q+d[2])*q+d[3])*q+1);
}
var q = p - 0.5;
var r = q*q;
return (((((a[0]*r+a[1])*r+a[2])*r+a[3])*r+a[4])*r+a[5])*q /
(((((b[0]*r+b[1])*r+b[2])*r+b[3])*r+b[4])*r+1);
}
totalscore5 = .85
totalscore6 = .225
totalscore7 = .975
totalscore8 = .125
var p = totalscore5
var probit1 = NORMSINV(p)
var p = totalscore6
var probit2 = NORMSINV(p)
var Dprime1 = probit1-probit2
var p = totalscore8
var probit3 = NORMSINV(p)
var p = totalscore7
var probit4 = NORMSINV(p)
var Dprime2 = probit3-probit4
Have also tried this by declaring the variables first: let's me lose the var prefix (var p = becomes p =).
Code:
var a;
var b;
var c;
var d;
var plow;
var phigh;
var p;
var q;
var r;
var probit1;
var probit2;
var probit3;
var probit4;
var Dprime1;
var Dprime2;
function NORMSINV(p)
{
a = new Array(-3.969683028665376e+01, 2.209460984245205e+02,
-2.759285104469687e+02, 1.383577518672690e+02,
-3.066479806614716e+01, 2.506628277459239e+00);
b = new Array(-5.447609879822406e+01, 1.615858368580409e+02,
-1.556989798598866e+02, 6.680131188771972e+01,
-1.328068155288572e+01 );
c = new Array(-7.784894002430293e-03, -3.223964580411365e-01,
-2.400758277161838e+00, -2.549732539343734e+00,
4.374664141464968e+00, 2.938163982698783e+00);
d = new Array (7.784695709041462e-03, 3.224671290700398e-01,
2.445134137142996e+00, 3.754408661907416e+00);
plow = 0.02425;
phigh = 1 - plow;
if ( p < plow ) {
q = Math.sqrt(-2*Math.log(p));
return (((((c[0]*q+c[1])*q+c[2])*q+c[3])*q+c[4])*q+c[5]) /
((((d[0]*q+d[1])*q+d[2])*q+d[3])*q+1);
}
if ( phigh < p ) {
q = Math.sqrt(-2*Math.log(1-p));
return -(((((c[0]*q+c[1])*q+c[2])*q+c[3])*q+c[4])*q+c[5]) /
((((d[0]*q+d[1])*q+d[2])*q+d[3])*q+1);
}
q = p - 0.5;
r = q*q;
return (((((a[0]*r+a[1])*r+a[2])*r+a[3])*r+a[4])*r+a[5])*q /
(((((b[0]*r+b[1])*r+b[2])*r+b[3])*r+b[4])*r+1);
}
//totalscore5 = .85
//totalscore6 = .225
//totalscore7 = .975
//totalscore8 = .125
p = totalscore5
probit1 = NORMSINV(p)
p = totalscore6
probit2 = NORMSINV(p)
Dprime1 = probit1-probit2
p = totalscore8
probit3 = NORMSINV(p)
p = totalscore7
probit4 = NORMSINV(p)
Still didn't work. Can't get Dprime1 and Dprime2 as results which need to display in textboxes.
Any help appreciated.