Algorithm for conducting principal component analysis