5
$\begingroup$

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.

$\endgroup$
5
  • $\begingroup$ 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. $\endgroup$
    – bbgodfrey
    Commented Jul 23, 2015 at 2:48
  • $\begingroup$ Leslie, have you already seen the explicit kernel specifications, roughly halfway down the "Details and Options" section of the documentation for SmoothKernelDistribution? $\endgroup$
    – MarcoB
    Commented Jul 23, 2015 at 2:54
  • $\begingroup$ 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 $\endgroup$ Commented Jul 23, 2015 at 13:37
  • 1
    $\begingroup$ 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. $\endgroup$
    – Andy Ross
    Commented Jul 23, 2015 at 19:28
  • $\begingroup$ 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, $\endgroup$ Commented Jul 23, 2015 at 23:01

1 Answer 1

4
$\begingroup$

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

enter image description here

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$ Commented Jul 26, 2015 at 21:12
  • $\begingroup$ 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. $\endgroup$ Commented Jul 26, 2015 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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