W
Wan
How can I find an inverse error function on Excel, using functions that are
available?
available?
are
available?
....Dana DeLouis said:Function InverseErf(n)
If n < 0 Or n >= 1 Then Exit Function
Dim g As Double
Dim j As Long
g = 0
For j = 1 To 15
g = g + (Exp(g * g) * SqrPi * (n - Erf(g))) / 2
Next j
InverseErf = g
End Function
Function Erf(z)
Dim k As Long
Dim F As Double '(F)actorial
Dim n As Double
Dim d As Double
Dim Ans As Double
If z = 0 Then Exit Function
F = 1
For k = 0 To 25
n = (-1) ^ k * z ^ (2 * k + 1)
d = F * (2 * k + 1)
Ans = Ans + n / d
F = F * (k + 1)
Next k
Erf = Ans * 2 / SqrPi
End Function
..>'InverseErf [0.1]
..>'0.0888559904942577
..>'InverseErf [0.5]
..>'0.4769362762044698
..>'InverseErf [0.9]
..>'1.163087153676674
=NORMSINV((y+1)/2)/SQRT(2)
.. since ERF(x) = 2*NORMSDIST(x*SQRT(2))-1, then why notHarlan Grove said:
use NORMSINV? That is, why not estimate InverseERF(y) as
=NORMSINV((y+1)/2)/SQRT(2)
..>'InverseErf [0.1]
..>'0.0888559904942577
=NORMSINV((0.1+1)/2)/SQRT(2) -> 0.0888559904942577
Harlan Grove said:Someone's gotta ask, since ERF(x) = 2*NORMSDIST(x*SQRT(2))-1, then why not
use NORMSINV? That is, why not estimate InverseERF(y) as
=NORMSINV((y+1)/2)/SQRT(2)
..>'InverseErf [0.1]
..>'0.0888559904942577
=NORMSINV((0.1+1)/2)/SQRT(2) -> 0.0888559904942577
..>'InverseErf [0.5]
..>'0.4769362762044698
=NORMSINV((0.5+1)/2)/SQRT(2) -> 0.47693627620447
..>'InverseErf [0.9]
..>'1.163087153676674
=NORMSINV((0.9+1)/2)/SQRT(2) -> 1.16308715367667
Jerry W. Lewis said:You could avoid loss of precision for small erf values by using
SQRT(inv_gamma(erf_value,0.5,1))
where inv_gamma is the highly accurate equivalent of GAMMAINV from Ian
Smith's VBA library
http://members.aol.com/iandjmsmith/Examples.xls
Unfortunately, the native GAMMAINV function is very crude for the purpose.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.