How getting the probability density estimation for positive data?

5 views (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 6 Apr 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 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!