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
Here, is the center of the ellipse, and and 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 for a set of data points is:
where and are the variances along the and axes, and is the covariance between and . 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 and 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