[Rd] erf calculation (PR#13271)
Jerry.Lewis at biogenidec.com
Jerry.Lewis at biogenidec.com
Mon Nov 10 06:00:04 CET 2008
Full_Name: Jerry W. Lewis
Version: 2.8.0
OS: Windows XP Professional
Submission from: (NULL) (71.184.139.210)
On p.1202 of the Reference manual, calculating erf(x) is given as an example
using the code
erf <- function(x) 2 * pnorm(x * sqrt(2)) - 1
A numerically better (avoiding cancellation for x near 0) formula is
erf <- function(x){
ret <- pgamma(x^2,0.5,1)
ret[x<0] <- -ret[x<0]
ret
}
It would also be convenient if erf and erfc functions were provided in R, as
they are in S-PLUS.
More information about the R-devel
mailing list