Kernel density estimation Problem graph ?

1 visualización (últimos 30 días)
Lakshit Chugh
Lakshit Chugh el 3 de Mayo de 2020
Respondida: Shubh Sahu el 6 de Mayo de 2020
l = linspace(-4,4,500);
fhat = zeros(size(l));
h = 1.06*n^(-1/5);
hold on
for i=1:n % get each kernel function evaluated at x% centered at data
f = exp(-(1/(2*h^2))*(l-x(i)).^2)/sqrt(2*pi)/h;
plot(l,f/(n*h));
fhat = fhat+f/(n);
end
plot(l,fhat);
hold off
Thats my code for kernel density estimation where x(i) is dataset of mixture of gaussian and beta distribution but the graph i am getting is value so small that even i cant see it and i am not sure is it right?

Respuestas (1)

Shubh Sahu
Shubh Sahu el 6 de Mayo de 2020
See this piece of code:
f = exp(-(1/(2*h^2))*(l-x(i)).^2)/sqrt(2*pi)/h;
plot(l,f/(n*h));
In this f is a point and l is a vector. So in first place you are plotting point against a vector so it will be very difficult to see. Make fhat an array.
fhat(i)= fhat(i-1)+f/(n);
Note: I will strongly recommend you to see this link. Never plot anything inside for loop until it's very necessary to do that.

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by