Closed kaz462 closed 1 year ago
I think we might want to mention SAS's rounde
function, which matches R's round
function
It might be nice to give this PHUSE working group more of a shout out! A cross-industry initiative to document differences between programming languages.
SO I first encountered this issue when double programming in R for TLGs made in SAS. I think you experienced the same issue and I think that should be mentioned here to set the stage.
Maybe change this to Exploring Rounding Options. Bug Fix makes it seem like R is doing something wrong and SAS is doing it right.
The post just sort of ends abruptly - anyway we could tie it up with your current experiences/summary of the post?
This one is going to be awesome!!!
Maybe change this to Exploring Rounding Options. Bug Fix makes it seem like R is doing something wrong and SAS is doing it right.
what do you think of changing "Bug Fix" to "Numerical precision issue"? I also linked a SAS documentation on this topic: Numerical Accuracy in SAS Software
@manciniedoardo @bms63 Thanks so much for your review and comments!
I have limited knowledge on computational precision and floating-point, so I didn't go too deep on this topic, let me know if everything makes sense by referencing multiple resources.
Perhaps leave them with a question at the end of the post. How concerned should we be if a programs in R and and SAS are off ...
Good idea on the open-ended question. The following example illustrate the "safe" options I mentioned in the last section doesn't work as expected, but I'm not sure if this will ever happen in our daily work.
In this example, a
is a value slightly less than 1.5
. So if we choose round half up approach with 0 decimal places, output 1
is expected, but because + sqrt(.Machine$double.eps)
is used, we get 2
as the result.
> a <- 1.5 - 0.5*sqrt(.Machine$double.eps)
> janitor::round_half_up(a, digits = 0)
[1] 2
If it happens, maybe we could argue a
and 1.5 are nearly equal by using all.equal()
function from base R with default tolerance
value (default tolerance = sqrt(.Machine$double.eps)
> all.equal(a, 1.5)
[1] TRUE
@manciniedoardo @rossfarrugia @bms63 depends on the situation, maybe discrepancies like this example can be accepted? should I add this example in the last section?
Fine from my side 👍
CAn we increase the description here. Feels kind of empty