find_quantile_bin: Find the quantile bin in which an observation belongs

View source: R/find_quantile_bin.R

find_quantile_binR Documentation

Find the quantile bin in which an observation belongs

Description

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.

Usage

find_quantile_bin(
  x,
  y,
  probs = seq(0, 1, by = 0.02),
  pad_min = NULL,
  pad_max = NULL,
  ...
)

Arguments

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 quantile.

pad_min

A number which is added to x to extend the left-hand side of the distribution of values encompassed.

pad_max

A number which is added to x to extend the right-hand side of the distribution of values encompassed.

...

Additional arguments passed to quantile.

Details

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

Value

The function returns a dataframe with the index of the quantile bin in which each observation belongs ('bin') and the corresponding probability ('prob').

Author(s)

Edward Lavender

Examples

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)


edwardlavender/utils.add documentation built on Dec. 14, 2024, 8:11 a.m.