Binning Function in R

AlHal2
AlHal2 used Ask the Experts™
on
I've installed the rattle package and run this code.
library(rattle)
test <- c(1,2,3,4,5,6)
test
test2 <- binning(test,4,method = "quantile",ordered = FALSE)
test2

Open in new window


This is the output I get.

[1] 1.000000 1.916667 3.500000 5.083333 6.000000
Levels: [1,1.92] (1.92,3.5] (3.5,5.08] (5.08,6]

Open in new window

I understand that 3.5 is the median.  Where do 1.92 and 5.08 come from?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
HelpDesk Technician
Commented:
I believe those are your Lower (Q1) and Upper (Q3) Quartiles. Mathematically the function quantile() gives 9 different methods of computing quartiles. You results match the results of quantile() computed using method 8.

quantile(1:6,type=8)
      0%      (Q1) 25%     50%    (Q3)75%     100%
1.000000 1.916667 3.500000 5.083333 6.000000

It's possible that the arguments in binning, potentially the method = "quantile" argument specifically, specify this method of computing quartiles.

Here is the documentation for that function in R: https://www.rdocumentation.org/packages/rattle/versions/5.2.0/topics/binning

I believe that "wtd.quantile" instead of "quantile" would potentially yield the expected and more common box-plot estimations of:
      0%      (Q1) 25%     50%    (Q3)75%     100%
1.000000 2.250000 3.500000 5.250000 6.000000

test2 <- binning(test,4,method = "wtd.quantile",ordered = FALSE)

Open in new window

Author

Commented:
Thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial