0

I am graphing a contour plot of MVN density using Python. The code is copied below but my question can be answered without reading the code.

import numpy as np
from scipy.stats import multivariate_normal as mvn
import matplotlib.pyplot as plt
D = 2
x = np.random.rand(D)
mu = np.random.rand(D)
A = np.random.rand(D,D)
# random symmetric matrix
cov = A.T.dot(A)

# Generate grid points
x, y = np.meshgrid(np.linspace(-1,2,100),np.linspace(-1,2,100))
xy = np.column_stack([x.flat, y.flat])

# density values at the grid points
Z = mvn.pdf(xy, mu, cov).reshape(x.shape)

# arbitrary contour levels
contour_level = [0.1, 0.2, 0.3]

fig = plt.contour(X, Y, Z, levels = contour_level)

I am trying to pick a meaningful levels of the contour plot (i.e., the curve with the same density value). In the univariate case, $\pm \sigma$ and 2$\sigma$ represent 68% and 95% of the data, respectively.

Is there an analogous concept for the bivariate normal distribution such that with in the first contour line, some percentage of data is contained and so on?

zcadqe
  • 3
  • It comes down to using chi-squared quantiles to identify the size of the required ellipsoid (ellipse for the bivariate) defined by $(x-\mu)^\prime \Sigma^{-1} (x-\mu)=q_{1-\alpha}$. See https://stats.stackexchange.com/questions/69350/about-trivariate-normal-distribution and https://stats.stackexchange.com/questions/64680/how-to-determine-quantiles-isolines-of-a-multivariate-normal-distribution – Glen_b Aug 01 '17 at 05:14

0 Answers0