How to estimate 95% probability contour in bivariate kernel density function MATLAB
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Bruno Luong
le 27 Sep 2023
Modifié(e) : Bruno Luong
le 27 Sep 2023
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.
0 commentaires
Voir également
Catégories
En savoir plus sur Contour Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!