statsmodels.nonparametric.kde.KDEUnivariate

class statsmodels.nonparametric.kde.KDEUnivariate(endog)[source]

Univariate Kernel Density Estimator.

Parameters
endogarray_like

The variable for which the density estimate is desired.

See also

KDEMultivariate
kdensity, kdensityfft

Notes

If cdf, sf, cumhazard, or entropy are computed, they are computed based on the definition of the kernel rather than the FFT approximation, even if the density is fit with FFT = True.

KDEUnivariate is much faster than KDEMultivariate, due to its FFT-based implementation. It should be preferred for univariate, continuous data. KDEMultivariate also supports mixed data.

Examples

>>> import statsmodels.api as sm
>>> import matplotlib.pyplot as plt
>>> nobs = 300
>>> np.random.seed(1234)  # Seed random generator
>>> dens = sm.nonparametric.KDEUnivariate(np.random.normal(size=nobs))
>>> dens.fit()
>>> plt.plot(dens.cdf)
>>> plt.show()
Attributes
cdf

Returns the cumulative distribution function evaluated at the support.

Will not work if fit has not been called.

cumhazard

Returns the hazard function evaluated at the support.

Will not work if fit has not been called.

entropy

Returns the differential entropy evaluated at the support

Will not work if fit has not been called. 1e-12 is added to each probability to ensure that log(0) is not called.

icdf

Inverse Cumulative Distribution (Quantile) Function

Will not work if fit has not been called. Uses scipy.stats.mstats.mquantiles.

sf

Returns the survival function evaluated at the support.

Will not work if fit has not been called.

Methods

evaluate(point)

Evaluate density at a point or points.

fit([kernel, bw, fft, weights, gridsize, …])

Attach the density estimate to the KDEUnivariate class.

Methods

evaluate(point)

Evaluate density at a point or points.

fit([kernel, bw, fft, weights, gridsize, …])

Attach the density estimate to the KDEUnivariate class.

Properties

cdf

Returns the cumulative distribution function evaluated at the support.

cumhazard

Returns the hazard function evaluated at the support.

entropy

Returns the differential entropy evaluated at the support

icdf

Inverse Cumulative Distribution (Quantile) Function

sf

Returns the survival function evaluated at the support.