Determining 1, 2 and 3 sigma radii for a bivariate Gaussian histogram
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tim Fulcher
am 18 Dez. 2021
Kommentiert: Star Strider
am 20 Dez. 2021
Hi all,
I've a 2d scatter plot which I've converted into a 2d histogram using scatter_kde (credit: Nils). I'd like to know whether it's possible to determine the 1, 2 and 3 sigma radii for the 2d histogram? It would also be useful if I could quantify the "roundness" of those circles.
Thanks and compliments of the season.
Tim
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/838230/image.jpeg)
0 Kommentare
Akzeptierte Antwort
Star Strider
am 18 Dez. 2021
If the point positions are in matrix format (or can be interpolated to matrix format using griddata or a similar function), the contour function would likely be appropriate. Set the contours to be whatever values are desired.
Example —
xv = linspace(-30, 30);
yv = linspace(-40, 40);
[Xm,Ym] = ndgrid(xv, yv);
zfcn = @(x,y) exp(-(x/15).^2) + exp(-(y/20).^2);
Zm = zfcn(Xm,Ym) + randn(size(Xm))*0.25;
Xm(Zm < 1) = NaN;
Ym(Zm < 1) = NaN;
Zm(Zm < 1) = NaN;
Zmm = mean(Zm(:),'omitnan');
sgma1 = std(Zm,1,1,'omitnan');
sgma1m = mean(sgma1);
sgma2 = std(Zm,1,2,'omitnan');
sgma2m = mean(sgma2);
NoNaN = ~isnan(Zm);
Xmn = Xm(NoNaN);
Ymn = Ym(NoNaN);
Zmn = Zm(NoNaN);
xvi = linspace(-30, 30, 25);
yvi = linspace(-40, 40, 25);
[Xi,Yi] = ndgrid(xvi, yvi);
Zi = griddata(Xmn(:), Ymn(:), Zmn(:), Xi, Yi);
figure
scatter3(Xm(:), Ym(:), Zm(:), [], Zm(:), 'Marker','.')
xlabel('X')
ylabel('Y')
hold on
surf(Xi, Yi, Zi, 'FaceAlpha',0.75, 'EdgeColor','k')
contour3(Xi, Yi, Zi, Zmm+[0.15 0.30 0.45], '-r', 'LineWidth',5)
hold off
grid on
figure
scatter3(Xm(:), Ym(:), Zm(:), [], Zm(:), 'Marker','.')
xlabel('X')
ylabel('Y')
view(0,90)
hold on
contour3(Xi, Yi, Zi, Zmm+[0.15 0.30 0.45], '-r', 'LineWidth',2.5)
hold off
grid on
This is definitely not a perfect illustration of the data, however it illustrates the approach.
.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!