# Why is SmoothKernelDistribution not symmetric in 2D?

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
]


• 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? – kirma May 22 '19 at 10:14
• @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. – Pinti May 22 '19 at 10:28
• Interestingly setting MaxRecursion to any value, even 0, will increase accuracy of Mean considerably. Results won't be exact with any value, though. – kirma May 22 '19 at 10:34
• The following gets a more centered result: SmoothKernelDistribution[{{0, 0}}, Automatic, InterpolationPoints -> 500]. – JimB Jun 5 '19 at 5:02
• "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? – JimB Jun 5 '19 at 17:01

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}}]]


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}}]]


With InterpolationPoints -> 512 we get

(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.