Interpreting covariance in bivariate normal plot

69 Views Asked by At

I am a newbie in stats, and after much searching, I found this site: https://demonstrations.wolfram.com/TheBivariateNormalDistribution/

It is great, and I guess it cannot get more basic than that, but I still have questions.

Whenever I increase variance in only one variable, I undoubtedly feel/see that the variance of the other variable decreases, and I know this is not happening, why am I seeing this? Is this just me?

(I found many different plots, but nowhere it's explained exactly how to interpret/see the plot).

1

There are 1 best solutions below

0
On BEST ANSWER

This is an unfortunate effect of the color values changing, as a result of the distribution changing. Maybe this representation will help you see the effect more clear:

enter image description here

In the gif I normalized each frame by the maximum value of the distribution and project on each axis. This link has a pretty good description of what's happening, in particular see the Marginal Distribution section.

If you pay close attention to the projection on the $X$ axis while $\sigma_Y$ is increased, the envelope (green contour) keeps the same width, which means that the variance is not being modified.

Code was generated in python, here is MWV:

import numpy as np
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import matplotlib

matplotlib.rcParams['text.usetex'] = True

xmin, xmax = [-4, 4]
ymin, ymax = [-4, 4]
zmin = -0.05
zmax = 1.05

def get_normal(mux = 0, muy = 0, sigmax = 1.5, sigmay = 1, rho = 0):

    x = np.linspace(xmin, xmax, num = 200)
    y = np.linspace(xmin, xmax, num = 200)
    x, y = np.meshgrid(x, y)

    f = (x - mux)**2 / sigmax**2 + (y - muy)**2 / sigmay**2 \
        - 2 * rho * (x - mux) * (y - muy) / (sigmax * sigmay)
    f /= -2 * (1 - rho**2)
    f = np.exp(f) / (2 * np.pi * sigmax * sigmay * np.sqrt(1 - rho**2))

    return x, y, f / f.max()


sigmax = 1.5
sigmay = 0.5
mux = 0
muy = 0
rho = 0

fig = plt.figure()
ax = fig.gca(projection = '3d')

x, y, z = get_normal(mux = mux, muy = muy, sigmax = sigmax, sigmay = sigmay)

ax.plot_surface(x, y, z, cstride = 4, alpha = 0.5, cmap = matplotlib.cm.jet)
cset = ax.contour(x, y, z, zdir = 'z', offset = zmin, cmap = matplotlib.cm.jet)
cset = ax.contour(x, y, z, zdir = 'x', offset = xmin, cmap = matplotlib.cm.jet)
cset = ax.contour(x, y, z, zdir = 'y', offset = ymax, cmap = matplotlib.cm.jet)


ax.set_xlabel(r'$x$')
ax.set_xlim(xmin, xmax)
ax.set_ylabel(r'$y$')
ax.set_ylim(xmin, xmax)
ax.set_zlabel(r'$f(x, y) / f_{\max}$')
ax.set_zlim(zmin, zmax)
plt.show()