why my kernel density function never touches x axes?

조회 수: 2 (최근 30일)
Poulomi Ganguli
Poulomi Ganguli 2021년 1월 28일
답변: the cyclist 2021년 1월 28일
Hello:
I want plot kernel density function with the attached test data. I have used foll. code:
Xgrid1 = linspace(min(X),max(X),1000);
pdfEst_1 = ksdensity(X,Xgrid1,'function','pdf');
plot(Xgrid1,pdfEst_1,'Color','B','linew',1.8);
However, the generated density function never touches the x-axes & always moves up, without any closed bounds. Any possible ways that the generated PDFs touches x - axes?
  댓글 수: 4
the cyclist
the cyclist 2021년 1월 28일
Is that what is in the file Test1? Just those 15 data points?
It will depend on the kernel you choose, but the estimated density will be zero (or approach zero) as you move away from where the function has support. You haven't defined any grid points that are far away from where X has support.
Poulomi Ganguli
Poulomi Ganguli 2021년 1월 28일
Got it. Thanks!

댓글을 달려면 로그인하십시오.

채택된 답변

the cyclist
the cyclist 2021년 1월 28일
Now that we've clarified some things, let me capture my reply in an actual answer.
The issue is that you have defined your X range to cover only places where the estimated PDF has support, because you actually have some data there. If, instead, you extend the range far enough away from the data, then the estimated PDF will go to zero (or at least approach zero).
For example:
extendRange = (max(X)-min(X))/2;
Xgrid1 = linspace(min(X) - extendRange,max(X) + extendRange,1000);
pdfEst_1 = ksdensity(X,Xgrid1,'function','pdf');
figure
plot(Xgrid1,pdfEst_1,'Color','B','linew',1.8);
Exactly how far out you need to go will depend on the kernel you choose for ksdensity.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by