Dear R people I came across a strange thing: sd(rep(0.01, 15)) #0 sd(rep(0.001, 15)) #4.489023e-19 sd(rep(0.00001, 15)) #0 sd(rep(0.00000001,15)) #1.712427e-24 sd(rep(0.01, 13)) #1.805557e-18 sd(rep(0.001, 13)) #4.513894e-19 sd(rep(0.00001, 13)) #0 sd(rep(0.00000001,13)) #0 sd(rep(5.01, 15)) #0 sd(rep(5.001, 15)) #4.489023e-19 sd(rep(5.00001, 15)) #1.838704e-15 sd(rep(5.00000001,15)) #9.19352e-16 sd(rep(5.01, 13)) #9.244454e-16 sd(rep(5.001, 13)) #9.244454e-16 sd(rep(5.00001, 13)) #1.848891e-15 sd(rep(5.00000001,13)) #0 Why gives sd sometimes zero and sometimes values close to zero and why does it depend on the value and on how many times it is repeated? Shouldn't it give always zero? Is there a way to control this? I use R Version 1.8.1 under UNIX. Thanks for any suggestions!! Andreas
Hello,> -----Original Message----- > From: Andreas Pauling [SMTP:pauling at giub.unibe.ch] > Sent: Monday, March 29, 2004 4:02 PM > To: r-help at stat.math.ethz.ch > Subject: [R] strange thing with sd > > > Shouldn't it give always zero? >I was running your example code, and I always had the result zero (see below). Best, Roland > sd(rep(0.01, 15)) #0 [1] 0 > sd(rep(0.001, 15)) #4.489023e-19 [1] 0 > sd(rep(0.00001, 15)) #0 [1] 0 > sd(rep(0.00000001,15)) #1.712427e-24 [1] 0 > > sd(rep(0.01, 13)) #1.805557e-18 [1] 0 > sd(rep(0.001, 13)) #4.513894e-19 [1] 0 > sd(rep(0.00001, 13)) #0 [1] 0 > sd(rep(0.00000001,13)) #0 [1] 0 > > sd(rep(5.01, 15)) #0 [1] 0 > sd(rep(5.001, 15)) #4.489023e-19 [1] 0 > sd(rep(5.00001, 15)) #1.838704e-15 [1] 0 > sd(rep(5.00000001,15)) #9.19352e-16 [1] 0 > > sd(rep(5.01, 13)) #9.244454e-16 [1] 0 > sd(rep(5.001, 13)) #9.244454e-16 [1] 0 > sd(rep(5.00001, 13)) #1.848891e-15 [1] 0 > sd(rep(5.00000001,13)) #0 [1] 0 > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 1 minor 8.1 year 2003 month 11 day 21 language R > +++++ This mail has been sent through the MPI for Demographic Rese...{{dropped}}
I tried your sample code, and a few other variations, and got 0 for all of them, running R 1.8.1 on a Windows machine Peter Peter L. Flom, PhD Assistant Director, Statistics and Data Analysis Core Center for Drug Use and HIV Research National Development and Research Institutes 71 W. 23rd St www.peterflom.com New York, NY 10010 (212) 845-4485 (voice) (917) 438-0894 (fax)>>> Andreas Pauling <pauling at giub.unibe.ch> 3/29/2004 9:01:40 AM >>>Dear R people I came across a strange thing: sd(rep(0.01, 15)) #0 sd(rep(0.001, 15)) #4.489023e-19 sd(rep(0.00001, 15)) #0 sd(rep(0.00000001,15)) #1.712427e-24 sd(rep(0.01, 13)) #1.805557e-18 sd(rep(0.001, 13)) #4.513894e-19 sd(rep(0.00001, 13)) #0 sd(rep(0.00000001,13)) #0 sd(rep(5.01, 15)) #0 sd(rep(5.001, 15)) #4.489023e-19 sd(rep(5.00001, 15)) #1.838704e-15 sd(rep(5.00000001,15)) #9.19352e-16 sd(rep(5.01, 13)) #9.244454e-16 sd(rep(5.001, 13)) #9.244454e-16 sd(rep(5.00001, 13)) #1.848891e-15 sd(rep(5.00000001,13)) #0 Why gives sd sometimes zero and sometimes values close to zero and why does it depend on the value and on how many times it is repeated? Shouldn't it give always zero? Is there a way to control this? I use R Version 1.8.1 under UNIX. Thanks for any suggestions!! Andreas ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Andreas Pauling wrote:> Dear R people > > I came across a strange thing: > > > sd(rep(0.01, 15)) #0 > sd(rep(0.001, 15)) #4.489023e-19 > sd(rep(0.00001, 15)) #0 > sd(rep(0.00000001,15)) #1.712427e-24 > > sd(rep(0.01, 13)) #1.805557e-18 > sd(rep(0.001, 13)) #4.513894e-19 > sd(rep(0.00001, 13)) #0 > sd(rep(0.00000001,13)) #0 > > sd(rep(5.01, 15)) #0 > sd(rep(5.001, 15)) #4.489023e-19 > sd(rep(5.00001, 15)) #1.838704e-15 > sd(rep(5.00000001,15)) #9.19352e-16 > > sd(rep(5.01, 13)) #9.244454e-16 > sd(rep(5.001, 13)) #9.244454e-16 > sd(rep(5.00001, 13)) #1.848891e-15 > sd(rep(5.00000001,13)) #0 > > Why gives sd sometimes zero and sometimes values close to zero > and why does it depend on the value and on how many times it is > repeated? > Shouldn't it give always zero? > Is there a way to control this? > > I use R Version 1.8.1 under UNIX. > > Thanks for any suggestions!! > > Andreas >I think this is due to expected inaccuracy of numerical floating point representation (and also happens for me under WinNT 4.0, R-1.9.0 beta). And for the largest value you have listed all.equal(1.848891e-15, 0) is still TRUE. Uwe Ligges
Just so you don't feel that you are alone.... I get the same response as you use R1.8.0 on an XP operating system. Alex -----Original Message----- From: Andreas Pauling [mailto:pauling at giub.unibe.ch] Sent: March 29, 2004 10:02 AM To: r-help at stat.math.ethz.ch Subject: [R] strange thing with sd Dear R people I came across a strange thing: sd(rep(0.01, 15)) #0 sd(rep(0.001, 15)) #4.489023e-19 sd(rep(0.00001, 15)) #0 sd(rep(0.00000001,15)) #1.712427e-24 sd(rep(0.01, 13)) #1.805557e-18 sd(rep(0.001, 13)) #4.513894e-19 sd(rep(0.00001, 13)) #0 sd(rep(0.00000001,13)) #0 sd(rep(5.01, 15)) #0 sd(rep(5.001, 15)) #4.489023e-19 sd(rep(5.00001, 15)) #1.838704e-15 sd(rep(5.00000001,15)) #9.19352e-16 sd(rep(5.01, 13)) #9.244454e-16 sd(rep(5.001, 13)) #9.244454e-16 sd(rep(5.00001, 13)) #1.848891e-15 sd(rep(5.00000001,13)) #0 Why gives sd sometimes zero and sometimes values close to zero and why does it depend on the value and on how many times it is repeated? Shouldn't it give always zero? Is there a way to control this? I use R Version 1.8.1 under UNIX. Thanks for any suggestions!! Andreas ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html