Obtaining a list of percentages/cumulative probabilities from a data vector given the percentile/quantile values

19 vues (au cours des 30 derniers jours)
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?

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 8 Oct 2022
Modifié(e) : MathWorks Support Team le 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);

Plus de réponses (0)

Tags

Aucun tag saisi pour le moment.

Produits


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by