How getting the probability density estimation for positive data?

Hi all,
I need to find the probability density estimation and the cumulative distribution of the following set of data using ksdensity.
x=[0 0.0000265 0 0.00000366 0 0.00101 0 0 0.000296 0.0000894 0 0.000182 0 0 0.00511 0.00118 0.000012115279359 0 0.000000000901 0 0 0.000562 0.0008061 0 0 0 0 0.0000702 0 0.000693];
The data is positive, so no negative values are possibile. I get a strange behaviour using ksdensity. Hopefully someone would be able to help me.
Here my code for computing the probability density estimation of x:
[f,xi] = ksdensity(x);
figure
subplot(1,2,1)
plot(x,zeros(size(x)),'*r')
hold on
plot(xi,f);
xlabel('Original data','FontSize',14)
ylabel('Probability function','FontSize',14)
subplot(1,2,2)
hold on
subplot(1,2,2)
[f,xi] = ksdensity(x*1000);
ylabel('Probability function','FontSize',14)
xlabel('data times 1000','FontSize',14)
plot(xi,f);
hold on
plot(x*1000,zeros(size(x)),'*r')
here a plot from the previous code:
On left side there is the probability density estimation for the original data and on the right side for the data times 1000. The two shapes are identical but with the original data the probability is much lower than 1. Why do I get this big difference? Moreover the data can be only positive, but the estimated probability distribution is upper than zero for negative value. I tried to change the support in this way:
[f,xi] = ksdensity(x,'support','positive');
but I get the following error message:
Error using ksdensity>compute_finite_support (line 218)
Cannot set support to 'positive' with non-positive data.
Error in ksdensity (line 119)
[L,U] = compute_finite_support(support,ymin,ymax);
Is not possibile to compute the restrict the probability density estimation only for positive data?
Thanks
Cheers
Pietro

 Respuesta aceptada

Star Strider
Star Strider el 6 de Abr. de 2014
  • I can’t explain the plot on the left, since by definition the probability is never greater than 1.
  • Your data are not truly positive. Several are zero, that by definition are neither positive nor negative. Consider the result of sign([-1 0 1]).

4 comentarios

Thanks for you reply. What should I do to not get any probability for negative values? What do you mean for "Consider the result of sign([-1 0 1])."?
To not get any probability for negative values, you have to cheat a bit. Define your zero values as eps instead. Create a second vector (to preserve your first):
xnz = x;
xnz(xnz == 0) = eps;
This puts (eps = 222.0446e-018) in place of every zero.
The sign reference demonstrates that zero is considered neither negative nor positive:
st = sign([-2 0 2])
produces:
st =
-1.0000e+000 0.0000e+000 1.0000e+000
So the sign of zero is 0, not +.
Oh thanks, it works!
My pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 6 de Abr. de 2014

Comentada:

el 6 de Abr. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by