View source: R/genCDFInv_linear.R
genCDFInv_linear | R Documentation |
This function creates an inverse cumulative distribution function (CDF) for
a given dataset using linear interpolation. The resulting function maps
probabilities (in the range [0, 1]
) to values in the dataset.
genCDFInv_linear(X)
X |
A numeric vector. The dataset for which the inverse CDF is to be created. |
The function works as follows:
Computes the empirical CDF (ECDF) of the dataset.
Extracts the sorted ECDF values for the dataset.
Sorts the original data values.
Uses approxfun
to create a linear interpolation function
mapping probabilities to dataset values.
The resulting function can handle probabilities outside [0, 1]
using the
rule = 2
parameter in approxfun
, which extrapolates
based on the nearest data points.
A function that takes a single argument, p
, a numeric vector of
probabilities in [0, 1]
, and returns the corresponding values interpolated
from the dataset.
ecdf
, approxfun
# Example usage:
data <- c(1, 2, 3, 4, 5)
inv_cdf <- genCDFInv_linear(data)
inv_cdf(c(0.1, 0.5, 0.9)) # Compute the interpolated values for given probabilities
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.