[R] accuracy of test cases

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Apr 29 12:51:10 CEST 2005


Robin Hankin wrote:

> Hi
> 
> I have several methods for evaluating a function.  The methods are 
> algebraically
> identical but use different numerical techniques. The different methods 
> work
> better (converge faster, etc) in different parts of the function's domain.
> 
> I am compiling a test suite for a package, and would like to verify that 
> the
> different methods return approximately identical results.
> 
> Toy example follows:
> 
> 
> R> f1 <- function(x){ (x-1)*(x+1)}
> R> f2 <- function(x){x^2-1}
> R> x <- pi+100i
> R> abs(f1(x) - f2(x))
> [1] 9.298027e-12
> R> stopifnot(abs(f1(x)-f2(x)) < 1e-11)
> 
> Observe that f1() should be identically equal to f2(); any differences 
> are due to
> rounding errors (needless to say, the real examples are more complex, with
> larger errors).
> 
> My question is, I am unhappy about the numerical value of the tolerance 
> used in the last line.
> The tolerance should be as small as possible, but If I make it too 
> small, the test may fail
> when executed on a machine with different architecture from mine.
> 
> How do I deal with this?

See ?all.equal

Uwe Ligges


> 
> 
> -- 
> Robin Hankin
> Uncertainty Analyst
> Southampton Oceanography Centre
> European Way, Southampton SO14 3ZH, UK
>  tel  023-8059-7743
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html




More information about the R-help mailing list