Define distribution function to be zero if ecdf(X) is not defined

I have a distribution of random numbers X in the interval [50,100]. When using the function ecdf(X) to receive the empirical cumulative distribution function, the values for x<50 are not defined.
I the following, I want to integrate (1-ecdf(X)) from 0 to infinity and therefore need the ecdf(X) to be zero.
Is there a possibility to define the ecdf(X) to be zero for x<50?

 Accepted Answer

[f,x] = ecdf(X);
Ecdf=@(p) interp1(x,f,p)*(p>=50)
Best wishes
Torsten.

6 Comments

Thank your for your answer, it makes sense, but I have trouble implementing this in my specific case, since I already used the interpl-function...would be great if you could help with the following code:
g=0.1;
h=0.2;
a = 50;
b = 100;
R = (b-a).*rand(100,1) + a;
[distribution_neutral,x]=ecdf(R);
distribution_distorted= 1-(1-distribution_neutral).^(1/(1+g)).^(1+h);
x(1)=-realmax;
fun3= @(xq) interp1(x,distribution_distorted,xq,'previous','extrap');
final_value=integral(fun3,0,inf);
Why not simply
g = 0.1;
h = 0.2;
a = 50;
b = 100;
R = (b-a).*rand(100,1) + a;
[distribution_neutral,x]=ecdf(R);
distribution_distorted= 1-(1-distribution_neutral).^(1/(1+g)).^(1+h);
final_value = trapz(x,distribution_distorted)
?
And note that
a^b^c = a^(b^c).
I don't know if this is really what you want in the expression
(1-distribution_neutral).^(1/(1+g)).^(1+h)
Best wishes
Torsten.
Thank you for your quick answer! Unfortunately, this simple solution is not possible because my distribution function is decreasing from 1 to 0 and not increasing from 0 to 1. Thus for an integration in the interval of [0:inf] the area for x<50 needs to be defined as 1. Sorry for the confusion, would be thankful for any further advice!
A CDF must always increase from 0 to 1.
And your "distribution_distorted" does:
For x<50, it must be defined as 0, for 50<x<100, it increases from 0 to 1, and for x>100, it must equal 1.
Just use
plot(x,distribution_distorted)
Best wishes
Torsten.
You are totally right, but the problem is that the CDF in my plot seems to be not defined as 0 for x<50. Before integrating I calculate 1-CDF and therefore get the decreasing function...
If you integrate from the first x-value to the last x-value (as the command
"trapz(x,Distribution_distorted)"
does), you automatically ensure that the CDF is counted to be zero outside the interval where its mass is concentrated (namely outside [x(1);x(end)]). And I guess this is what you want.
Best wishes
Torsten.

More Answers (0)

This question is closed.

Asked:

on 9 Nov 2017

Closed:

on 17 Apr 2018

Community Treasure Hunt

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

Start Hunting!