How to calculate the 95% (area under the curve) of Kernel probability density curve?

Hi everyone,
I require to plot the kernel density curve and mark its 5% and 95% values on the plot. I attempted but not working (my script is attached) May someone suggest to me how can I fix this?
raw=readmatrix('5_95.csv');
a=raw(:,4);
figure(1)
pdSix = fitdist(a,'Kernel','Width',0.5);
x = -5:0.01:5;
ySix = pdf(pdSix,x);
plot(x,ySix,'k-','LineWidth',2)
The espected output should be like this.

 Risposta accettata

Paul
Paul il 10 Lug 2022
Modificato: Paul il 10 Lug 2022
The function icdf can find the values of x such that P(X < x) = 0.05 and 0.95.
Use those values with xline to add the vertical lines to the plot.

5 Commenti

I attempted but did not work in my case, may you please provide a bit more detail. Thank you!
Why not show the code?
Here is an example based on the doc
SixMPG = [13;15;23;29;32;34];
pdSix = fitdist(SixMPG,'Kernel','Width',4);
x = 0:.01:45;
ySix = pdf(pdSix,x);
plot(x,ySix,'k-','LineWidth',2)
hold on
xvals = icdf(pdSix,[0.05 .95])
xvals = 1×2
9.7202 37.4349
xline(xvals,'r')
% verify xvals (approximately)
trapz(x(x<xvals(1)),ySix(x<xvals(1)))
ans = 0.0499
trapz(x(x<xvals(2)),ySix(x<xvals(2)))
ans = 0.9498
Thanks a lot this works for my case, i jsut wounder how can i specify the kernel type e.g. normal or gaussian kernal along with the bandwidth option.
According to fitdist
pdSix = fitdist(SixMPG,'Kernel','Kernel,',kernel,'Width',4);
where kernel is one of:
  • 'normal'
  • 'box'
  • 'triangle'
  • 'epanechnikov'

Accedi per commentare.

Più risposte (0)

Prodotti

Tag

Richiesto:

il 10 Lug 2022

Commentato:

il 16 Lug 2022

Community Treasure Hunt

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

Start Hunting!

Translated by