Description Usage Arguments Value Examples
Function which bins numeric vector into bins of equal weight (or a smooth function on weight).
1 2 3 4 5 6 7 8 9 |
var_to_band |
Vector[numeric] - vector of values to be binned. Should be true numeric however can also be categorical with fewer levels than |
n_bins |
numeric - Number of bins to split exposure into |
weight |
numeric - vector weight for observations |
method |
string - One of |
use_labels |
logical - should the bins be numbered ( |
mean |
numeric - Only used when |
sd |
numeric - Only used when |
a list with the following named entries:
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 occured
cut_values: The numbers the cuts are made at such that they can be reproduced using cut
fucntion
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
)
1 2 3 4 5 6 7 | out1 <- prep_num_bin(var_to_band=1:20, n_bins=5)
out2 <-prep_num_bin(var_to_band=1:20, n_bins=5, method="gaussian_weight")
out3 <-prep_num_bin(var_to_band=1:20, n_bins=5, method="gaussian_weight", use_labels=TRUE)
#To reproduce using cuts
out1$bins
cut(1:20, breaks=out1$cut_values, labels=FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.