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);figuresubplot(1,2,1)plot(x,zeros(size(x)),'*r')hold onplot(xi,f);xlabel('Original data','FontSize',14)ylabel('Probability function','FontSize',14)subplot(1,2,2)hold onsubplot(1,2,2)[f,xi] = ksdensity(x*1000);ylabel('Probability function','FontSize',14)xlabel('data times 1000','FontSize',14)plot(xi,f);hold onplot(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
Best Answer