How to integrate a distribution function for a specific interval?

I computed two distribution function:
[distribution_1,x]=ecdf(X); Distribution_2= f(distribution_1);
Now I want to integrate Distribution_2 over the interval [a,b] and tried to use q = integral(fun,xmin,xmax) but I have trouble creating the function handle "fun" in my specific case (since I cannot create the connection to x?)
Thankful for any advice!

5 个评论

Is Distribution_2 also a CDF? Just to be clear, are you trying to integrate the CDF or integrate the corresponding PDF (which you could do by differencing two points on the CDF).
Concerning the distortion function f: Distribution_2=1-(1-distribution_1.^(1/(1+g))).^(1+h) eg. with g=0.1 and h=0.2

 采纳的回答

To make your empirical CDF into a function that integral can use, you should interpolate distribution_2. Because of the way the CDF is defined, I recommend you interpolate based on the previous value. The first value of x is a duplicate of the second, but for use with interp1(..., 'previous') it should be a (finite) number less than any you plan to use. -realmax should do the trick.
x(1) = -realmax;
f_dist2 = @(new_x) interp1(x, distribution_2, new_x, 'previous', 'extrap');
integral(f_dist2, -1, 1)

3 个评论

Here is the code I used for testing:
X = randn(100, 1); % sample data
[distribution_1, x] = ecdf(X);
g=0.1;
h=0.2;
distribution_2 = 1-(1-distribution_1.^(1/(1+g))).^(1+h);
cla
stairs(x, distribution_1)
hold all
stairs(x, distribution_2)
hold off
x(1) = -realmax;
f_dist2 = @(new_x) interp1(x, distribution_2, new_x, 'previous', 'extrap');
f_dist2(0)
f_dist2([-10, 10])
integral(f_dist2, -1, 1)
integral(f_dist2, -10, 10)
Thank you very much! This was exactly what I needed =)
Another problem came up for the code when using integral(f_dist2,0,inf). Do I need to take into account anything extraordinary in this infinity case? Would be very pleased to receive another answer :)
Below the warning I get when running the code: Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 1.7e-04. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.

更多回答(1 个)

Hi Nina,
If this is not a misinterpretation of the problem, then it seems to work. I am assuming that the function ecdf is already on the Matlab path.
g = .1; h = .2;
fun = @(x) 1-(1-ecdf(x).^(1/(1+g))).^(1+h)
integral(@(x) fun(x), 2,3)
function a = ecdf(x) % for demo purposes
a = sin(x);
end
I'm curious about the idea of integrating a cdf, could you perhaps comment on that?

1 个评论

Hi David, thanks for your answer, your code would work if X=x, but this is not the case here: Interpolation can solve this problem as described by Robert below :)

此问题已关闭。

提问:

2017-11-6

关闭:

2018-4-17

Community Treasure Hunt

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

Start Hunting!

Translated by