I'm building up on my preivous question because there is a further issue.
I have fitted in Matlab a normal distribution to my data vector: PD = fitdist(data,'normal')
. Now I have a new data point coming in (e.g. x = 0.5) and I would like to calculate its probability.
Using cdf(PD,x)
will not work because it gives the probability that the point is smaller or equal to x (but not exactly x). Using pdf(PD,x)
gives just the densitiy but not the probability and so it can be greater than one.
How can I calculate the probability?
Let's say you have a random variable X
that follows the normal distribution with mean mu
and standard deviation s
.
Let F be the cumulative distribution function for the normal distribution with mean mu
and standard deviation s
. The probability the random variableX
falls between a
and b
, that is P(a < X <= b) = F(b) - F(a).
In Matlab code:
P_a_b = normcdf(b, mu, s) - normcdf(a, mu, s);
Note: observe that the probability X is exactly equal to 0.5 (or any specific value) is zero! A range of outcomes will have positive probability, but an insufficient sum of individual outcomes will have probability zero.