This could be a quick one.
I have not been able to find a function for the mathematical "error function" or the "inverse error function" in R. I have not seen a package either.
I am aware I can script this but I thought someone must have made a package for its various approximations by now. Could be poor Googling due to generic terms "error function" ...
The property erf (−z) = −erf z means that the error function is an odd function.
An error function is defined by the integral. (1) and it occurs frequently in engineering problems; e.g., in heat conduction problems. The error function represents the area under the Gaussian function from t = 0 to t = x, so that erf ∞ = 1.
These are very closely related to pnorm()
and qnorm()
: see the last 4 lines of the example code in ?pnorm
:
## if you want the so-called 'error function'
erf <- function(x) 2 * pnorm(x * sqrt(2)) - 1
## (see Abramowitz and Stegun 29.2.29)
## and the so-called 'complementary error function'
erfc <- function(x) 2 * pnorm(x * sqrt(2), lower = FALSE)
## and the inverses
erfinv <- function (x) qnorm((1 + x)/2)/sqrt(2)
erfcinv <- function (x) qnorm(x/2, lower = FALSE)/sqrt(2)
If you want to use complex-valued arguments, you need erfz
from the pracma
package (as commented above by @eipi10). Otherwise, it's not clear whether there's an advantage to using the versions in pracma
(the implementations of pnorm()
and qnorm()
have been very thoroughly tested over a wide range of parameter values ...)
As far as searching goes,
library("sos")
findFn("erf")
seems to work pretty well ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With