6
$\begingroup$

For example, we create SmoothKernelDistribution from one data point in 2D, e.g. {0,0}. Why is the plot of PDF not symmetric around this point?

Observe where contour lines touch the image frame. Is this a bug, or is my understanding of SmoothKernelDistribution wrong?

ContourPlot[
 Evaluate@PDF[
   SmoothKernelDistribution[{{0, 0}}],
   {x, y}
 ],
{x, -1, 1}, {y, -1, 1},
PlotLegends -> Automatic,
Axes -> True
]

contourPlot

$\endgroup$
  • 1
    $\begingroup$ Clearly not the expected result, but is it a bug? It's probably a side effect of methods being used, error varies on basis of the bandwidth. What would you, by the way, expect the automatically calculated bandwidth to be for an input of a single point? $\endgroup$ – kirma May 22 at 10:14
  • $\begingroup$ @kirma Regarding the automatically calculated bandwidth, I have no idea, I just posted the simplest example. But this effect is visible also with (different) prescribed values. $\endgroup$ – Pinti May 22 at 10:28
  • 1
    $\begingroup$ Interestingly setting MaxRecursion to any value, even 0, will increase accuracy of Mean considerably. Results won't be exact with any value, though. $\endgroup$ – kirma May 22 at 10:34
  • $\begingroup$ The following gets a more centered result: SmoothKernelDistribution[{{0, 0}}, Automatic, InterpolationPoints -> 500]. $\endgroup$ – JimB Jun 5 at 5:02
  • 2
    $\begingroup$ "In practice" no one would expect that SmoothKernelDistribution provide any answer other than "Don't talk to me until you have more data". "In theory" what would you want/expect SmoothKernelDistribution to provide when there is no ability to estimate variances when there is just a single observation? A bivariate kernel with infinite bandwidth centered on the data point? $\endgroup$ – JimB Jun 5 at 17:01
1
$\begingroup$

No one should expect that giving SmoothKernelDistribution a single data point should provide any answer other than "Don't talk to me until you have more data" as there is no ability to estimate a bandwidth from the variation in the observations (as there is no variation). However, I agree that if however a bandwidth is chosen, the resulting distribution should be centered on that data point.

Here is what I think happens. SmoothKernelDistribution for a two-dimensional distribution is evaluated on a grid of 64 grid points (InterpolationPoints) in each direction by default. However, you can set the number of InterpolationPoints to any positive number but that value gets bumped up to the next highest multiple of 2 (if what you give isn't a multiple of 2).

For either dimension the default grid points are as follows for a single observation:

skd = SmoothKernelDistribution[{{0, 0}}];
skd[[2, 2, 1]]
(* {-3.17044, -3.06979, -2.96915, -2.8685, -2.76785, -2.6672, -2.56655, 
-2.4659, -2.36525, -2.2646, -2.16395, -2.0633, -1.96266, -1.86201, 
-1.76136, -1.66071, -1.56006, -1.45941, -1.35876, -1.25811, -1.15746, 
-1.05681, -0.956165, -0.855516, -0.754867, -0.654218, -0.553569, 
-0.45292, -0.352271, -0.251622, -0.150973, -0.0503245, 0.0503245, 
0.150973, 0.251622, 0.352271, 0.45292, 0.553569, 0.654218, 0.754867, 
0.855516, 0.956165, 1.05681, 1.15746, 1.25811, 1.35876, 1.45941, 
1.56006, 1.66071, 1.76136, 1.86201, 1.96266, 2.0633, 2.16395, 2.2646, 
2.36525, 2.4659, 2.56655, 2.6672, 2.76785, 2.8685, 2.96915, 3.06979, 
3.17044} *)

Consider the smallest absolute value which in this case is 0.0503245 and plot the point {0.0503245, 0.0503245} along with the contour plot:

skd = SmoothKernelDistribution[{{0, 0}}];
xy = Min[Abs[skd[[2, 2, 1]]]];
Show[ContourPlot[Evaluate@PDF[skd, {x, y}], {x, -1, 1}, {y, -1, 1}, Axes -> True],
 ListPlot[{{xy, xy}}]]

Off-center contour plot

Now lets try this with InterpolationPoints -> 16:

skd = SmoothKernelDistribution[{{0, 0}}, InterpolationPoints -> 16];
xy = Min[Abs[skd[[2, 2, 1]]]];
Show[ContourPlot[Evaluate@PDF[skd, {x, y}], {x, -1, 1}, {y, -1, 1}, Axes -> True],
 ListPlot[{{xy, xy}}]]

Off center plot with fewer interpolation points

With InterpolationPoints -> 512 we get

512 InterpolationPoints

(Strangely with InterpolationPoints -> 8, the contours are centered on {-xy, -xy}.)

I guess I wouldn't call this a bug but rather a feature whose effect can be minimized by choosing a large enough value of InterpolationPoints.

$\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.