Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feature Request: a function to align the SAS rounding in R? #1872

Closed
kaz462 opened this issue Apr 21, 2023 · 10 comments
Closed

Feature Request: a function to align the SAS rounding in R? #1872

kaz462 opened this issue Apr 21, 2023 · 10 comments
Labels
enhancement New feature or request programming

Comments

@kaz462
Copy link
Collaborator

kaz462 commented Apr 21, 2023

Feature Idea

The following function is from a PHUSE paper

ut_round <- function(x, n=0)
{
  # x is the value to be rounded
  # n is the precision of the rounding
  scale <- 10^n
  y <- trunc(x * scale + sign(x) * 0.5) / scale
  # Return the rounded number
  return(y)
}

Similar work has been done as shown in the link below, but I couldn't find the source code:
https://rdrr.io/github/mbrothe/brdgr/man/round_sas.html

Relevant Input

No response

Relevant Output

No response

Reproducible Example/Pseudo Code

No response

@bundfussr
Copy link
Collaborator

Having an option to use SAS rounding is a good idea.

I wonder why round() implements only one option for rounding. In the documentation of round() it is mentioned that the IEEE 754 standard is used. It has two options for rounding: the R way and the SAS way. I am not sure why only one option was implemented in R. (SAS provides functions for both.)

I don't think we need to implement a new function as implementations are already available like mentioned above or janitor::round_half_up().

At the moment we do not use round() in admiral. Once we do, we need to think about

  • which option we should use (by default) and
  • if and how the user should control which option is used.

@bms63
Copy link
Collaborator

bms63 commented Apr 24, 2023

As this is an R package meant to build datasets in R for production, I think we should always have the default rounding in R, i.e. round to even.

I do like the option of having the round like SAS available if folks want to use admiral for double programming of SAS datasets, but will we need to have this implemented in admiral or just show users how they can switch his on in a mutate statement or in one of functions that allows for expressions?

@rossfarrugia
Copy link
Collaborator

My 2 cents on this... isn't this more something for downstream TLG packages rather than in ADaM? Generally in ADaM we just show the full number and let that be a decision for table formatting. as Stefan says we don't use round() anywhere in admiral. my personal perspective is that part of the move to R is appreciating differences like this, and if HAs are informed we're using R for submission via briefing package then they'd expect such differences. it could come up during QC comparisons if using SAS to double program, but even then that could be explained. really, there's no right or wrong approach, they're just different so i wouldn't go overboard here.

@kaz462
Copy link
Collaborator Author

kaz462 commented Apr 26, 2023

Thank you all for the detailed replies! I agree no need to implement a new function as it's already available, and the rounding is not ADaM-specific.
The validation rounding discrepancies are not caused by SAS/R, but by different rounding approaches, which should be based on the study SAP instead of the software. (Sorry, the title of this issue may be misleading)

There are situations where rounding is done in ADaM (e.g., CDISC pilot data ADSL.BMIBL). I wonder if we could add examples/documentation on different rounding approaches in R, maybe at admiral or pharmaverse/end_to_end_examples?

@bms63
Copy link
Collaborator

bms63 commented Apr 26, 2023

Perhaps a certain blogging site could make a short article??

@rossfarrugia
Copy link
Collaborator

@mstackhouse / @MichaelRimler what's the latest on this PHUSE WG: https://advance.phuse.global/pages/viewpage.action?pageId=327874 ? That's where I usually point people towards and know there was a white paper planned for this.

@kaz462 another option could be a page at https://bayer-group.github.io/sas2r/ given it's not admiral or pharmaverse specific? i.e. it's part of general R training.

@MichaelRimler
Copy link

MichaelRimler commented Apr 27, 2023

Still reading the thread, but AVALC will round in its generation, won't it? @rossfarrugia

The CAMIS working group is focused more on statistical methodology implementations. The rounding issue seemed clear in that (R vs SAS), you could get round-to-even or round_away_from_zero with either. in SAS - round() or rounde(). In R, round() or janitor::round_half_up() {as mentioned above}.

@mstackhouse
Copy link

My biostats team has fussed with this as well and this PR to Tplyr is refined from some issues/testing that they did. atorus-research/Tplyr#126

@kaz462
Copy link
Collaborator Author

kaz462 commented Apr 28, 2023

Thanks all for your information! @bms63 @rossfarrugia a short article at SAS2R catalog sounds great, issue created, will include the two rounding approaches as mentioned by @bundfussr @MichaelRimler

you could get round-to-even or round_away_from_zero with either. in SAS - round() or rounde(). In R, round() or janitor::round_half_up() {as mentioned above}.

and mention options(tplyr.IBMRounding) for Tplyr

The function from PHUSE paper has precision issues as discussed in atorus-research/Tplyr#126, so I will stick with janitor::round_half_up()

@rossfarrugia
Copy link
Collaborator

thanks all for the input! think we can close this one out then. sounds a good outcome - thanks Kangjie!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request programming
Development

No branches or pull requests

6 participants