I am converting some matlab code into R that use inverse of the complementary error function, erfcinv and did not find an equivalent in R, is there such a function in some contributed modules? Thanks.
sun wrote:> I am converting some matlab code into R that use inverse of the > complementary error function, erfcinv and did not find an equivalent in > R, is there such a function in some contributed modules? > >Basically, it is qnorm() with suitable scaling. The help page for Normal has the construction for erfc() from pnorm() so just solve erfc(x) = y for x. -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Peter Dalgaard wrote:> sun wrote: >> I am converting some matlab code into R that use inverse of the >> complementary error function, erfcinv and did not find an equivalent in >> R, is there such a function in some contributed modules? >> >> > Basically, it is qnorm() with suitable scaling. The help page for Normal > has the construction for erfc() from pnorm() so just solve erfc(x) = y > for x. >Thanks for your quick answer and useful information! But please forgive my ignorance, I do not really know how to solve this inverse function actually. for example, >erfc <- function(x) 2 * pnorm(x * sqrt(2), lower = FALSE) > erfc(0.3) [1] 0.6713732 How do I find 0.3 given 0.6713732? Thanks!
At a guess ...> erfc <- function(x) 2 * pnorm(x * sqrt(2), lower = FALSE) > erfcinv <- function(x) qnorm(x/2, lower = FALSE)/sqrt(2) > erfc(0.3)[1] 0.6713732> erfcinv(erfc(0.3))[1] 0.3>It may not hurt to include these wrappers in R for matlab refugees. They seem to be coming thick and fast these days. Bill Venables CSIRO Laboratories PO Box 120, Cleveland, 4163 AUSTRALIA Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely necessary): +61 7 3826 7304 Mobile: +61 4 8819 4402 Home Phone: +61 7 3286 7700 mailto:Bill.Venables at csiro.au http://www.cmis.csiro.au/bill.venables/ -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of sun Sent: Monday, 14 April 2008 8:50 AM To: r-help at stat.math.ethz.ch Subject: Re: [R] R equivalent of erfcinv in matlab Peter Dalgaard wrote:> sun wrote: >> I am converting some matlab code into R that use inverse of the >> complementary error function, erfcinv and did not find an equivalentin>> R, is there such a function in some contributed modules? >> >> > Basically, it is qnorm() with suitable scaling. The help page forNormal> has the construction for erfc() from pnorm() so just solve erfc(x) y > for x. >Thanks for your quick answer and useful information! But please forgive my ignorance, I do not really know how to solve this inverse function actually. for example, >erfc <- function(x) 2 * pnorm(x * sqrt(2), lower = FALSE) > erfc(0.3) [1] 0.6713732 How do I find 0.3 given 0.6713732? Thanks! ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Bill.Venables at csiro.au wrote:> At a guess ... > >> erfc <- function(x) 2 * pnorm(x * sqrt(2), lower = FALSE) >> erfcinv <- function(x) qnorm(x/2, lower = FALSE)/sqrt(2) >> erfc(0.3) > [1] 0.6713732 >> erfcinv(erfc(0.3)) > [1] 0.3 > > It may not hurt to include these wrappers in R for matlab refugees. > They seem to be coming thick and fast these days. > > > Bill Venables > CSIRO Laboratories > PO Box 120, Cleveland, 4163 > AUSTRALIA > Office Phone (email preferred): +61 7 3826 7251 > Fax (if absolutely necessary): +61 7 3826 7304 > Mobile: +61 4 8819 4402 > Home Phone: +61 7 3286 7700 > mailto:Bill.Venables at csiro.au > http://www.cmis.csiro.au/bill.venables/Thanks very much indeed. This solved my problem. I think it will be very helpful to have these wrapper functions at least in some extra packages for the ease of people migrating.