How can I calculate the empircal CDF from an empirical PDF when dimensions are greater than 2?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
I would like to calculate the empirical cumulative distribution of a data set with more than 2 dimensions. The only examples I have been able to find are for bivariate data (using hist3 and cumsum). Below is an example 3 dimensional PDF. I would like a robust solution that can accommodate any number of dimensions, if possible. Any help would be very much appreciated. Thank you.
sPDF(1,1,1) = 1;
sPDF(2,1,1) = 2;
sPDF(1,2,1) = 3;
sPDF(2,2,1) = 4;
sPDF(1,1,2) = 5;
sPDF(2,1,2) = 6;
sPDF(1,2,2) = 7;
sPDF(2,2,2) = 8;
Accepted Answer
Star Strider
on 28 Jul 2014
10 Comments
Greg
on 28 Jul 2014
Thank you for your response, but this is not what I am asking for. This calculates the CDF for continuous multivariate normal distributions. I am looking for a solution that calculates the empirical CDF based on a multidimensional PDF (this is sometimes referred to as the Probability Mass Function).
Star Strider
on 28 Jul 2014
The only option I can suggest in that situation are the Nonparametric and Empirical Probability Distributions.
Greg
on 28 Jul 2014
For a bivariate example, the following works great to find the joint cumulative distribution function (the discrete form, which is all I need):
CDF = cumsum(cumsum(PDF,1),2);
Unfortunately, cumsum doesn't support > 2 dimensions. Perhaps I should be asking whether anyone can provide me an N-Dimensional cumsum function?
Star Strider
on 28 Jul 2014
I would use the cumtrapz function. You will probably have to apply it in as many dimensions as you have in your matrix. (It will produce a result that is one less dimension than its argument.) I doubt there is anything else in core MATLAB that will do what you want. I’ve used cumtrapz to integrate volumes, but not beyond three dimensions.
Greg
on 28 Jul 2014
Thanks again Star, I'll read through that function. Also, after much googling, I happened to come across the open source program FreeMat, and they have a CumSum function that supports multiple dimensions. This probably warrants a new question, but don`t suppose anyone is able to replicate it in Matlab easily? It produces the result I am expecting.
I used it as follows for a 3 dimensional example:
--> CDF = cumsum(sPDF,1);
--> CDF = cumsum(CDF,2);
--> CDF = cumsum(CDF,3);
--> CDF = CDF./36 ...where 36 is the sum of CDF
Star Strider
on 28 Jul 2014
Edited: Star Strider
on 28 Jul 2014
My pleasure!
The cumsum function can do that. From the cumsum documentation:
- B = cumsum(A,dim) returns the cumulative sum of the elements along dimension dim . For example, if A is a matrix, then cumsum(A,2) returns the cumulative sum of each row.
From the cumtrapz documentation, it can do that as well:
- Z = cumtrapz(_,dim) integrates across the dimension of Y specified by scalar dim , using any of the input arguments in the previous syntaxes. The length of X must be the same as size(Y,dim) .
You simply have to ask them!
Greg
on 28 Jul 2014
Wow. Well that is embarrassing. I thought I tried that earlier... Thank you very much! Recursively calling cumsum is the answer. Thank you for your time and help Star.
Star Strider
on 29 Jul 2014
My pleasure!
I didn’t completely understand what you wanted (my fault) or I’d have suggested it earlier.
Peter Mills
on 23 Feb 2018
What if I want to calculate the empirical cdf from an empirical pdf. Basically the question above but with data containing NaN's. I've tried cumsum but I get NaN's for every value after the first NaN value
Greg
on 23 Feb 2018
You could try interpolating the NaN values first. Something like the following: inpaint This one may also work: inpainting Or you could try fitting a neural network to the data and predict those NaN values.
More Answers (0)
Categories
Find more on Piecewise Linear Distribution in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)