genCDFInv_poly: Generate an Inverse CDF Function Using Polynomial Regression

View source: R/genCDFInv_poly.R

genCDFInv_polyR Documentation

Generate an Inverse CDF Function Using Polynomial Regression

Description

This function creates an inverse cumulative distribution function (CDF) for a given dataset using polynomial regression. The resulting function maps probabilities (in the range [0, 1]) to values in the dataset.

Usage

genCDFInv_poly(data, degree)

Arguments

data

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

degree

An integer. The degree of the polynomial to fit in the regression.

Details

The function works as follows:

  1. Sorts the dataset and computes the empirical CDF (ECDF) of the data.

  2. Fits a polynomial regression to model the relationship between ECDF values and the sorted dataset.

  3. Uses the fitted polynomial model to predict the inverse CDF for given probabilities.

The degree of the polynomial can be specified to control the flexibility of the regression model.

Value

A function that takes a single argument, y, a numeric vector of probabilities in [0, 1], and returns the corresponding values predicted by the polynomial regression.

See Also

lm, poly, ecdf

Examples

# Example usage:
data <- c(1, 2, 3, 4, 5)
inv_cdf <- genCDFInv_poly(data, degree = 2)
inv_cdf(c(0.1, 0.5, 0.9))  # Compute predicted values for given probabilities


covalchemy documentation built on April 12, 2025, 2:15 a.m.