フィルターのクリア

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

8 ビュー (過去 30 日間)
Tim Fulcher
Tim Fulcher 2021 年 12 月 18 日
コメント済み: Star Strider 2021 年 12 月 20 日
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 Center および File ExchangeStatistics 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