1
$\begingroup$

I have implemented the KDE distribution finding for a dataset. I apply the adaptive bandwidth method; I want to plot the change in bandwidth over the entire distribution. How can I do it? Thank you! enter image description here

$\endgroup$

1 Answer 1

1
$\begingroup$

The following will give you the adaptive bandwidths that Mathematica uses:

SeedRandom[12345];
data = RandomVariate[NormalDistribution[0, 1], 10] // Sort;

α = 0.6;
kmd = KernelMixtureDistribution[data, {"Adaptive", Automatic, α}];
bw = kmd[[2, 4]]
(* {0.455945, 0.367787, 0.354622, 0.350731, 0.340984, 0.33284, 0.335444, 0.336422,
    0.343412, 0.517947}{0.455945, 0.367787, 0.354622, 0.350731, 0.340984, 0.33284,
    0.335444, 0.336422, 0.343412, 0.517947} *)

However, these bandwidths do not match what R gives (using akj in the quantreg package) which is the same as I get doing this in Mathematica with a brute force method. I'll look at that more to see if I can figure out the difference.

One can then plot those adaptive bandwidths against the data values:

ListPlot[Transpose[{data, bw}], Frame -> True,
  FrameLabel -> {"Data value", "Adaptive bandwidth"}]

Data values vs adaptive bandwidth

$\endgroup$
4
  • $\begingroup$ Can also use kmd["Weights"] to get the list kmd[[2, 4]] (+1) $\endgroup$
    – kglr
    Commented Feb 8 at 0:15
  • $\begingroup$ @kglr kmd["Weights"] seems to get kmd[[2,1]]. And maybe those weights might help explain the difference I get using R. $\endgroup$
    – JimB
    Commented Feb 8 at 0:24
  • $\begingroup$ sorry, I meant kmd["Bandwidth"]. $\endgroup$
    – kglr
    Commented Feb 8 at 0:30
  • $\begingroup$ Thank you so much. I solved it $\endgroup$ Commented Mar 19 at 17:58

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.