Skip to content

Instantly share code, notes, and snippets.

@monogenea
Created October 7, 2019 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monogenea/10e7250d2c038cfa30f8c3c305941a0f to your computer and use it in GitHub Desktop.
Save monogenea/10e7250d2c038cfa30f8c3c305941a0f to your computer and use it in GitHub Desktop.
# Compare PCA scores with the SVD's U*Sigma
theoreticalScores <- mySVD$u %*% sigma
all(round(myPCA$x,5) == round(theoreticalScores,5)) # TRUE
# Compare PCA loadings with the SVD's V
all(round(myPCA$rotation,5) == round(mySVD$v,5)) # TRUE
# Show that mat == U*Sigma*t(V)
recoverMatSVD <- theoreticalScores %*% t(mySVD$v)
all(round(mat,5) == round(recoverMatSVD,5)) # TRUE
# Show that mat == scores*t(loadings)
recoverMatPCA <- myPCA$x %*% t(myPCA$rotation)
all(round(mat,5) == round(recoverMatPCA,5)) # TRUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment