Simulating from an Epanechnikov kernel density estimate / exact functional form of the Epanechnikov kernel?

15 views (last 30 days)
It's my first time posting, so apologies if I'm breaking any etiquette. I've used the ksdensity function to estimate a density using the Epanechnikov kernel and would now like to make repeated random draws from this density. I'm doing so according to the suggestion at How can I draw a value randomly from a kernel density estimate? while sampling from the kernel using the scheme described at Generating a sample from Epanechnikov's kernel. On simulated data, this ends up looking something like this:
reps = 1000;
weight1 = 0.4;
mu1 = 10;
sigma1 = 5;
mu2 = -7;
sigma2 = 3;
v1 = rand(reps,1);
v2 = mu1 + sigma1*randn(reps,1);
v3 = mu2 + sigma2*randn(reps,1);
data = (v1 <= weight1).*v2 + (v1 > weight1).*v3;
clear v1 v2 v3;
[density,points,bandwidth] = ksdensity(data,'Kernel','epanechnikov');
u1 = (-1)+(1-(-1))*rand(reps,1);
u2 = (-1)+(1-(-1))*rand(reps,1);
u3 = (-1)+(1-(-1))*rand(reps,1);
u = (abs(u3) >= max(abs(u1),abs(u2))).*u2 + (abs(u3) < max(abs(u1),abs(u2))).*u3;
clear u1 u2 u3;
sim = randsample(data,reps,true) + bandwidth*sqrt(5)*u;
My concern has to do with the last line of this sample and that multiplier sqrt(5). I'm inferring this term is necessary based on the discussion at Different definitions of Epanechnikov-Kernel; i also find that it seems to deliver densities that better line up with my data than when i omit it. however, to be certain that it belongs i'd need to know the precise functional form of the kernel that ksdensity is using. (if i understand the terminology correctly, i think it would also suffice to figure out the "canonical bandwidth" being used). Does anyone know these details or where they can be found? Thanks very much!

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!