# Documentation for the Bounded option of SmoothKernelDistribution

I have found the Bounded option useful in the SmoothKernelDistribution function, but I can't find any documentation for exactly how it is generating the bounded version of the distribution. Is there someplace I can go to find this? Thank you.

• Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory Tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. – bbgodfrey Jul 23 '15 at 2:48
• Leslie, have you already seen the explicit kernel specifications, roughly halfway down the "Details and Options" section of the documentation for SmoothKernelDistribution? – MarcoB Jul 23 '15 at 2:54
• Hi MarcoB, Yes, thank you, and that was helpful, but it doesn't seem to specify how the "Bounded" option is implemented. I assume it is reflecting the data around the boundaries and then truncating, but I am not sure whether that involves some adjustment to the bandwidth. Plus, there seem to be other options for imposing bounds, so I am not sure exactly what it is doing. That said, it seems to work well. Best, Leslie – Leslie Marx Jul 23 '15 at 13:37
• It has been a long time since I saw the code but if memory serves it works by reflecting about the boundaries and truncating. The bandwidth is unaffected. – Andy Ross Jul 23 '15 at 19:28
• Hi Andy, Am I thinking about this correctly: Suppose the data vector is a vector of length n. If the lower bound is zero, then estimate the kernel based on (-x,x). In particular, act as if there were 2*n data points, and if the bandwidth uses the standard deviation, then take the standard deviation of all 2*n data points. Then truncate the estimated density at zero and multiply by 2. Best, – Leslie Marx Jul 23 '15 at 23:01

This deserves a little explanation since I found that the behavior is sometimes inconsistent.

Take some very simple data and create a function bound that illustrates how we suspect the bounded method is working (by reflecting the data about the bound, computing the estimate with the given bandwidth, and then truncating at the bound).

data = {1, 2, 3};

bound[data_, bw_] :=
TruncatedDistribution[{0, Infinity},
SmoothKernelDistribution[Join[-data, data], bw]]


Comparing to the built-in seems to indicate we are on the right track.

NIntegrate[(PDF[bound[data, 1/2], x] -
PDF[SmoothKernelDistribution[data, 1/2, {"Bounded", 0, "Gaussian"}], x]
)^2, {x, 0, Infinity}]

(* 1.27734*10^-9 *)


In my testing, this generally seems to hold unless the bandwidth is left as Automatic. In that case, it appears the bandwidth is half that for unbounded estimates (which I consider a bug).

bws = {"Scott", "Silverman", 3, Automatic};

(SmoothKernelDistribution[data, #]["Bandwidth"]/
SmoothKernelDistribution[data, #, {"Bounded", 0, "Gaussian"}][
"Bandwidth"]) & /@ bws

(* {1., 1., 1., 2.} *)


My recommendation would be to select a bandwidth by running the estimator unbounded and then feeding that back in as a bandwidth for the bounded estimator. For example...

data = RandomVariate[ExponentialDistribution[1/25], 1000];
bw = SmoothKernelDistribution[data]["Bandwidth"];
est = SmoothKernelDistribution[data, bw, {"Bounded", 0, "Gaussian"}];

Plot[PDF[est, x], {x, -1, 100}]


• Hi Andy, Thank you so much for taking time with this. After experimenting more with your code and mine, it seems to me that there is a bug in the way "Bounded" is implemented, at least in the case with a fixed lower bound and an upper bound of Infinity. The bug seems to result in a density that integrates to 1/2 instead of 1. The fix is easy -- just multiply by 2. Using "Bounded" with a lower bound of -Infinity and a fixed upper bound seems to work fine. – Leslie Marx Jul 26 '15 at 21:12
• It makes some sense to me that this bug could happen because after doubling the data and then truncating, one would need to multiply the resulting density by 2. It seems that the code does not take this final step when there is a lower bound but no upper bound specified. – Leslie Marx Jul 26 '15 at 21:12