View source: R/find_quantile_bin.R
| find_quantile_bin | R Documentation |
This function identifies the quantile interval (or 'bin') in which an observation belongs, given an empirical distribution of values (x). For observations that lie beyond the range of x, the original distribution can be 'padded' by adding an extreme minimum and/or maximum value to increase the range of the distribution (see Details). Sample quantiles are calculated for x using user-specified probabilities (probs) via quantile. The quantile bins in which each observation (y) falls is then determined and returned in a dataframe.
find_quantile_bin(
x,
y,
probs = seq(0, 1, by = 0.02),
pad_min = NULL,
pad_max = NULL,
...
)
x |
A numeric vector. |
y |
A numeric vector of observations for which to determine the quantile bin in which they belong. |
probs |
A numeric vector of probabilities, passed to |
pad_min |
A number which is added to |
pad_max |
A number which is added to |
... |
Additional arguments passed to |
Padding is implemented by this function to express observations that are more extreme than the original distribution of observations as quantiles of that distribution. This has a small effect on the lowest/highest quantiles of the distribution but this is often unnoticeable if the quantile bins to which an observation is assigned are sufficiently large (e.g., 2
The function returns a dataframe with the index of the quantile bin in which each observation belongs ('bin') and the corresponding probability ('prob').
Edward Lavender
set.seed(0)
x <- runif(100, 0, 250)
y <- c(10, 100, 200)
find_quantile_bin(x, y)
find_quantile_bin(x, y, pad_min = 0, pad_max = 1e5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.