Skip to main content

Covariant Matrices and Ellipses

· 3 min read
Kirill Vasin

By simply computing the covariance matrix and finding its eigenvectors and -values, you can determine the principal axes and the corresponding lengths of the ellipse.

Ellipses are common shapes characterized by their major and minor axes

(xh)2a2+(yk)2b2=1\frac{(x - h)^2}{a^2} + \frac{(y - k)^2}{b^2} = 1

Here, (h,k)(h, k) is the center of the ellipse, and aa and bb represent the lengths of the semi-major and semi-minor axes, respectively. In multivariate statistics, ellipses frequently appear as confidence regions, where they represent the distribution and correlation between two or more variables.

The connection between ellipses and the covariance matrix arises from the fact that the covariance matrix encapsulates the variance and covariance of data in multiple dimensions. Specifically, the covariance matrix of a set of data points can be used to determine the orientation and lengths of the ellipse that best represents the spread of the data.

Mathematically, the covariance matrix Σ\Sigma for a set of data points (xi,yi)(x_i, y_i) is:

Σ=(σxxσxyσxyσyy)\Sigma = \begin{pmatrix} \sigma_{xx} & \sigma_{xy} \\ \sigma_{xy} & \sigma_{yy} \end{pmatrix}

where σxx\sigma_{xx} and σyy\sigma_{yy} are the variances along the xx and yy axes, and σxy\sigma_{xy} is the covariance between xx and yy. The eigenvalues and eigenvectors of this covariance matrix are key to understanding the shape and orientation of the ellipse:

  • The eigenvectors indicate the directions of the ellipse's axes.
  • The eigenvalues correspond to the squared lengths of these axes.

This connection makes it surprisingly straightforward to estimate the semi-major and semi-minor axes aa and bb of an ellipse from sampled data. By simply computing the covariance matrix and finding its eigensystem, you can determine the principal axes and the corresponding lengths of the ellipse

In this code, sampleElipse generates random points distributed in the shape of an ellipse. The covariance matrix is computed from the centered data, and its eigensystem is then found. The eigenvectors provide the directions of the ellipse's axes, and the square roots of the eigenvalues give the lengths of these axes