depthbin: Equal depth binning

Description Usage Arguments Value See Also Examples

Description

Simple equal depth binning algorithm.

Usage

1
2
depthbin(ser, nbins = 10, qtype = 7, digits = 10, labelRange = T,
  labelPct = F, labelOrder = F)

Arguments

ser

numeric vector to bin

nbins

number of bins desired

qtype

an integer between 1 and 9 selecting one of the nine quantile algorithms detailed below to be used. See quantile for more details. Default is 7.

digits

number, number of digits to display in bin categories

labelRange

logical: TRUE assigns a numeric score/ranking (ex. 1/3, 2/3, or 3/3 if 3 bins) to each bin. Can be combined with labelOrder and labelPct

labelPct

logical: TRUE appends the percent of observations assigned to the bin to the factor level (name). Can be combined with labelOrder and labelRange

labelOrder

logical: TRUE appends the ordinal position of the bin to the factor level (name). Can be combined with labelPct and labelRange

Value

ordered factor vector with bins

See Also

quantile

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## perfect equal depth bins
x1 <- rnorm(1000, 0, 20)
binned1 <- depthbin(x1, nbins=10)
table(binned1)

## slightly uneven bins with integer data
x2 <- rpois(1000, 3)
binned2 <- depthbin(x2, nbins=5)
summary(binned2)

## as good as we can get with skewed integer data
x3 <- round(abs(log(abs(rnorm(1000)))))
binned3 <- depthbin(x3, nbins=5)
summary(binned3)

## including more information in category names (levels of factor variable)
x4 <- round(abs(log(abs(rnorm(1000)))))
binned4 <- depthbin(x4, nbins=3, labelRange=T, labelPct=T, labelOrder=T)
summary(binned4)

brooksandrew/Rsenal documentation built on May 13, 2019, 7:50 a.m.