MATLAB: How to get upper and lower bounds values from an empirical cumulative distribution

cdfconfidence intervalsecdfempirical confidenceerror analysisMATLAB

Hi, thanks for looking at my question. I've been googling, looking on here, and reading the Matlab documentation all afternoon and I can't work this out. I'm sure it's very simple, but I'm new to Matlab syntax so I need some help please!
I have a vector, which is a list of parameters from some data fitting. Specifically it's 250 values.
I want to find the 95% confidence bounds for the numbers in this vector. I can plot an ecdf:
I can also get the [x,y] values for this ECDF using:
[cdf_x,cdf_y] = ecdf(data_vector)
cdf = [cdf_x,cdf_y]
Where I am struggling is I cannot work out how to get the 95% upper and lower values from the array "cdf" (or any of the previous variables I've generated along the way). It's all empirical, so I just want to know the two values of cdf_y where cdf_x equals 0.025 and 0.975.
How can I do this?
NB. cdf_x doesn't have values specifically at 0.025 or 0.975 so it needs to either interpolate or give the closest result if possible.

Best Answer

  • Using the prctile funciton on ‘cdf_y’ may work to calculate the percentiles (that appear to be what you want). To get the approximate ‘cdf_x’ values that are associated with them, use the interp1 function.
    The code would go something like this:
    prctv = prctile(cdf_y, [2.5 97.5]);
    xval = interp1(cdf_y, cdf_x, prctv);
    I cann ot write exact code since I do not have your data.
    EDIT — (20 Oct 2020 at 15:42)
    Corrected typographical error.