I have a data $X=[x_1,\dots,x_n].$
In Matlab, I know by using
[f,x]=ecdf(X)
plot(x,f)
we will have the empirical distribution function based on $X$.
Now, if $x$ is given, how will I know the value of my ECDF at this point?
MATLABstatistics
I have a data $X=[x_1,\dots,x_n].$
In Matlab, I know by using
[f,x]=ecdf(X)
plot(x,f)
we will have the empirical distribution function based on $X$.
Now, if $x$ is given, how will I know the value of my ECDF at this point?
Best Answer
You can use interpolation for this. In Matlab,
interp1
(documentation) performs a variety of interpolation methods on 1-D data. In your case, you might try nearest neighbor or possibly linear interpolation, though you could attempt higher order schemes depending on your data. Nearest neighbor interpolation returns the point from your data $X$ that is closest to a supplied query point $x$ – here's an example:This produces a figure like this:
Note that in the code above I had to remove the first point from the values returned by
ecdf
. This is becauseinterp1
requires that the sample points (hereX
) be strictly monotonically increasing or decreasing.