create_initial_bins: Create initial bins

Description Usage Arguments Details Value See Also Examples

View source: R/initial_binning.R

Description

Creates a set of initial bins.

Usage

1
2
3
4
5
6
create_initial_bins(
  data = NULL,
  threshold = NULL,
  ordinal_value = NULL,
  default_ind = NULL
)

Arguments

data

The input data that contains ordinal_value and default_ind.

threshold

An integer that defines the minimum number of defaults in each bin. Typically needs a reasonable number of defaults to ensure the homogeneity test can be executed with some power.

ordinal_value

A numeric ordinal value that rank order each obligor's relative default risk. For example, a numeric score or numeric rating information.

default_ind

An integer, or double, representing the default status. The state of default must be indicated by 1 and non-default by 0.

Details

The current (only) method is based on an 'equal height' approach where a new bin is created as soon as the number of defaults is equal to (or larger) than a user defined threshold level. Thus, the term 'equal height' refers to roughly equal number of defaults in each bin. The data is processed based on the user supplied variables holding the ordinal_value and the default_ind. The state of default in default_ind is generally 1 if the obligor defaults in the next 12-month period. To avoid bias in the default rate calculation, only current non-default obligors should be included in data. This type of data pre-processing is left to the user before calling create_initial_bins. Similary, the rank-order information in ordinal_value must be invariant to sorting. Thus, it may be required to convert characters/factors of ratings to numerical values before calling create_initial_bins.

Value

A list of bins. Each list component in the returned list is a bin (of class bin). The list is returned in ascending order by min_score (see link to constructor below), and each bin contains at least threshold number of defaults.

See Also

The (helper) constructor to bin objects, bin. See also reduce_bins.

Examples

1
2
3
4
5
6
# create a set of initial bins
bins <- create_initial_bins(bin_data, 30, "score", "default")
bins_df <- dplyr::bind_rows(bins)
plot(x = bins_df$mid_score, y = log(bins_df$odds), type = "p",
     col = "lightblue", cex = 1.5, pch = 20,
     ylab = "log(odds)", xlab = "score")

rrunner/binsmlr documentation built on July 19, 2020, 12:41 a.m.