Re: [R] round giving different results on Windows and Mac
On Fri, Mar 09, 2012 at 09:34:14PM +, Ruth Ripley wrote: Dear all, I have been running some tests of my package RSiena on different platforms and trying to reconcile the results. With Mac, the commands options(digits=4) round(1.81652, digits=4) print 1.817 With Windows, the same commands print 1.816 I am not bothered which answer I get, but it would be nice if they were the same. A linux box agreed with the Mac. Hi. I obtain the same difference between Linux (1.817) and 32 bit Windows (1.816). As Duncan said, the number 1.8165 is not exactly representable and printing it to 4 significant digits may depend on the platform, since it is a middle case. Note that options(digits=4) means rounding to 4 significant digits, while round(1.81652, digits=4) is rounding to 4 digits in the fractional part. Try signif(1.81652, digits=4) to get the same type of rounding as in options(digits=4). The problem is not in round(), since x - round(1.81652, digits=4) print(x, digits=20) print(x, digits=4) yields on Linux [1] 1.8165036 [1] 1.817 and on 32 bit Windows [1] 1.8165036 [1] 1.816 The difference is not due to R, since R is responsible only for the choice of the number of printed digits and not for the digits themselves. The digits are computed by sprintf() on the given platform. So, the difference seems to be there. The command sprintf(%5.3f, 18165/1) yields on Linux [1] 1.817 and on 32 bit Windows [1] 1.816 Thank you for the example. Petr Savicky. __ R-help@r-project.org 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] round giving different results on Windows and Mac
Petr, Many thanks for this detailed explanation. It seems that the printing is going to vary because it is not done by R. I will try alternative numbers of significant digits: I had set options(digits=4) in an attempt to avoid inter-platform printing differences, without really understanding what was causing them. Ruth Original Message Subject: Re: [R] round giving different results on Windows and Mac Date: Sat, 10 Mar 2012 10:08:21 +0100 From: Petr Savicky savi...@cs.cas.cz To: r-help@r-project.org On Fri, Mar 09, 2012 at 09:34:14PM +, Ruth Ripley wrote: Dear all, I have been running some tests of my package RSiena on different platforms and trying to reconcile the results. With Mac, the commands options(digits=4) round(1.81652, digits=4) print 1.817 With Windows, the same commands print 1.816 I am not bothered which answer I get, but it would be nice if they were the same. A linux box agreed with the Mac. Hi. I obtain the same difference between Linux (1.817) and 32 bit Windows (1.816). As Duncan said, the number 1.8165 is not exactly representable and printing it to 4 significant digits may depend on the platform, since it is a middle case. Note that options(digits=4) means rounding to 4 significant digits, while round(1.81652, digits=4) is rounding to 4 digits in the fractional part. Try signif(1.81652, digits=4) to get the same type of rounding as in options(digits=4). The problem is not in round(), since x - round(1.81652, digits=4) print(x, digits=20) print(x, digits=4) yields on Linux [1] 1.8165036 [1] 1.817 and on 32 bit Windows [1] 1.8165036 [1] 1.816 The difference is not due to R, since R is responsible only for the choice of the number of printed digits and not for the digits themselves. The digits are computed by sprintf() on the given platform. So, the difference seems to be there. The command sprintf(%5.3f, 18165/1) yields on Linux [1] 1.817 and on 32 bit Windows [1] 1.816 Thank you for the example. Petr Savicky. __ R-help@r-project.org 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. -- Ruth M. Ripley, Email:r...@stats.ox.ac.uk Dept. of Statistics,http://www.stats.ox.ac.uk/~ruth/ University of Oxford, Tel: 01865 282857 1 South Parks Road, Oxford OX1 3TG, UK Fax: 01865 272595 __ R-help@r-project.org 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] round giving different results on Windows and Mac
Duncan, Thanks for your reply: given Petr's response, it seems the problem is the interpretation by the printing code, not the actual representation of the number. Given the representation, 1.817 would be correct, unless at the working accuracy it is considered to be equal to 1.8165 (as indeed I asked it to be). I will have to find a workaround, or live with two sets of test results. Ruth On 10/03/2012 00:48, Duncan Murdoch wrote: On 12-03-09 4:34 PM, Ruth Ripley wrote: Dear all, I have been running some tests of my package RSiena on different platforms and trying to reconcile the results. With Mac, the commands options(digits=4) round(1.81652, digits=4) print 1.817 The value you're printing is 1.8165, so I believe Windows gets it right using our round-to-even rule, but I'm not surprised that there are differences. The value 1.8165 isn't exactly representable, so it's somewhat random whether a system chooses to represent it slightly larger or slightly smaller. Duncan Murdoch With Windows, the same commands print 1.816 I am not bothered which answer I get, but it would be nice if they were the same. A linux box agreed with the Mac. Mac sessionInfo(): R version 2.14.2 (2012-02-29) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] RSiena_1.0.12.205 loaded via a namespace (and not attached): [1] grid_2.14.2 lattice_0.20-0 Matrix_1.0-4 tools_2.14.2 Windows (but 2.14.1patched was the same) sessionInfo(): R version 2.15.0 alpha (2012-03-08 r58640) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United Kingdom.1252 [2] LC_CTYPE=English_United Kingdom.1252 [3] LC_MONETARY=English_United Kingdom.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base Any enlightenment would be gratefully received. Ruth -- Ruth M. Ripley, Email:r...@stats.ox.ac.uk Dept. of Statistics,http://www.stats.ox.ac.uk/~ruth/ University of Oxford, Tel: 01865 282857 1 South Parks Road, Oxford OX1 3TG, UK Fax: 01865 272595 __ R-help@r-project.org 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] round giving different results on Windows and Mac
Hello Ruth: Many thanks for this detailed explanation. It seems that the printing is going to vary because it is not done by R. I will try alternative numbers of significant digits: I had set options(digits=4) in an attempt to avoid inter-platform printing differences, without really understanding what was causing them. If you round the numbers by, say, signif(x, digits=4) before printing and print with at least 4 digits precision, then the output should not depend on the printing function, but on signif(), since in this case, the printing function does not get middle cases. Function signif() can also have platform dependence, but i think, it should be rare. Send examples of platform dependencies in signif(), if you find some. Petr. __ R-help@r-project.org 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] round giving different results on Windows and Mac
Dear all, I have been running some tests of my package RSiena on different platforms and trying to reconcile the results. With Mac, the commands options(digits=4) round(1.81652, digits=4) print 1.817 With Windows, the same commands print 1.816 I am not bothered which answer I get, but it would be nice if they were the same. A linux box agreed with the Mac. Mac sessionInfo(): R version 2.14.2 (2012-02-29) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] RSiena_1.0.12.205 loaded via a namespace (and not attached): [1] grid_2.14.2lattice_0.20-0 Matrix_1.0-4 tools_2.14.2 Windows (but 2.14.1patched was the same) sessionInfo(): R version 2.15.0 alpha (2012-03-08 r58640) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United Kingdom.1252 [2] LC_CTYPE=English_United Kingdom.1252 [3] LC_MONETARY=English_United Kingdom.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base Any enlightenment would be gratefully received. Ruth -- Ruth M. Ripley, Email:r...@stats.ox.ac.uk Dept. of Statistics,http://www.stats.ox.ac.uk/~ruth/ University of Oxford, Tel: 01865 282857 1 South Parks Road, Oxford OX1 3TG, UK Fax: 01865 272595 __ R-help@r-project.org 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] round giving different results on Windows and Mac
On 12-03-09 4:34 PM, Ruth Ripley wrote: Dear all, I have been running some tests of my package RSiena on different platforms and trying to reconcile the results. With Mac, the commands options(digits=4) round(1.81652, digits=4) print 1.817 The value you're printing is 1.8165, so I believe Windows gets it right using our round-to-even rule, but I'm not surprised that there are differences. The value 1.8165 isn't exactly representable, so it's somewhat random whether a system chooses to represent it slightly larger or slightly smaller. Duncan Murdoch With Windows, the same commands print 1.816 I am not bothered which answer I get, but it would be nice if they were the same. A linux box agreed with the Mac. Mac sessionInfo(): R version 2.14.2 (2012-02-29) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] RSiena_1.0.12.205 loaded via a namespace (and not attached): [1] grid_2.14.2lattice_0.20-0 Matrix_1.0-4 tools_2.14.2 Windows (but 2.14.1patched was the same) sessionInfo(): R version 2.15.0 alpha (2012-03-08 r58640) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United Kingdom.1252 [2] LC_CTYPE=English_United Kingdom.1252 [3] LC_MONETARY=English_United Kingdom.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base Any enlightenment would be gratefully received. Ruth __ R-help@r-project.org 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.