PCA: Difference between revisions

From RAJ INFO
Jump to navigation Jump to search
Created page with "Category:R <pre> ## Getting the data > mydata <- read.table ("D:/ITC/USER/Rudresh/data/data.txt", header=T, sep="\t") > mydata <- na.omit(mydata) # listwise deletion of ..."
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:R]]
[[:Category:R]]


<pre>
<pre>

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