Azzera filtri
Azzera filtri

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

8 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Star Strider
Star Strider il 18 Dic 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 Commenti
Tim Fulcher
Tim Fulcher il 20 Dic 2021
Thanks Star Strider. I've not finished implementation yet but so far...so good.
Regards and compliments of the season.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Statistics and Machine Learning Toolbox in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by