How to get probability of sample coming from a distribution? I have a set of observations drawn from an unknown distribution. Given a new observation $x$ I would like to ascertain the probability that $x$ was drawn from the same distribution.
My approach was to use kernel density estimation to estimate the pdf of the initial samples, and then use this to estimate the probability of $x$. It has now come to my attention that the $\mathrm{pdf}(x) \neq P(x)$.
How can I calculate $P(x)$?
 A: You can extend your non-parametric method if your original sample is large enough.  
Suppose you wanted to have a 95% probability of not rejecting the null hypothesis that your new observation comes from the same distribution if it in fact does: your critical region could be to reject the null hypothesis if your new observation is in the top $k$ or bottom $k$ of the now $n+1$ values.  
So you want $\frac{2k}{n+1} = 1 - 0.95$, i.e. $k=0.05\frac{n+1}{2}$, giving the following pairs of values of $k$ and $n$
k   n
1   39
2   79
3  119
4  159

and the pattern is obvious.  In reality, $n$ will be decided for you so you need to make a sensible choice in the circumstances. 
In my view, you should choose $k$ (or, in general, the critical region) based on $n$ (or the original sample) before you look at the new observation, rather than looking at the full data and then trying to derive a probability from the new observation as seen: if the null hypothesis is in fact true then each position is equally likely, and the probability of being as extreme or more extreme than the new observation would be basing your conclusion on things that were not observed.   
If you had some idea about the unknown original distribution or the possible alternative distribution, you could probably do better than this.
A: You can't get $P(x)$ for a continuous distribution. It is 0. To get $P(a \leq x \leq b)$ you would compute the following:
$$\int_{a}^{b} f(x) \ dx $$
