Solved – How to obtain the angle of rotation produced by a PCA on a 2D dataset

pcar

I want to find the principal direction in a set of spatial coordinates (i.e. in a 2D table). To do so I'm using PCA implemented in prcomp (because it allows missing values). prcomp returns a 'rotation' matrix which is said to be

the matrix of variable loadings (i.e., a matrix whose columns contain the eigenvectors).

From this, I would like to calculate the angle of the rotation achieved by the PCA, expressed as the clockwise angle from the North direction. I know the information is there, but I cannot get the calculation right. Any help would be appreciated.

EDIT: It seems that deg(asin(abs(rotation[1,1]))) works. My understanding of what I read elsewhere led me to that solution, but I don't feel like I would be able to correctly spell out an explanation for the benefit of others.

Best Answer

In a 2D case, the rotation matrix is $2\times 2$ and contains two eigenvectors as its columns. The first eigenvector $(x,y)$ is given by the first column. Its angle to the horizontal axis (abscissa) is given by $$\alpha = \operatorname{arctan} (y/x).$$As all eigenvectors are scaled to have unit length, this is equal to $$\alpha = \operatorname{arccos} (x/1)=\operatorname{arccos} (x).$$ You might call it a "counterclockwise" angle "from the East direction". If you want a "clockwise" angle "from the North direction", then you need $$\beta = 90^\circ - \alpha=90^\circ - \operatorname{arccos} (x)= \operatorname{arcsin} (x).$$ In R, it should be:

beta = asin(pc$rotation[1,1])*180/pi

which is more or less your formula too.

PCA angles in 2D