Obtaining a list of percentages/cumulative probabilities from a data vector given the percentile/quantile values
4 views (last 30 days)
Show older comments
MathWorks Support Team
on 14 Apr 2016
Edited: MathWorks Support Team
on 8 Oct 2022
The "prctile" and "quantile" functions compute percentile and quantile values from a given data vector. How can I perform the inverse operation, i.e. provide a list of values and get the corresponding percentages/cumulative probabilities?
Accepted Answer
MathWorks Support Team
on 8 Oct 2022
Edited: MathWorks Support Team
on 8 Oct 2022
While MATLAB does not include an inbuilt function to accomplish this, it is possible to write some simple code to do so. The following page of the MATLAB documentation provides details of the algorithm used by the "prctile" and "quantile" functions.
The following code can be used to reverse these algorithms to arrive at the percentage and cumulative probability values given a data vector "X" and a list of percentile or quantile values "Y".For "prctile",
>> sortedX = sort(X);
>> listPercentages = (100/length(X))*(0.5:1:length(X)-0.5);
>> percentages = interp1(sortedX,listPercentages,Y);
For "quantile",
>> sortedX = sort(X);
>> listCumProb = (1/length(X))*(0.5:1:length(X)-0.5);
>> cumProbs = interp1(sortedX,listCumProb,Y);
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!