cum.bin {monobin} | R Documentation |
Monotonic binning based on maximum cumulative target rate (MAPA)
Description
cum.bin
implements monotonic binning based on maximum cumulative target rate.
This algorithm is known as MAPA (Monotone Adjacent Pooling Algorithm).
Usage
cum.bin(
x,
y,
sc = c(NA, NaN, Inf, -Inf),
sc.method = "together",
g = 15,
y.type = NA,
force.trend = NA
)
Arguments
x |
Numeric vector to be binned. |
y |
Numeric target vector (binary or continuous). |
sc |
Numeric vector with special case elements. Default values are |
sc.method |
Define how special cases will be treated, all together or in separate bins.
Possible values are |
g |
Number of starting groups. Default is 15. |
y.type |
Type of |
force.trend |
If the expected trend should be forced. Possible values: |
Value
The command cum.bin
generates a list of two objects. The first object, data frame summary.tbl
presents a summary table of final binning, while x.trans
is a vector of discretized values.
In case of single unique value for x
or y
in complete cases (cases different than special cases),
it will return data frame with info.
Examples
suppressMessages(library(monobin))
data(gcd)
amount.bin <- cum.bin(x = gcd$amount, y = gcd$qual)
amount.bin[[1]]
gcd$amount.bin <- amount.bin[[2]]
gcd %>% group_by(amount.bin) %>% summarise(n = n(), y.avg = mean(qual))
#increase default number of groups (g = 20)
amount.bin.1 <- cum.bin(x = gcd$amount, y = gcd$qual, g = 20)
amount.bin.1[[1]]
#force trend to decreasing
cum.bin(x = gcd$amount, y = gcd$qual, g = 20, force.trend = "d")[[1]]