Thanks again Karen. I'll have a good look at this function later but use what I have in the meantime.
Regards Paul On 3/11/06, Karen <[EMAIL PROTECTED]> wrote: > > On Mar 10, 2006, at 3:18 AM, Paul Rehill wrote: > > > One more question. Do you have a good function for the inverse of the > > standard normal cumulative distribution? > > Function InvCumNormDist(p as Double, Mean as Double = 0.0, StdDev as > Double = 1.0) As Double > > Const a1= -3.969683028665376e+01 > Const a2= 2.209460984245205e+02 > Const a3= -2.759285104469687e+02 > Const a4= 1.383577518672690e+02 > Const a5= -3.066479806614716e+01 > Const a6= 2.506628277459239e+00 > > Const b1= -5.447609879822406e+01 > Const b2= 1.615858368580409e+02 > Const b3= -1.556989798598866e+02 > Const b4= 6.680131188771972e+01 > Const b5= -1.328068155288572e+01 > > Const c1= -7.784894002430293e-03 > Const c2= -3.223964580411365e-01 > Const c3= -2.400758277161838e+00 > Const c4= -2.549732539343734e+00 > Const c5= 4.374664141464968e+00 > Const c6= 2.938163982698783e+00 > > Const d1= 7.784695709041462e-03 > Const d2= 3.224671290700398e-01 > Const d3= 2.445134137142996e+00 > Const d4= 3.754408661907416e+00 > Const Sqrt_2Pi = 2.5066282746310 > > Const p_low = 0.02425 > Const p_high= 0.97575 > > Dim z, r as Double > if p < 0.0 or p >= 1.0 Then Return - 1 > > if p < p_low then > z = Sqrt(-2.0*Ln(p)) > z = (((((c1*z+c2)*z+c3)*z+c4)*z+c5)*z+c6) / ((((d1*z+d2)*z+d3)*z > +d4)*z+1.0) > elseif p <= p_high then > > z = p - 0.5 > r = z*z > z = (((((a1*r+a2)*r+a3)*r+a4)*r+a5)*r+a6)*z /(((((b1*r+b2)*r+b3) > *r+b4)*r+b5)*r+1.0) > else > z = Sqrt(-2.0*Ln(1.0-p)) > z = -(((((c1*z+c2)*z+c3)*z+c4)*z+c5)*z+c6) /((((d1*z+d2)*z+d3)*z > +d4)*z+1.0) > End if > > r = (CumNormalDist(z) - p) * Sqrt_2Pi * Exp(0.5 * z*z) > > z = z - ( r/(1+0.5*z*r)) > > return mean + z*StdDev > End Function > '----------------------------------------------------------------------- > ------------------- > Function CumNormalDist(Z as Double, Mean as Double = 0.0, StdDev as > Double = 1.0) As Double > Const a1 = 0.31938153 > Const a2 = -0.356563782 > Const a3 = 1.781477937 > Const a4 = -1.821255978 > Const a5 = 1.330274429 > Const Sqrt_2Pi = 2.5066282746310 > > Dim K, w As double , isNegative as boolean > > z = (z - Mean)/StdDev > if z < 0.0 then > isNegative = true > z = Abs(z) > End if > > K = 1.0 / (1.0 + 0.2316419 * z) > w= 1.0 - 1.0 /Sqrt_2Pi * Exp(-z * z / 2.0) * (a1 * K + a2 * K*K + > a3 * Pow(K, 3) + a4 * Pow(K , 4) + a5 * Pow(K, 5)) > > If isNegative Then w = 1.0 - w > > Return w > End Function > _______________________________________________ Unsubscribe or switch delivery mode: <http://www.realsoftware.com/support/listmanager/> Search the archives of this list here: <http://support.realsoftware.com/listarchives/lists.html>
