calculate_decile_table: Calculate a decile breakdown

Description Usage Arguments Examples

Description

This function calculates a decile table for any combination of numerical and categorical variables.

Usage

1
2
calculate_decile_table(df, binning, grouping, top_level = "1",
  n_bins = 10, risk_names = TRUE, format = FALSE, ...)

Arguments

df

A data frame

binning

Variable for which binning should be applied

grouping

A two-level (binary) variable to calculate the ratio in each bin

top_level

Top level of the grouping variable. Defaults to "1"

n_bins

Provide a number of bins. Defaults to 10

risk_names

Should column names be converted to risk-specific names? Defaults to TRUE

format

Should table printing be formatted with kable? Defaults to FALSE

...

Additional grouping columns to calculate deciles

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
recipes::credit_data %>%
  first_to_lower() %>%
  calculate_decile_table(binning = time,
                      grouping = status,
                      top_level = "bad",
                      n_bins = 10,
                      risk_names = FALSE,
                      format = FALSE)

recipes::credit_data %>%
  first_to_lower() %>%
  calculate_decile_table(binning = time,
                      grouping = status,
                      top_level = "bad",
                      n_bins = 10,
                      risk_names = FALSE,
                      format = FALSE,
                      marital) # to include an additional grouping column

recipes::credit_data %>%
  first_to_lower() %>%
  select(marital, status, time) %>%
  nest(-marital) %>%
  mutate(stats = purrr::map(data, calculate_decile_table, time, status, "bad")) %>%
  select(marital, stats) %>%
  unnest()

konradsemsch/aider documentation built on May 22, 2019, 2:40 p.m.