How to add two empirical CDFs without using a for loop?

How can I add two CDFs together if their respective double arrays are of different sizes?
Take for example:
[Fp,Xp] = ecdf(distribution1); % blue CDF shown below
[Fv,Xv] = ecdf(distribution2); % orange CDF shown below
size(Fp,1)
ans = 492
size(Xp,1)
ans = 492
size(Fv,1)
ans = 899
size(Pv,1)
ans = 899
If Fp is the probability of event p happening at time Xp, and Fv is the probability of event v happening at time Xv, how could I calculate Fpv and Xpv if the double arrays are of unequal sizes? I hope this makes sense, sorry if it's a confusing explanation of what I'm trying to do.
The formula I want to use is:
Fpv(x) = Fp(x) + Fv(x) - Fp(x)*Fv(x)
Which assumes that Fp(x)*Fv(x) < Fp(x) + Fv(x)

2 comentarios

Mirlan Karimov
Mirlan Karimov el 6 de Abr. de 2019
Editada: Mirlan Karimov el 6 de Abr. de 2019
Why not interpolating Fv in 899 points. interp(Fv, 2)
or other way around: interpolating Fp in 492 points
Rik
Rik el 6 de Abr. de 2019
I don't think you have any option that doesn't involve resampling one of your arrays. I haven't read the doc for interp, but there should be an option to use a spline.

Iniciar sesión para comentar.

 Respuesta aceptada

Darren Kenney
Darren Kenney el 6 de Abr. de 2019
Editada: Darren Kenney el 6 de Abr. de 2019
Solution:
times = 0:0.1:2000;
[Fp,Xp] = ecdf(distribution1);
[uniqueXp, uniqueXpIndex] = unique(Xp);
interpolatedP = interp1(uniqueXp, Fp(uniqueXpIndex), times, 'previous');
[Fv,Xv] = ecdf(distribution2);
[uniqueXv, uniqueXvIndex] = unique(Xv);
interpolatedV = interp1(uniqueXv, Fv(uniqueXvIndex), times, 'previous');

Más respuestas (0)

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Preguntada:

el 6 de Abr. de 2019

Editada:

el 6 de Abr. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by