# Impose conditions on PDF distribution

Consider some data

data = {{x1,y1},{x2,y2},...}


I organize a density distribution using

datadistr = SmoothKernelDistribution[data]


I know that the real distribution must vanish at $$x\leqslant x_{\text{min}}$$ and, independently, $$y \leqslant y_{\text{min}}, y \geqslant y_{\text{max}}$$. Quantitative statement is that there are no points with $$x \leqslant x_{\text{min}}, y \leqslant y_{\text{min}}, y \geqslant y_{\text{max}}$$ in the data set.

However, PDF tells me that the distribution is non-zero in this domain. I do not know how to let the PDF know that the distribution must be zero in $$x_{\text{min}}$$ and $$y_{\text{min}}, y_{\text{max}}$$, i.e. to force it smoothly falls to zero close to these thresholds. Is there any way to impose this restriction?

• Well, the distribution is created by convolution of the sum of Dirac-measures centered at the data points against a smoothing kernel. By construction, the resulting distribution bleeds a bit out of the bounds of the distribution from which you have sampled. (You can remedy the effect a little by picking a compactly supported smoothing kernel and by choosing a not too broad bandwidth parameter.) Maybe SmoothKernelDistribution is not the appropriate tool for what you try to do. – Henrik Schumacher Mar 20 '19 at 21:45
• @HenrikSchumacher : got it. Thank you! – John Taylor Mar 20 '19 at 21:55
• You're welcome. – Henrik Schumacher Mar 20 '19 at 21:57
• Try the "Bounded" option when there are "hard" boundaries. – JimB Mar 20 '19 at 22:27

@HenrikSchumacher explained why you're getting "leakage" outside of the fixed boundaries of your data generation process. Here's one way to account for the kind of borders you have: use the "Bounded" option.

(* Generate some bounded data *)
data = RandomVariate[BinormalDistribution[{0, 0}, {1, 1}, 0.9], 5000];
data = Select[data, #[[1]] > -1 && -1 < #[[2]] < 1 &];

(* Get nonparametric density estimate *)
skd = SmoothKernelDistribution[data, 0.3, {"Bounded", {{-1, ∞}, {-1, 1}}, "Gaussian"}];

(* Show results *)
Show[ListPlot[data, PlotRange -> {{-1.5, 3}, {-1.5, 1.5}}, Frame -> True],
ContourPlot[PDF[skd, {x, y}], {x, -1.5, 3}, {y, -1.5, 1.5},
ContourShading -> None, PlotPoints -> 100]]


And as a check see if pdf integrates to 1:

NIntegrate[PDF[skd, {x, y}], {x, -1, ∞}, {y, -1, 1}]
(* 1. *)