Probability Density Function using ksdensity is not normalized

20 visualizaciones (últimos 30 días)
Ali
Ali el 28 de Jun. de 2014
Respondida: VladTheInstaller el 15 de En. de 2017
I have a vector "columnA" of N data points. I want to find the PDF. I use:
xi = min(columnA):1e-9:max(columnA);
f = ksdensity(columnA,xi);
plot(xi,f)
But when I use trapz to integrate f:
trapz(f)/length(xi)
the value is too far from 1. Even when increasing the range of xi, I still do not get reasonable value.

Respuestas (3)

VladTheInstaller
VladTheInstaller el 15 de En. de 2017
Actually, the output from ksdensity is normalized, but you will have to use numerical integration along the appropriate space. In your case,
trapz(xi,f)
should be close to 1.

Image Analyst
Image Analyst el 21 de Ag. de 2014
Why not use hist() or histc() to get the histogram? The histogram is essentially the probability density function.

Youssef  Khmou
Youssef Khmou el 21 de Ag. de 2014
The ksdensity produces a Probability density function, no need to divide by the length of the x vector :
x=randn(200,1);
y=[min(x):0.1:max(x)];
p=ksdensity(x,y);
sum(p)
% plot(y,p)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by