PCA & PCA: Get angle between pc1-pc2 planes

A command to calculate the angle between two planes. Each plane is spanned by the first two eigenvectors from the corresponding PCA.

Algorithm

The algorithm is described in section 12.4.3 of Golub & van Loan (1996):

First we form the projection of one set of eigenvectors on the other set. This results in a 2×2 matrix C:

C = E1E2,

where E1 and E2 are 2×dimension and dimension×2 matrices that contain the first two eigenvectors of the PCA's, respectively.

Next, we compute the singular value decomposition of C:

C = U Σ V

Now the cosine of the angle between the two planes is given by σ2 and the angle in degrees is therefore:

arccos (σ2)·180/π

© djmw, October 28, 2004