View source: R/genCDFInv_poly.R
genCDFInv_poly | R Documentation |
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.
genCDFInv_poly(data, degree)
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. |
The function works as follows:
Sorts the dataset and computes the empirical CDF (ECDF) of the data.
Fits a polynomial regression to model the relationship between ECDF values and the sorted dataset.
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.
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.
lm
, poly
, ecdf
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.