フィルターのクリア

Plotting average of many empirical cumulative distribution functions

14 ビュー (過去 30 日間)
kevin cecere palazzo
kevin cecere palazzo 2019 年 10 月 20 日
コメント済み: Jeff Miller 2019 年 10 月 24 日
I have a code in which I start a figure, make hold on and repeat a for cycle where at the end of each repetition I plot an empirical cumulative distribution function. So at the end I have in the same figure many ecdf (they are defined on the interval [0,1] and take value, obviously in [0,1]. How can I add to the same figure the average of these functions? I mean, is there a command that memomrizes the values taken by each function and thanks to which I can plot the average of these functions?

採用された回答

Jeff Miller
Jeff Miller 2019 年 10 月 20 日
I'm pretty sure there is no function to do that. To compute the average function by Vincentizing, you first choose a set of CDF values where you will compute the averages & initialize a vector to hold the totals at each CDF value, say
CDFvals = 0.01:0.01:0.99;
ttlCDFs = zeros(size(avgCDFs));
Then, each time you go through the loop and make a new eCDF, you find the score at each avgCDF value (e.g., with one of the methods described in iecdf from FileExchange), something like
[f,x] = ecdf(y); % y is your data for the empirical CDF computed in this pass through the loop.
for iCDF = 1:numel(avgCDFs) % Probably can be vectorized for speed, but this shows the idea
pos = find(CDFvals(iCDF)<=f,1);
xq = x(pos);
ttlCDFs(iCDF) = ttlCDFs(iCDF) + xq;
end
Then at the end you can compute & plot the average data value at each CDFval,
avgCDFs = ttlCDFs / NumberOfCDFsBeingAveraged; % Same as the number of passes through the loop
plot(CDFvals,avgCDFs)
  4 件のコメント
kevin cecere palazzo
kevin cecere palazzo 2019 年 10 月 24 日
編集済み: kevin cecere palazzo 2019 年 10 月 24 日
Last question, I did not get what exactly do these two lines:
pos = find(CDFvals(iCDF)<=f,1);
xq = x(pos);
should'nt I write "last" after 1 in the first of the two lines?
Jeff Miller
Jeff Miller 2019 年 10 月 24 日
Those lines, which I may have miscopied from eicdf, are supposed to find the x value with the indicated CDFval. I think you are right about 'last'. Or maybe it should be
pos = find(f<=CDFvals(iCDF),1);
Just look at an example or two and it will be easy to tell.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by