Last active
January 25, 2018 10:32
-
-
Save slchangtw/733757f963d2bba9b01ce3f0840c4e1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iris2 <- as.matrix(iris[, 1:4]) | |
# cetralize data | |
centered_iris2 <- scale(iris2, center = TRUE, scale = FALSE) | |
# covariance matrix | |
cov_iris2 <- (t(centered_iris2) %*% centered_iris2) / (dim(centered_iris2)[1] - 1) | |
# perform eigendecomposition on covariance matrix | |
eig_cov <- eigen(cov_iris2) | |
# Compare the results | |
pca <- prcomp(iris2) | |
pca$sdev - sqrt(eig_cov$values) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment