# Chi distribution

When studying a multi-dimensional random variable, if these are guassian the norm if the vector follows a $\chi$ distribution (see http://en.m.wikipedia.org/wiki/Chi_distribution).

In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np


This is important when one considers for instance a 2D vector which is normally distributed:

In [2]:
N = 1e3
x = np.random.randn(2, N)

In [3]:
_ = plt.scatter(x[0], x[1])

In [4]:
d = np.sqrt(x[0]**2+x[1]**2)

In [5]:
hist, bins, _ = plt.hist(d, 20)


This should be well fitted with the $\chi$-dstribution with n=2

In [6]:
p = bins * np.exp(- bins**2 / 2)
plt.bar(bins[:-1], hist/hist.sum(), width=bins[1]-bins[0])
plt.plot(bins, p/p.sum(), 'r')

Out[6]:
[<matplotlib.lines.Line2D at 0x112d81790>]

Hurray! Other visualizations for this distribution:

In [7]:
_ = plt.semilogy(bins, p/p.sum())

In [8]:
_ = plt.semilogx(bins, p/p.sum())


Comparison to other distirbutions

In [19]:
_ = plt.loglog(bins, bins, 'r--', label='lin')
_ = plt.loglog(bins, np.exp(- bins**2 / 2), 'g--', label='gaussian')
_ = plt.loglog(bins, np.exp(- np.log(bins)**2 / 2), 'r--', label='log-gaussian')
_ = plt.loglog(bins, (bins+.1)**-2, 'b--', label='power-law')
_ = plt.loglog(bins, p, label=r'$\chi$')
_ = plt.legend(loc='lower center' )

In [13]:
plt.legend?

In [ ]: