Plotting average of many empirical cumulative distribution functions

12 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Jeff Miller
Jeff Miller el 20 de Oct. de 2019
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 comentarios
kevin cecere palazzo
kevin cecere palazzo el 24 de Oct. de 2019
Editada: kevin cecere palazzo el 24 de Oct. de 2019
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 el 24 de Oct. de 2019
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.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by