prep_num_bin: prep_num_bin

Description Usage Arguments Value Examples

View source: R/prep_num_bin.R

Description

Function which bins numeric vector into bins of equal weight (or a smooth function on weight).

Usage

1
2
3
4
5
6
7
8
9
prep_num_bin(
  var_to_band,
  n_bins = 10,
  weight = NULL,
  method = "even_weight",
  use_labels = FALSE,
  mean = 0.5,
  sd = 0.3
)

Arguments

var_to_band

Vector[numeric] - vector of values to be binned

n_bins

numeric - Number of bins to split exposure into

weight

numeric - vector weight for observations

method

string - One of c("even_weight", "gaussian_weight"). If "even_weight" is used the weight (exposure) in each bucket is even If "gaussian_weight" is used the weight look like a normal distribution centered on mean with width sd. The effect of this is to give thinner tails

use_labels

logical - should the bins be numbered or human readable labelled

mean

numeric - Only used when method="gaussian_weight" - value between 0 - 1 for if the bucket with maximum weight is at min or max prediction. Default is 0.5 (middle bucket)

sd

numeric - Only used when method="gaussian_weight" - value between 0.1 - 1 for how thin the distribution tails should be. Low numbers give thin tails

Value

a list with the following named entried: bins: Either a numeric vector or a factor (depending on use_labels) which gives the bin. The vector is of length length(var_to_band) and has n_bins unique values labels: Human readable labels of where binning has occored vector with values 1 to n_bins indicating bin of var_to_band. (1 is low var_to_band and n_bins is high var_to_band)

Examples

1
2
3
prep_num_bin(var_to_band=1:20, n_bins=5)
prep_num_bin(var_to_band=1:20, n_bins=5, method="gaussian_weight")
prep_num_bin(var_to_band=1:20, n_bins=5, method="gaussian_weight", use_labels=TRUE)

gloverd2/admr documentation built on Dec. 2, 2020, 11:16 p.m.