필터 지우기
필터 지우기

Determining 1, 2 and 3 sigma radii for a bivariate Gaussian histogram

조회 수: 8 (최근 30일)
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

채택된 답변

Star Strider
Star Strider 2021년 12월 18일
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
Tim Fulcher
Tim Fulcher 2021년 12월 20일
Thanks Star Strider. I've not finished implementation yet but so far...so good.
Regards and compliments of the season.
Star Strider
Star Strider 2021년 12월 20일
As always, my pleasure!
Thank you! And to you, too!
.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by