6.5.6.2.4. statsmodels.sandbox.nonparametric.kernels.CustomKernel

class statsmodels.sandbox.nonparametric.kernels.CustomKernel(shape, h=1.0, domain=None, norm=None)[source]

Generic 1D Kernel object. Can be constructed by selecting a standard named Kernel, or providing a lambda expression and domain. The domain allows some algorithms to run faster for finite domain kernels.

shape should be a function taking and returning numeric type.

For sanity it should always return positive or zero but this isn’t enforced in case you want to do weird things. Bear in mind that the statistical tests etc. may not be valid for non-positive kernels.

The bandwidth of the kernel is supplied as h.

You may specify a domain as a list of 2 values [min, max], in which case kernel will be treated as zero outside these values. This will speed up calculation.

You may also specify the normalisation constant for the supplied Kernel. If you do this number will be stored and used as the normalisation without calculation. It is recommended you do this if you know the constant, to speed up calculation. In particular if the shape function provided is already normalised you should provide norm = 1.0.

Warning: I think several calculations assume that the kernel is normalized. No tests for non-normalized kernel.

__init__(shape, h=1.0, domain=None, norm=None)[source]

shape should be a function taking and returning numeric type.

For sanity it should always return positive or zero but this isn’t enforced in case you want to do weird things. Bear in mind that the statistical tests etc. may not be valid for non-positive kernels.

The bandwidth of the kernel is supplied as h.

You may specify a domain as a list of 2 values [min, max], in which case kernel will be treated as zero outside these values. This will speed up calculation.

You may also specify the normalisation constant for the supplied Kernel. If you do this number will be stored and used as the normalisation without calculation. It is recommended you do this if you know the constant, to speed up calculation. In particular if the shape function provided is already normalised you should provide norm = 1.0.

Warning: I think several calculations assume that the kernel is normalized. No tests for non-normalized kernel.

6.5.6.2.4.1. Methods

__init__(shape[, h, domain, norm]) shape should be a function taking and returning numeric type.
density(xs, x) Returns the kernel density estimate for point x based on x-values
density_confint(density, nobs[, alpha]) approximate pointwise confidence interval for kernel density
density_var(density, nobs) approximate pointwise variance for kernel density
geth() Getter for kernel bandwidth, h
in_domain(xs, ys, x) Returns the filtered (xs, ys) based on the Kernel domain centred on x
moments(n)
seth(value) Setter for kernel bandwidth, h
smooth(xs, ys, x) Returns the kernel smoothing estimate for point x based on x-values xs and y-values ys.
smoothconf(xs, ys, x[, alpha]) Returns the kernel smoothing estimate with confidence 1sigma bounds
smoothvar(xs, ys, x) Returns the kernel smoothing estimate of the variance at point x.
weight(x) This returns the normalised weight at distance x

6.5.6.2.4.2. Attributes

L2Norm Returns the integral of the square of the kernal from -inf to inf
h Kernel Bandwidth
kernel_var Returns the second moment of the kernel
norm_const Normalising constant for kernel (integral from -inf to inf)
normal_reference_constant Constant used for silverman normal reference asymtotic bandwidth calculation.