Hello, I am trying to test the precision of R on datasets from The Statistical Reference Datasets Project http://www.itl.nist.gov/div898/strd/index.html and I don't manage to understand how R is storing its results. For example, I calculate a mean on the michelso dataset (100 values) and find:> m=mean(michel) > mV1 299.8524> print(m,digits=15)V1 299.8524> print(m,digits=22)V1 299.85239999999993 The certified value of the mean is 299.85240, so I try> print(m-299.8524)V1 -5.684342e-14> print(m-299.8524,digits=15)V1 -5.68434188608080e-14 Does it have a sens to print with more than 15 signifiant digits? Why is the difference not equal to zero? I am using R 2.0.1 under Windows XP. Regards, Anthony Landrevie --------------------------------- [[alternative HTML version deleted]]
Anthony Landrevie wrote:> Hello, > > I am trying to test the precision of R on datasets from The Statistical Reference Datasets Project http://www.itl.nist.gov/div898/strd/index.html and I don't manage to understand how R is storing its results. > > For example, I calculate a mean on the michelso dataset (100 values) and find: > > >>m=mean(michel) >>m > > V1 > 299.8524 > >>print(m,digits=15) > > V1 > 299.8524 > > >>print(m,digits=22) > > V1 > 299.85239999999993 > > > The certified value of the mean is 299.85240, so I try > > > >>print(m-299.8524) > > V1 > -5.684342e-14 > > >>print(m-299.8524,digits=15) > > V1 > -5.68434188608080e-14 > > Does it have a sens to print with more than 15 signifiant digits?Depends, e.g. you mightg want to see that the result is only -5.684342e-14 off, hence not identical() to, but all.equal() with what you expected.> Why is the difference not equal to zero?Floating point calculations on a digital computer are involved... Uwe Ligges> I am using R 2.0.1 under Windows XP. > > Regards, > > Anthony Landrevie > > > --------------------------------- > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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
Try signif(m,8) At 1:03 AM -0800 3/23/05, Anthony Landrevie wrote:>Hello, > >I am trying to test the precision of R on datasets from The >Statistical Reference Datasets Project >http://www.itl.nist.gov/div898/strd/index.html and I don't manage to >understand how R is storing its results. > >For example, I calculate a mean on the michelso dataset (100 values) and find: > >> m=mean(michel) >> m > V1 >299.8524 >> print(m,digits=15) > V1 >299.8524 > >> print(m,digits=22) > V1 >299.85239999999993 > > >The certified value of the mean is 299.85240, so I try > > >> print(m-299.8524) > V1 >-5.684342e-14 > >> print(m-299.8524,digits=15) > V1 >-5.68434188608080e-14 > >Does it have a sens to print with more than 15 signifiant digits? >Why is the difference not equal to zero? > >I am using R 2.0.1 under Windows XP. > >Regards, > >Anthony Landrevie > > >--------------------------------- > > > [[alternative HTML version deleted]] > >______________________________________________ >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-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA