statistics-0.6.0.2: A library of statistical types, data, and functionsSource codeContentsIndex
Statistics.KernelDensity
Portabilityportable
Stabilityexperimental
Maintainerbos@serpentine.com
Contents
Simple entry points
Building blocks
Choosing points from a sample
Bandwidth estimation
Kernels
Low-level estimation
Description
Kernel density estimation code, providing non-parametric ways to estimate the probability density function of a sample.
Synopsis
epanechnikovPDF :: Vector v Double => Int -> v Double -> (Points, Vector Double)
gaussianPDF :: Vector v Double => Int -> v Double -> (Points, Vector Double)
newtype Points = Points {
fromPoints :: Vector Double
}
choosePoints :: Vector v Double => Int -> Double -> v Double -> Points
type Bandwidth = Double
bandwidth :: Vector v Double => (Double -> Bandwidth) -> v Double -> Bandwidth
epanechnikovBW :: Double -> Bandwidth
gaussianBW :: Double -> Bandwidth
type Kernel = Double -> Double -> Double -> Double -> Double
epanechnikovKernel :: Kernel
gaussianKernel :: Kernel
estimatePDF :: Vector v Double => Kernel -> Bandwidth -> v Double -> Points -> Vector Double
simplePDF :: Vector v Double => (Double -> Double) -> Kernel -> Double -> Int -> v Double -> (Points, Vector Double)
Simple entry points
epanechnikovPDFSource
:: Vector v Double
=> IntNumber of points at which to estimate
-> v DoubleData sample
-> (Points, Vector Double)
Simple Epanechnikov kernel density estimator. Returns the uniformly spaced points from the sample range at which the density function was estimated, and the estimates at those points.
gaussianPDFSource
:: Vector v Double
=> IntNumber of points at which to estimate
-> v DoubleData sample
-> (Points, Vector Double)
Simple Gaussian kernel density estimator. Returns the uniformly spaced points from the sample range at which the density function was estimated, and the estimates at those points.
Building blocks
Choosing points from a sample
newtype Points Source
Points from the range of a Sample.
Constructors
Points
fromPoints :: Vector Double
show/hide Instances
choosePointsSource
:: Vector v Double
=> IntNumber of points to select, n
-> DoubleSample bandwidth, h
-> v DoubleInput data
-> Points

Choose a uniform range of points at which to estimate a sample's probability density function.

If you are using a Gaussian kernel, multiply the sample's bandwidth by 3 before passing it to this function.

If this function is passed an empty vector, it returns values of positive and negative infinity.

Bandwidth estimation
type Bandwidth = DoubleSource
The width of the convolution kernel used.
bandwidth :: Vector v Double => (Double -> Bandwidth) -> v Double -> BandwidthSource
Compute the optimal bandwidth from the observed data for the given kernel.
epanechnikovBW :: Double -> BandwidthSource
Bandwidth estimator for an Epanechnikov kernel.
gaussianBW :: Double -> BandwidthSource
Bandwidth estimator for a Gaussian kernel.
Kernels
type Kernel = Double -> Double -> Double -> Double -> DoubleSource

The convolution kernel. Its parameters are as follows:

  • Scaling factor, 1/nh
  • Bandwidth, h
  • A point at which to sample the input, p
  • One sample value, v
epanechnikovKernel :: KernelSource
Epanechnikov kernel for probability density function estimation.
gaussianKernel :: KernelSource
Gaussian kernel for probability density function estimation.
Low-level estimation
estimatePDFSource
:: Vector v Double
=> KernelKernel function
-> BandwidthBandwidth, h
-> v DoubleSample data
-> PointsPoints at which to estimate
-> Vector Double
Kernel density estimator, providing a non-parametric way of estimating the PDF of a random variable.
simplePDFSource
:: Vector v Double
=> Double -> DoubleBandwidth function
-> KernelKernel function
-> DoubleBandwidth scaling factor (3 for a Gaussian kernel, 1 for all others)
-> IntNumber of points at which to estimate
-> v Doublesample data
-> (Points, Vector Double)
A helper for creating a simple kernel density estimation function with automatically chosen bandwidth and estimation points.
Produced by Haddock version 2.4.2