I have prices that I am finding difficult to compare with ==, > and >, due to precision. For example: the numbers should match, with '==', but they differ in the magnitude of 1e-14 due to bunch of calculations that I run on them. Programming with java, I am used to implementing a function that compares the difference between the numbers to a pre determined precision factor. This could be very slow when I have two matrices of numbers that I could otherwise compare with a simple '==', '>' or '<' in R. What is teh best solution for this problem? Can I control the precision of ==, > and < without having to reimplement the operations in a slow way?
precision problem
8 messages · Omar Lakkis, Uwe Ligges, Roger Bivand +2 more
Omar Lakkis wrote:
I have prices that I am finding difficult to compare with ==, > and >, due to precision. For example: the numbers should match, with '==', but they differ in the magnitude of 1e-14 due to bunch of calculations that I run on them. Programming with java, I am used to implementing a function that compares the difference between the numbers to a pre determined precision factor. This could be very slow when I have two matrices of numbers that I could otherwise compare with a simple '==', '>' or '<' in R. What is teh best solution for this problem? Can I control the precision of ==, > and < without having to reimplement the operations in a slow way?
The R FAQ "Why doesn't R think these numbers are equal?" points you to ?all.equal Uwe Ligges
______________________________________________ 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
On Wed, 25 May 2005, Omar Lakkis wrote:
?all.equal, I think
I have prices that I am finding difficult to compare with ==, > and >, due to precision. For example: the numbers should match, with '==', but they differ in the magnitude of 1e-14 due to bunch of calculations that I run on them. Programming with java, I am used to implementing a function that compares the difference between the numbers to a pre determined precision factor. This could be very slow when I have two matrices of numbers that I could otherwise compare with a simple '==', '>' or '<' in R. What is teh best solution for this problem? Can I control the precision of ==, > and < without having to reimplement the operations in a slow way?
______________________________________________ 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
Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no
Dear Omar, Perhaps I'm missing something, but why not just subtract one matrix from the other and test the difference in relation to the precision that you require for the comparison? E.g., to test near equality, something like, abs(A - B) < 1e-13. I hope this helps, John -------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.mcmaster.ca/jfox --------------------------------
-----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Omar Lakkis Sent: Wednesday, May 25, 2005 9:09 AM To: r-help at stat.math.ethz.ch Subject: [R] precision problem I have prices that I am finding difficult to compare with ==,
and >, due to precision. For example: the numbers should
match, with '==', but they differ in the magnitude of 1e-14 due to bunch of calculations that I run on them. Programming with java, I am used to implementing a function that compares the difference between the numbers to a pre determined precision factor. This could be very slow when I have two matrices of numbers that I could otherwise compare with a simple '==', '>' or '<' in R. What is teh best solution for this problem? Can I control the precision of ==, > and < without having to reimplement the operations in a slow way?
______________________________________________ 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
Thank you all. all.equal is very helpful since I am also interested in finding the mismatched prices.
On 5/25/05, John Fox <jfox at mcmaster.ca> wrote:
Dear Omar, Perhaps I'm missing something, but why not just subtract one matrix from the other and test the difference in relation to the precision that you require for the comparison? E.g., to test near equality, something like, abs(A - B) < 1e-13. I hope this helps, John -------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.mcmaster.ca/jfox --------------------------------
-----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Omar Lakkis Sent: Wednesday, May 25, 2005 9:09 AM To: r-help at stat.math.ethz.ch Subject: [R] precision problem I have prices that I am finding difficult to compare with ==,
and >, due to precision. For example: the numbers should
match, with '==', but they differ in the magnitude of 1e-14 due to bunch of calculations that I run on them. Programming with java, I am used to implementing a function that compares the difference between the numbers to a pre determined precision factor. This could be very slow when I have two matrices of numbers that I could otherwise compare with a simple '==', '>' or '<' in R. What is teh best solution for this problem? Can I control the precision of ==, > and < without having to reimplement the operations in a slow way?
______________________________________________ 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
all.equal is helpful when I am comparing equality of two matrices. However, when I am comparing two individual number with > or < is my best bet doing if( abs(x - y) < tolerence) or is there a function like all.equal that has the same default tolerence?
On 5/25/05, Omar Lakkis <uofiowa at gmail.com> wrote:
Thank you all. all.equal is very helpful since I am also interested in finding the mismatched prices. On 5/25/05, John Fox <jfox at mcmaster.ca> wrote:
Dear Omar, Perhaps I'm missing something, but why not just subtract one matrix from the other and test the difference in relation to the precision that you require for the comparison? E.g., to test near equality, something like, abs(A - B) < 1e-13. I hope this helps, John -------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.mcmaster.ca/jfox --------------------------------
-----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Omar Lakkis Sent: Wednesday, May 25, 2005 9:09 AM To: r-help at stat.math.ethz.ch Subject: [R] precision problem I have prices that I am finding difficult to compare with ==,
and >, due to precision. For example: the numbers should
match, with '==', but they differ in the magnitude of 1e-14 due to bunch of calculations that I run on them. Programming with java, I am used to implementing a function that compares the difference between the numbers to a pre determined precision factor. This could be very slow when I have two matrices of numbers that I could otherwise compare with a simple '==', '>' or '<' in R. What is teh best solution for this problem? Can I control the precision of ==, > and < without having to reimplement the operations in a slow way?
______________________________________________ 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
Omar Lakkis wrote:
I have prices that I am finding difficult to compare with ==, > and >, due to precision. For example: the numbers should match, with '==', but they differ in the magnitude of 1e-14 due to bunch of calculations that I run on them. Programming with java, I am used to implementing a function that compares the difference between the numbers to a pre determined precision factor. This could be very slow when I have two matrices of numbers that I could otherwise compare with a simple '==', '>' or '<' in R. What is teh best solution for this problem? Can I control the precision of ==, > and < without having to reimplement the operations in a slow way?
The somewhat misleadingly named "all.equal()" function does what you want for ==. For the inequalities, you may want to add some constant to one side, e.g. x > y-.Machine$double.eps ^ 0.5 instead of x > y. Duncan Murdoch
Dear Omar, It wasn't clear to me from your original question that you wanted to test that *all* the corresponding entries were equal, as opposed to each individual entry. In any event, I don't think that you'll find a similar function for testing inequality, so you can do as you suggest, but of course without abs(). Regards, John -------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.mcmaster.ca/jfox --------------------------------
-----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Omar Lakkis Sent: Wednesday, May 25, 2005 10:08 AM To: r-help at stat.math.ethz.ch Subject: Re: [R] precision problem all.equal is helpful when I am comparing equality of two matrices. However, when I am comparing two individual number with > or < is my best bet doing if( abs(x - y) < tolerence) or is there a function like all.equal that has the same default tolerence? On 5/25/05, Omar Lakkis <uofiowa at gmail.com> wrote:
Thank you all. all.equal is very helpful since I am also interested in finding the mismatched prices. On 5/25/05, John Fox <jfox at mcmaster.ca> wrote:
Dear Omar, Perhaps I'm missing something, but why not just subtract
one matrix
from the other and test the difference in relation to the
precision
that you require for the comparison? E.g., to test near equality, something like, abs(A - B) < 1e-13. I hope this helps, John -------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.mcmaster.ca/jfox --------------------------------
-----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of
Omar Lakkis
Sent: Wednesday, May 25, 2005 9:09 AM To: r-help at stat.math.ethz.ch Subject: [R] precision problem I have prices that I am finding difficult to compare with ==,
and >, due to precision. For example: the numbers should
match, with '==', but they differ in the magnitude of
1e-14 due to
bunch of calculations that I run on them. Programming
with java, I
am used to implementing a function that compares the difference between the numbers to a pre determined precision factor. This could be very slow when I have two matrices of numbers that I could otherwise compare with a simple '==', '>' or '<' in R. What is teh best solution for this problem? Can I control the precision of ==, > and < without having to reimplement the operations in a slow way?
______________________________________________ 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
______________________________________________ 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