How to estimate 95% probability contour in bivariate kernel density function MATLAB
17 次查看(过去 30 天)
显示 更早的评论
Hello:
I have fitted bivariate kernel density function using ksdensity in MATLAB and obtained contour as the method described here: https://stackoverflow.com/questions/44398251/matlab-contour-data-for-2d-normal-cumulative-probability-density
I want to show the area encompassed 95% probability field and related contour for the bivariate density field. I am looking for some thing like this as implemented in R : https://stackoverflow.com/questions/23437000/how-to-plot-a-contour-line-showing-where-95-of-values-fall-within-in-r-and-in
Does MATLAB has such facility to show 95% contours for the joint probability fields?
0 个评论
回答(1 个)
Bruno Luong
2023-9-27
编辑:Bruno Luong
2023-9-27
I'm not sure if there is a standard definition of area of 95 confidence in 2D pdf since it like asking what if the shape of 95% of the cake, one can cut in many way provide the remaning is 95%.
Assuming one cut on a level of pdf, here is one way
% Invent some fake 2D pdf
pdf=abs(peaks(100));
pdf=pdf-min(pdf,[],'all');
maxp = max(pdf,[],'all');
minp = 0;
smin = 1;
smax = 0;
spdf = sum(pdf,'all');
starget = 0.95;
sold = NaN;
while true
l = (minp+maxp)/2;
i = find(pdf >= l);
s = sum(pdf(i)) / spdf
if s > starget
minp = l;
else
maxp = l;
end
if s==sold || ... % stuck due to quantification of pixels
abs(smax-smin) < 0.001
break
end
sold = s;
end
close all
figure;
surf(pdf+10)
hold on
contourf(pdf,[l l])
Note that estimation of the integration
%i = find(pdf >= l);
%s = sum(pdf(i)) / spdf
is very crude. One can do much better but a it cumbersome to implement more precise integration.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!