Thursday, June 10, 2010

Egenvalue, PCA, SVD (Singular Value Decomposition)

http://www.gersteinlab.org/courses/545/07-spr/slides/cbb545b-spr07-bioinfo5-svd1.ppt

library(HSAUR)
data("heptathlon", package="HSAUR")
h <- heptathlon score <- which(colnames(h) == "score") h_pca <- prcomp(h[, -score], scale=T) summary(h_pca) biplot(h_pca) screeplot(h_pca) h_pca$sdev^2 / sum(h_pca$sdev^2) # variance http://cran.r-project.org/web/packages/HSAUR/vignettes/Ch_principal_components_analysis.pdf

heptathlon_pca <- prcomp(heptathlon, scale=T) plot(heptathlon_pca) # barplot of variances # get proportion of variance for each PC summary(hepathalon_pca) # linear combination of PC1 from diff. columns (events) hepathalon_pca$rotation[,1] # compute scores for each row (competitors) # score = scaled(original data) * loadings (the coefficients, rotations) # same as hepathalon_pca$x[,1] predict(hepathalon_pca)[,1] # arrows are columns, points are rows biplot(heptathlon_pca, col = c("gray", "black")) # PC1 vs PC2, A biplot allows information on both samples and variables of a data matrix to be displayed graphically, http://support.sas.com/documentation/cdl/en/imlsug/62558/HTML/default/viewer.htm#ugmultpca_sect2.htm quadrant I = NE, quadrant II = NW http://r.789695.n4.nabble.com/PCA-and-variance-explained-td866300.html
p$sdev^2 / sum(p$sdev^2)

screeplot(hepathalon_pca)

No comments: