Sample from Kernel Density Estimator

I do not know of an implementation, but you can write your own with few lines. Assuming a 1-D normal kernel density estimator, to get one sample you need to:

  • pick a data point x, using for instance with something like x = sample(data)
  • get the kernel bandwith h, be it the Silverman optimal bandwith or extracted from the object created by the function kde_lscv(data) from the package you mention
  • generate a random sample with rand(Normal(x,1/h))

If you change the kernel beware of the parametrisation to make sure your bandwith is a proper scale parameter, and if you go multidimensional pay attention too.

But essentially you are sampling from a mixture model with equal weights, so first sample a component then sample from that component.

2 Likes