This section collects various methods in nonparametric statistics. This includes kernel density estimation for univariate and multivariate data, kernel regression and locally weighted scatterplot smoothing (lowess).
sandbox.nonparametric contains additional functions that are work in progress or don’t have unit tests yet. We are planning to include here nonparametric density estimators, especially based on kernel or orthogonal polynomials, smoothers, and tools for nonparametric models and methods in other parts of statsmodels.
The kernel density estimation (KDE) functionality is split between univariate and multivariate estimation, which are implemented in quite different ways.
Univariate estimation (as provided by KDEUnivariate) uses FFT transforms, which makes it quite fast. Therefore it should be preferred for continuous, univariate data if speed is important. It supports using different kernels; bandwidth estimation is done only by a rule of thumb (Scott or Silverman).
Multivariate estimation (as provided by KDEMultivariate) uses product kernels. It supports least squares and maximum likelihood cross-validation for bandwidth estimation, as well as estimating mixed continuous, ordered and unordered data. The default kernels (Gaussian, Wang-Ryzin and Aitchison-Aitken) cannot be altered at the moment however. Direct estimation of the conditional density () is supported by KDEMultivariateConditional.
KDEMultivariate can do univariate estimation as well, but is up to two orders of magnitude slower than KDEUnivariate.
Kernel regression (as provided by KernelReg) is based on the same product kernel approach as KDEMultivariate, and therefore has the same set of features (mixed data, cross-validated bandwidth estimation, kernels) as described above for KDEMultivariate. Censored regression is provided by KernelCensoredReg.
Note that code for semi-parametric partial linear models and single index models, based on KernelReg, can be found in the sandbox.
The public functions and classes are
|smoothers_lowess.lowess(endog, exog[, frac, ...])||LOWESS (Locally Weighted Scatterplot Smoothing)|
|kde.KDEUnivariate(endog)||Univariate Kernel Density Estimator.|
|kernel_density.KDEMultivariate(data, var_type)||Multivariate kernel density estimator.|
|kernel_density.KDEMultivariateConditional(...)||Conditional multivariate kernel density estimator.|
|kernel_density.EstimatorSettings([...])||Object to specify settings for density estimation or regression.|
|kernel_regression.KernelReg(endog, exog, ...)||Nonparametric kernel regression class.|
|kernel_regression.KernelCensoredReg(endog, ...)||Nonparametric censored regression.|
helper functions for kernel bandwidths
|bandwidths.bw_scott(x[, kernel])||Scott’s Rule of Thumb|
|bandwidths.bw_silverman(x[, kernel])||Silverman’s Rule of Thumb|
|bandwidths.select_bandwidth(x, bw, kernel)||Selects bandwidth for a selection rule bw|
There are some examples for nonlinear functions in statsmodels.nonparametric.dgp_examples
The sandbox.nonparametric contains additional insufficiently tested classes for testing functional form and for semi-linear and single index models.