Comparison between two stairs graphs

4 vues (au cours des 30 derniers jours)
mercury
mercury le 20 Oct 2013
Hi all, In a statistics project I have to calculate the maximum of the norm of difference between two graphs (kolmogorov-smirnov distance). The graphs are from empirical data. I tried to create a vector of differences between the two graphs (which are stair graphs) but we don't have the same number of points. Worst, we don't know the x-coordinates to access all the f1(x) and f2(x) to compare them. I searched for 2 days, please any help is welcome. this is a part of the code and the graphs. You can see that the graphs represent the relative cumulate frequencies obtained from the same data (a vector of numbers from (0 to 20). One vector is contructed from a sample of the data and one of the entire data. Then I have just compare the plots generated by cdfplot function:
freq_cum_theorie = cdfplot(vect_moy_theorie); hold on freq_cum_echant_theorie = cdfplot(moy_echant_theorie); hold on
Thank you a lot.

Réponses (1)

Jonathan LeSage
Jonathan LeSage le 22 Oct 2013
Since you're interested in the values of the empirical CDF curves, you could use the ecdf function as opposed to cdfplot. The ecdf function will return the (x,y) vectors of the empirical CDF fit which you can then use to compute your Kolmogorov-Smirnov distance. You can find out more about the ecdf function in the documentation:
On another note, you may need to perform some sort of interpolation to "expand" the data vectors from one empirical CDF to match the dimensions of the other. For example, you may have one ecdf with 50 values and another with 25. In this example, you need to interpolate the smaller data set, such that the dimensions are the same. From there, the distance calculations should be pretty straightforward. For interpolation, MATLAB has the handy interp1 function. Here is a link to the interp1 documentation:
Seems like an interesting problem! Good luck!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by