Say I have a 2D Gaussian with μ=(μ1,μ2)
For example
p = {m1 -> 1.5, m2 -> -0.5, s11 -> 0.5, s22 -> 0.5, r -> -0.2};
ContourPlot[
PDF[MultinormalDistribution[{m1, m2}, {{s11^2, r s11 s22}, {r s11 s22, s22^2}}] /. p, {x, y}],
{x, 0, 3.}, {y, -2, 1},
Contours -> {0.2}, ContourShading -> None]
[Contours -> {0.2}
inserted only for illustration, just to have any number to make a plot.]
How can I plot the 1σ contour of the 2D Gaussian? It encompasses ≈0.39 of the volume under the surface (being analogous to the 0.68 fraction marking the 1σ region in the 1D Gaussian case).
So, the precise questions are (a) at what height of the PDF should I place the 1σ contour? (Note: I can extract the maximum max
of the PDF and easily plot, e.g., the contour corresponding to FWHM with Contours -> {1/2 max}
.) And, if it's not that straightforward, my next idea would be (b) to to find the proper value via numerical integration (how to set this up?).
Answer
I don't know what a "1σ contour of the 2D Gaussian" is but if you want a specific volume (between 0 and 1), then the following will get you the contour height for the bivariate normal:
p = {m1 -> 1.5, m2 -> -0.5, s11 -> 0.5, s22 -> 0.5, r -> -0.2};
(* Contour of interest *)
α = 0.39 (* Desired volume *)
c = Exp[-InverseCDF[ChiSquareDistribution[2], α]/2]/(2 π s11 s22 (1 - r^2)) /. p
ContourPlot[PDF[MultinormalDistribution[{m1, m2}, {{s11^2, r s11 s22}, {r s11 s22, s22^2}}] /. p, {x, y}],
{x, 0, 3.}, {y, -2, 1}, Contours -> {c}, ContourShading -> None]
(* As a check: Do the integration... *)
pdf = PDF[MultinormalDistribution[{m1, m2}, {{s11^2, r s11 s22}, {r s11 s22, s22^2}}], {x, y}] /. p;
xmin = m1 - 10 s11 /. p;
xmax = m1 + 10 s11 /. p;
ymin = m2 - 10 s22 /. p;
ymax = m2 + 10 s22 /. p;
NIntegrate[pdf Boole[((x - m1)^2/s11^2 + (y - m2)^2/s22^2 - 2 r (x - m1) (y - m2)/(s11 s22))/(1 - r^2) <=
InverseCDF[ChiSquareDistribution[2], α] /. p], {x, xmin, xmax}, {y, ymin, ymax}]
(* 0.39 *)
Comments
Post a Comment