genCDFInv_linear {covalchemy}R Documentation

Generate an Inverse CDF Function Using Linear Interpolation

Description

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.

Usage

genCDFInv_linear(X)

Arguments

X

A numeric vector. The dataset for which the inverse CDF is to be created.

Details

The function works as follows:

  1. Computes the empirical CDF (ECDF) of the dataset.

  2. Extracts the sorted ECDF values for the dataset.

  3. Sorts the original data values.

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

Value

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.

See Also

ecdf, approxfun

Examples

# 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


[Package covalchemy version 1.0.0 Index]