# load swiss bank notes x<-read.table("bank2.dat") spr <-princomp(x) U<-spr$loadings L<-(spr$sdev)^2 Z <-spr$scores # scatterplot of input x pairs(x,pch=c(rep(1,100),rep(3,100)),col=c(rep("blue",100),rep("red",100))) # scatterplot of principal components pairs(Z,pch=c(rep(1,100),rep(3,100)),col=c(rep("blue",100),rep("red",100))) # variances of each principal component par(mfrow=c(1,2)) plot(L,type="b",xlab="component",ylab="lambda",main="Scree plot") plot(cumsum(L)/sum(L)*100,ylim=c(0,100),type="b",xlab="component",ylab="cumulative propotion (%)",main="Cum. Scree plot") # biplot par(mfrow=c(1,1)) biplot(spr, choices = 1:2, scale = 1, pc.biplot = FALSE) par(mfrow=c(1,2)) barplot(spr$loadings[,1],main="PC1 loadings") barplot(spr$loadings[,2],main="PC2 loadings") # preprocessed golub data #source("http://bioconductor.org/biocLite.R") #biocLite("multtest") data(golub, package = "multtest") dim(golub) # golub.gnames # names of genes # golub.cl # indicater for ALL (AML==0, ALL==1) # gpr <- princomp(t(golub)) gpr <- prcomp(t(golub)) U <- gpr$rotation L <- (gpr$sdev)^2 Z <- gpr$x # scatterplot of principal components pairs(Z[,1:4],pch=c(rep(1,27),rep(3,11)),col=c(rep("blue",27),rep("red",11))) pairs(Z[,1:8],pch=c(rep(1,27),rep(3,11)),col=c(rep("blue",27),rep("red",11))) # variances of each principal component par(mfrow=c(1,2)) plot(L,type="b",xlab="component",ylab="lambda",main="Scree plot") plot(cumsum(L)/sum(L)*100,ylim=c(0,100),type="b",xlab="component",ylab="cumulative propotion (%)",main="Cum. Scree plot") # biplot does not help # biplot par(mfrow=c(1,1)) biplot(gpr, choices = 1:2, scale = 1, pc.biplot = FALSE)