How to pick the j-th percentile of a distribution?

Hi all,
I have some data and I want to pick the j-th percentile of the distribution.
Here an example:
a=2000;
b=300;
c=a+(b)*randn(100,1);
cdfval = fitdist(arg_1, 'normal');
So how can I get the 50° percentile of the distribution, that it is 2000?
thanks

 Akzeptierte Antwort

Star Strider
Star Strider am 6 Jun. 2014

2 Stimmen

Since you have the Statistics Toolbox, use the prctile function.

5 Kommentare

pietro
pietro am 6 Jun. 2014
Bearbeitet: pietro am 6 Jun. 2014
Thanks and how can I get the equivalent value at a specific prctile? here an example:
a=2000;
b=300;
c=a+(b)*randn(100000,1);
prova=fitdist(c,'normal');
pdfval=pdf(prova,linspace(a-4*b,a+4*b,100));
prctile(pdfval,50)
the 50th percentile is the average value, that is 2000, but with prctile I get the probability. So how can I do to get the equivalent data value at a specific percentile?
Star Strider
Star Strider am 6 Jun. 2014
Bearbeitet: Star Strider am 6 Jun. 2014
My pleasure!
  1. The 50th percentile is the median value, by definition. With normally-distributed data, the mean (average) and median are approximately equal, but the interpretations of them are completely different.
  2. The prctile function gives you the data value at a specific percentile, at least according to the documentation (that I linked to in my original Answer). That is not a probability as such, but the value for which a given percentage (the percentile) of the data are less than that value.
Adding a line to your code:
a=2000;
b=300;
c=a+(b)*randn(100000,1);
prova=fitdist(c,'normal');
pdfval=pdf(prova,linspace(a-4*b,a+4*b,100));
pctval = prctile(pdfval,50)
mdnval = median(pdfval)
Note that the median is equal to the 50th percentile.
pietro
pietro am 6 Jun. 2014
I know that the 50th percentile is median, but I need to calculate the j-th percentile from the probability distribution, because I have to calculate the 95th percentile as well.
Star Strider
Star Strider am 6 Jun. 2014
Bearbeitet: Star Strider am 6 Jun. 2014
Change this line to:
pctval = prctile(pdfval,95)
to get the 95th percentile.
If you want to get every percentile from the 5th to the 95th, put the call in a loop:
a=2000;
b=300;
pdfval = a + b*randn(100000,1);
pctl = 5:5:95;
for k1 = 1:length(pctl)
pctval(k1,:) = [pctl(k1) prctile(pdfval,pctl(k1))];
end
The pctval array now has the information as:
pctval =
5.0000e+000 1.5063e+003
10.0000e+000 1.6155e+003
15.0000e+000 1.6915e+003
. . .
with the percentile in the first column and the percentile value for your data in the second column.
Take out these lines:
prova=fitdist(c,'normal');
pdfval=pdf(prova,linspace(a-4*b,a+4*b,100));
and just use the code I included here. These lines will simply make things more complicated and will give you wrong answers if your actual data are not normally distributed. The prctile function does everything you need.
Hi all, do you know how to get the confidence interval for a given percentile?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

pietro
pietro am 6 Jun. 2014

0 Stimmen

You're on right, Thanks

3 Kommentare

My pleasure!
pietro
pietro am 7 Jun. 2014
Supposing I have few numbers got by experiment that I know from a theory they are distributed according to a specific distribution. If I'm not lucky to get spread values using prctile(numbers) I'll never get the real percentile of the distribution because the percentiles are limited by the experimental data. Therefore I need to compute the percentiles from a distribution. In this case, how can I compute them? Generating casual numbers according to the fitted distribution and then using prctile?
If you know the distribution, then estimate its parameters from your experimental data (the fitdist function is probably best here) and calculate the percentiles from the cumulative distribution function for that distribution. Use the icdf function for the appropriate distribution, Don’t use prctile in that situation.

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by