From Jerry.Lewis at biogenidec.com  Mon Nov 10 06:00:04 2008
From: Jerry.Lewis at biogenidec.com (Jerry.Lewis at biogenidec.com)
Date: Mon, 10 Nov 2008 06:00:04 +0100 (CET)
Subject: [Rd] erf calculation (PR#13271)
Message-ID: <20081110050004.28654282EF48@mail.pubhealth.ku.dk>

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.



[Rd] erf calculation (PR#13271)
Jerry.Lewis at biogenidec.com