Rounding [Software]

posted by Helmut Homepage – Vienna, Austria, 2013-01-04 18:35 (4505 d 21:19 ago) – Posting: # 9786
Views: 13,135

Dear Detlew!

❝ SAS 9.2: round(125.005,0.01) → 125.01

(Note the definition of rounding to 2 decimals as rounding to multiples of 0.01)


There is a similar function in Excel (has to be activated in Add-ins: Analysis Toolpak):
mround(125.005,0.01) → 125.01
But – like R:
Maxima: round(125.005*100)/100 → 125.00

❝ A more drastically example, may be important also in normal life I think:

round(c(0.5,1.5,2.5,3.5,4.5,5.5),0)

❝ [1] 0 2 2 4 4 6

❝ At least in Germany one would expect:

[1] 1 2 3 4 5 6


Splendid.

❝ Wow! Seems rounding the CI anyhow is not such a good idea.


Yes. Not so important for the conventional acceptance range, but we have double rounding for NTIDs (AR 90.00–111.11%). Must not forget to state theta2=1.1111 in sampleN.TOST explicitly.

❝ [edit]Also the rounding seems to be implied by regulatory definitions of the acceptance range as 80.00 - 125.00 (EMA & FDA)![/edit]


<nitpick>

Well, the width of FDA's/EMA's AR is not 45% but 125.004–79.995=45.009%…

</nitpick>

❝ But ... IMHO this must be independent from the used rounding method for 5 except the magnitude of deviation from the not rounded results since all the other results >125.0000 - 125.0049 will be also counted as BE if rounded and as not BE if not rounded.


Right. Maybe I will run a set and save individual results to a file. In the meantime I finished my balanced cross-over sim’s. n 12–60, CV 6–100%. With my grid I have 306·106 sim’s each. With rounding I got 24 (7.84%) empiric alphas significantly >0.05; without 11 (3.59%). If I take power.TOST(CV=…, n=…, theta0=1.25) as the gold standard and calculate the %RSE of the simulated alphas I see a positive bias of the rounding again:

            Q I    median   Q III
rounded    -0.110  +0.218  +0.574
unrounded  -0.404  -0.036  +0.325


Jiří showed me another gem. Try

sprintf("%.2f", round(125.005, 2))
sprintf("%.2f", 100*round(1.25005, 4))



Edit: 2012-01-05
After reading a lot of stuff on the net I guess the only way to get “commercial rounding” (the one we learned in school; 1–4 down, 5–9 up) in R without requiring a library is by a function (THX to an anonymous poster):

cround <- function(x,n){
  z    <- abs(x)*10^n
  z    <- z + 0.5
  z    <- trunc(z)
  z    <- z/10^n
  z*sign(x)
}


round(c(79.994, 79.995, 125.004, 125.005), 2)
79.99  80.00 125.00 125.00
cround(c(79.994, 79.995, 125.004, 125.005), 2)
79.99  80.00 125.00 125.01


But note:
round(c(0.79994, 0.79995, 1.25004, 1.25005), 4)
0.7999 0.8000 1.2500 1.2501
cround(c(0.79994, 0.79995, 1.25004, 1.25005), 4)
0.7999 0.8000 1.2500 1.2501


Sometimes R drives me nuts.

Dif-tor heh smusma 🖖🏼 Довге життя Україна! [image]
Helmut Schütz
[image]

The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes

Complete thread:

UA Flag
Activity
 Admin contact
23,424 posts in 4,927 threads, 1,669 registered users;
129 visitors (0 registered, 129 guests [including 7 identified bots]).
Forum time: 16:55 CEST (Europe/Vienna)

[Those] who have an excessive faith in their theories or in their
ideas are not only poorly disposed to make discoveries, but they
also make very poor observations.    Claude Bernard

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5