Re: [R] acos(0.5) == pi/3 FALSE
On Tue, 19 Sep 2006, Johannes H?sing wrote: Peter Dalgaard: Ben Bolker [EMAIL PROTECTED] writes: 1. compose your response I've always wondered why step 1. - often the time-consuming bit - is not listed last. The advice applies to the situation when answering immediately would be your knee-jerk reaction. It is assumed that actually composing and sending the mail would take very little time and thought, whereas coming around to answering it after runif(1)*4 hours would take considerably more time, even when mulitiplied with the probability that you are still the first one. Looking at the submission times of questions and answers in this particular case, though, I would be upset if the helpful guys actually used this algorithm. Most of the answers were submitted after 3.5 to 4 h time, thus revealing a possible flaw of the random number generator underlying runif(). Johannes, Turn on 'full-headers' in your email reader. Most of the replies were submitted within 20 minutes of the posting of the original query by the list-serv (to me and I assume to others) and several that said essentially the same thing were posted within the first 10 minutes, I recall. The list-serv held the initial email for a couple of hours before passing it on. The replies are processed more rapidly, being held at most a few minutes each. Given the initial hold placed on that email, runif(1)*4 hours would have increased the overall response time (from time of initial posting to time of first response) by less than 25% (with high probability). And would have saved several respondents from having to type up their replies. In this case even runif(1)*20 minutes would likely have cut the response traffic to one or two and would have increased the overall response time by less than 10 minutes. Chuck __ R-help@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 and provide commented, minimal, self-contained, reproducible code. Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:[EMAIL PROTECTED] UC San Diego http://biostat.ucsd.edu/~cberry/ La Jolla, San Diego 92093-0717 __ R-help@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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] acos(0.5) == pi/3 FALSE
Peter Dalgaard: Ben Bolker [EMAIL PROTECTED] writes: 1. compose your response I've always wondered why step 1. - often the time-consuming bit - is not listed last. The advice applies to the situation when answering immediately would be your knee-jerk reaction. It is assumed that actually composing and sending the mail would take very little time and thought, whereas coming around to answering it after runif(1)*4 hours would take considerably more time, even when mulitiplied with the probability that you are still the first one. Looking at the submission times of questions and answers in this particular case, though, I would be upset if the helpful guys actually used this algorithm. Most of the answers were submitted after 3.5 to 4 h time, thus revealing a possible flaw of the random number generator underlying runif(). __ R-help@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 and provide commented, minimal, self-contained, reproducible code.
[R] acos(0.5) == pi/3 FALSE
Hello, I don't know if the result of acos(0.5) == pi/3 is a bug or not. It looks strange to me. Inaki Murillo __ R-help@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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] acos(0.5) == pi/3 FALSE
On Mon, 2006-09-18 at 19:31 +0200, Iñaki Murillo Arcos wrote: Hello, I don't know if the result of acos(0.5) == pi/3 is a bug or not. It looks strange to me. Inaki Murillo Seems reasonable to me: acos(0.5) == pi/3 [1] FALSE print(acos(0.5), 20) [1] 1.0471975511965978534 print(pi/3, 20) [1] 1.0471975511965976313 See R FAQ 7.31 Why doesn't R think these numbers are equal? HTH, Marc Schwartz __ R-help@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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] acos(0.5) == pi/3 FALSE
If you had looked at help(==) you would have seen the following: For numerical and complex values, remember == and != do not allow for the finite representation of fractions, nor for rounding error. Using all.equal with identical is almost always preferable. Then if you had tried all.equal(acos(0.5),pi/3) [1] TRUE On 18/09/06, Iñaki Murillo Arcos [EMAIL PROTECTED] wrote: Hello, I don't know if the result of acos(0.5) == pi/3 is a bug or not. It looks strange to me. Inaki Murillo __ R-help@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 and provide commented, minimal, self-contained, reproducible code. -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP __ R-help@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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] acos(0.5) == pi/3 FALSE
How close do you think it should be, given finite resolution with digital computing? acos(0.5) - pi/3 [1] 2.220446e-16 Charles Annis, P.E. [EMAIL PROTECTED] phone: 561-352-9699 eFax: 614-455-3265 http://www.StatisticalEngineering.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Iñaki Murillo Arcos Sent: Monday, September 18, 2006 1:32 PM To: r-help@stat.math.ethz.ch Subject: [R] acos(0.5) == pi/3 FALSE Hello, I don't know if the result of acos(0.5) == pi/3 is a bug or not. It looks strange to me. Inaki Murillo __ R-help@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 and provide commented, minimal, self-contained, reproducible code. __ R-help@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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] acos(0.5) == pi/3 FALSE
Iñaki Murillo Arcos [EMAIL PROTECTED] writes: Hello, I don't know if the result of acos(0.5) == pi/3 is a bug or not. It looks strange to me. Have a look in the R FAQ: acos(0.5) - pi/3 [1] 2.220446e-16 -- 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 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] acos(0.5) == pi/3 FALSE
On 9/18/06, Iñaki Murillo Arcos [EMAIL PROTECTED] wrote: Hello, I don't know if the result of acos(0.5) == pi/3 is a bug or not. It looks strange to me. However, all.equal(acos(0.5), pi/3) [1] TRUE so you may want to check the FAQ entry on comparisons involving floating point numbers. __ R-help@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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] acos(0.5) == pi/3 FALSE
On Mon, 18 Sep 2006, [iso-8859-1] I?aki Murillo Arcos wrote: Hello, I don't know if the result of acos(0.5) == pi/3 is a bug or not. It looks strange to me. Real numbers are strange. Would the result of: acos(0.5) - pi/3 close enough to zero for you? Try help('Comparison') , ?'==' for an explanation, or 'abs(acos(0.5) - pi/3) 1e-9' for a solution. Dave -- Dr. David Forrest [EMAIL PROTECTED](804)684-7900w [EMAIL PROTECTED] (804)642-0662h http://maplepark.com/~drf5n/ __ R-help@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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] acos(0.5) == pi/3 FALSE
Iñaki Murillo Arcos said the following on 9/18/2006 12:31 PM: Hello, I don't know if the result of acos(0.5) == pi/3 is a bug or not. It looks strange to me. Inaki Murillo __ R-help@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 and provide commented, minimal, self-contained, reproducible code. This is a FAQ: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f acos(.5) [1] 1.047198 pi/3 [1] 1.047198 acos(0.5) == pi/3 [1] FALSE all.equal(acos(0.5), pi/3) [1] TRUE --sundar __ R-help@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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] acos(0.5) == pi/3 FALSE
On 18-Sep-06 Iñaki Murillo Arcos wrote: Hello, I don't know if the result of acos(0.5) == pi/3 is a bug or not. It looks strange to me. Inaki Murillo It is not a bug, but a feature, in that acos(0.5) and pi/3 are not computed in the same way, so (because of the small inaccuracies inevitable in their finite representations) they are indeed not equal; and this is what R is telling you. acos(0.5) - pi/3 [1] 2.220446e-16 The difference, as you can see is very small. However, if for some reason (e.g. in the logic of a programming branch which depends on such a comparison) then you could make it work by computing them in the same way: pi-3*acos(0.5) acos(0.5) - pi/3 [1] 0 I.e. redefine pi in R so that its computation is compatible with that of acos(0.5) (but this pi is only in the current environment). However, the usual way of comparing two numbers which should theoretically be equal, but might differ slightly when computed in R, is to use all.equal(x, y) See ?all.equal. Also see ?identical. all.equal(acos(0.5),pi/3) [1] TRUE (Here I'm using R's default value of pi, not the value I defined above). all.equal(x,y) tests whether x and y differ by more than a tolerance which by default is .Machine$double.eps but which can be set to something else if you wish. Best wishes, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 18-Sep-06 Time: 23:05:01 -- XFMail -- __ R-help@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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] acos(0.5) == pi/3 FALSE
Time for folks to re-read the posting guide? * When responding to a very simple question, use the following algorithm: 1. compose your response 2. type 4*runif(1) at the R prompt, and wait this many hours 3. check for new posts to R-help; if no similar suggestion, post your response (This is partly in jest, but if you know immediately why it is suggested, you probably should use it! Also, it's a nice idea to replace 4 by the number of years you have been using R or S-plus.) [inspired by Romain Francois's similar post back in March] cheers Ben Bolker __ R-help@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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] acos(0.5) == pi/3 FALSE
Ben Bolker [EMAIL PROTECTED] writes: Time for folks to re-read the posting guide? * When responding to a very simple question, use the following algorithm: 1. compose your response 2. type 4*runif(1) at the R prompt, and wait this many hours 3. check for new posts to R-help; if no similar suggestion, post your response (This is partly in jest, but if you know immediately why it is suggested, you probably should use it! Also, it's a nice idea to replace 4 by the number of years you have been using R or S-plus.) I've always wondered why step 1. - often the time-consuming bit - is not listed last. -- 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 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@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 and provide commented, minimal, self-contained, reproducible code.