How to pick the j-th percentile of a distribution?
43 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
pietro
el 6 de Jun. de 2014
Comentada: Marco Soldati
el 4 de Abr. de 2018
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
0 comentarios
Respuesta aceptada
Star Strider
el 6 de Jun. de 2014
5 comentarios
Star Strider
el 6 de Jun. de 2014
Editada: Star Strider
el 6 de Jun. de 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.
Marco Soldati
el 4 de Abr. de 2018
Hi all, do you know how to get the confidence interval for a given percentile?
Más respuestas (1)
pietro
el 6 de Jun. de 2014
3 comentarios
Star Strider
el 7 de Jun. de 2014
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.
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!