3
$\begingroup$

I would like to know more about the structure behind the KernelMixtureDistribution and SmoothKernelDistribution in Mathematica.

data = 
  RandomVariate[
    distrib = 
      MixtureDistribution[{2, 1, 0.5}, 
        {NormalDistribution[1.5, 0.2], 
         NormalDistribution[2.5, 0.5], 
         NormalDistribution[3.0, 0.1]}], 
   10^4];
kmd = 
  KernelMixtureDistribution[data, {"Adaptive", Automatic, Automatic}];
smd = SmoothKernelDistribution[data];
Plot[{PDF[distrib, x], PDF[kmd, x]}, {x, 0, 5}, 
  PlotStyle -> {{Black, Dotted}, Black}, 
  PlotRange -> {{0, 5}, {0, 1.4}}, 
  Frame -> True, 
  ImageSize -> 400]
kmd[[2]]
smd[[2]]

Each of the last two commands returns a list of numbers, that I guess are the internal representation for the Gaussian superposition approximating the distribution given by data. My question is: How do I interpret these numbers?

$\endgroup$
  • $\begingroup$ I'd figure out something for KernelMixtureDistribution. The variable kmd in my small piece of code is such that kmd[[2]]={1/n,kind,{x1,..,xn},bw}. Where n are the data points, kind is the kind of kernel used (in the above case is Gaussian), x1,..,xn are the centers of the Gaussians and bw is the bandwidth (see Mathematica manual). For SmoothKernelDensity I am working on. EDIT: SORRY! the first element of kmd[[2]], i.e. kmd[[2]][[1]] is not 1/n. For small n this is true but when n grows this becomes a list. So I am yet walking in the darkness. $\endgroup$ – Fabio Oct 11 '14 at 14:20
5
$\begingroup$

I'm a bit pressed for time at the moment so this is not a complete answer.

The key to understanding SmoothKernelDistribution lies in understanding KernelMixtureDistribution whose PDF it interpolates. The internals for SmoothKernelDistribution are simply coordinates for that interpolation.

As for KernelMixtureDistribution it is important to look at the MaxMixtureKernels option. KernelMixtureDistribution effectively uses two different methods for smoothing. One is to place a kernel at each data point with a fixed bandwidth and the other is to bin the data and place kernels at the center of each bin and weight them according to the local density.

The internals are best interpreted as {weights, kernel-type, kernel locations, bandwidth}. For the first case, the weights are always equal to 1/n. In the second case they are determined by the number of points in the bin.

When and whether to switch to the binned estimator (for speedy estimation of the density with large data) is determined by MaxMixtureKernels. If it is set to All the switch will never be made and the exact density (placing a kernel at each data point) will always happen. If the setting is Automatic the binned estimator is called when the sample size is sufficiently large.

The bandwidth component is determined by whether bandwidth is fixed or adaptive. For a fixed bandwidth you should get a single number. For adaptive bandwidths each kernel gets its own bandwidth (hence the list).

The short story is that if you want the standard definition of a kernel density estimator with no approximation you should set MaxMixtureKernels to All.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.