Copy link to clipboard
Copied
Hi,
I am working on an eLearning lesson that needs to score quiz results using a statistical formula called a probit function.
There are formulas in many languages (VB, C++, etc.) for the probit function, but not in AS3. The closest I can find is in JavaScript.
Other languages:
http://home.online.no/~pjacklam/notes/invnorm/
JavaScript:
http://home.online.no/~pjacklam/notes/invnorm/impl/misra/normsinv.html
I wonder if this JavaScript version can serve as the basis for an AS3 version of the formula?
Any help would be appreciated.
Kind Regards,
i see rr is helping you in that linked thread. he's knowledgable so follow his suggestions.
Copy link to clipboard
Copied
What is the problem? From a quick look, the JS one should translate nearly perfect to AS3.
Copy link to clipboard
Copied
it needs almost no editing except to rid the duplicate variable declarations. and, at most:
function NORMSINV(p:Number):Number {
// Coefficients in rational approximations
var a:Array = new Array(-3.969683028665376e+01, 2.209460984245205e+02,
-2.759285104469687e+02, 1.383577518672690e+02,
-3.066479806614716e+01, 2.506628277459239e+00);
var b:Array = new Array(-5.447609879822406e+01, 1.615858368580409e+02,
-1.556989798598866e+02, 6.680131188771972e+01,
-1.328068155288572e+01 );
var c:Array = new Array(-7.784894002430293e-03, -3.223964580411365e-01,
-2.400758277161838e+00, -2.549732539343734e+00,
4.374664141464968e+00, 2.938163982698783e+00);
var d:Array = new Array (7.784695709041462e-03, 3.224671290700398e-01,
2.445134137142996e+00, 3.754408661907416e+00);
// Define break-points.
var plow:Number=0.02425;
var phigh:Number=1-plow;
// Rational approximation for lower region:
if (p<plow) {
var q:Number=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);
}
// Rational approximation for upper region:
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);
}
// Rational approximation for central region:
q=p-0.5;
var r:Number=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);
}
Copy link to clipboard
Copied
Hi,
Thanks for your help. I'll set up a new Fla using AS3. This was the "big" formula, but there are a few other math operation (+, -, *, /) some if/esle conditionals. I'll try to figure out how use the 4 score variables from the quiz and run the formulas to get the end results. (As mentioned, I already have done this in JS, even some AS2, in an other authoring software, but my AS3 skills are far more limited.)
Again, thanks for your help.
Kind Regards,
Copy link to clipboard
Copied
you're welcome.
as dave mentioned, you can copy just about any javascript into an as3 file, correct the few compiler errors that result from sloppy javascript coding and execute error-free actionscript.
Copy link to clipboard
Copied
Hi,
Thanks for explaining this.
My bigger challenge maybe getting all the maths to work, plugging in the variables from the other swf's SO (separate thread: http://forums.adobe.com/message/3601240#3601240).
Kind Regards,
Copy link to clipboard
Copied
i see rr is helping you in that linked thread. he's knowledgable so follow his suggestions.
Copy link to clipboard
Copied
Hi,
Thanks. Yes, getting help there and making progress.![]()
Kind Regards,
Copy link to clipboard
Copied
you're welcome.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more