PCA: Difference between revisions

From RAJ INFO
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
(No difference)

Latest revision as of 09:39, 6 August 2013

Category:R

## Getting the data
> mydata <- read.table ("D:/ITC/USER/Rudresh/data/data.txt", header=T, sep="\t") 
> mydata <- na.omit(mydata) # listwise deletion of missing 
> mydata <- scale(mydata) # standardize variables

## Pricipal Components Analysis (from the correlation matrix )
> fit <- princomp(mydata, cor=TRUE, scores=TRUE )
> summary(fit) # print variance accounted for 
> loadings(fit) # pc loadings 
> plot(fit,type="lines") # scree plot 
> fit$scores # the principal components
> biplot(fit)

## Determine Number of Factors to Extract
> library(nFactors)
> ev <- eigen(cor(mydata)) # get eigenvalues
> ap <- parallel(subject=nrow(mydata),var=ncol(mydata), rep=100,cent=.05)
> nS <- nScree(ev$values, ap$eigen$qevpea)
> plotnScree(nS)

## Simple PCA analysis (PCA Variable Factor Map )
> library(FactoMineR)
> result <- PCA(mydata) # graphs generated automatically