Abstract: Provides an efficient implementation of univariate local polynomial kernel density estimators that can handle bounded and discrete data. See Geenens (2014), Geenens and Wang (2018), Nagler (2018a), and Nagler (2018b) for the underlying theoretical framework.
Introduction
Kernel Density Estimation (KDE) is a fundamental statistical technique used to estimate the probability density function of a random variable. While standard KDE methods, such as R's default density() function, are widely used, they often struggle with real-world data constraints. Specifically, they suffer from boundary bias in bounded data, fail to respect the nature of discrete variables, and can be computationally prohibitive for large-scale datasets. The kde1d package provides a high-performance solution to these challenges using local polynomial likelihood estimation.
Addressing Data Constraints
Boundary and Discrete Data Handling
One of the primary strengths of kde1d is its ability to handle complex data types through specialized transformations and parameters. For bounded data (e.g., percentages or strictly positive values), the package applies log or probit transformations to map the data onto the entire real line, preventing probability "leakage" outside of physical bounds.
For discrete data, the package utilizes a deterministic jittering technique called equi_jitter. This method spreads tied observations equidistantly over an interval, allowing the estimator to treat discrete data as continuous while maintaining deterministic behavior. Users can specify these constraints using the xmin, xmax, and type arguments in the main estimation function.
Local Polynomial Flexibility
The package moves beyond simple sum-of-kernels approaches by employing local polynomial likelihood estimation. Users can select the degree of the polynomial (0, 1, or 2), allowing the model to adapt from a log-constant fit to a log-quadratic fit. This flexibility enables the estimator to better capture the curvature and nuances of the underlying density.
Implementation and Performance
To ensure scalability, kde1d utilizes spline interpolation. By calculating the density on a fixed grid and interpolating elsewhere, the package significantly reduces the computational overhead and memory usage required for millions of observations.
The package follows standard R distribution naming conventions, providing a familiar interface for users through functions like dkde1d (density), pkde1d (CDF), qkde1d (quantile), and rkde1d (random generation). Notably, the rkde1d function supports quasi-random number generation (Sobol sequences), which can improve efficiency in simulation tasks.
Conclusion
The kde1d package offers a robust and efficient framework for univariate density estimation. By addressing the limitations of standard KDE—particularly regarding boundaries and discrete data—it provides researchers and practitioners with a more accurate tool for modeling complex empirical distributions. While currently limited to univariate data, its performance and flexibility make it a superior choice for one-dimensional density estimation tasks.
Summary updated