PCA: Difference between revisions
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 |
||
| Line 1: | Line 1: | ||
[[Category:R]] | [[:Category:R]] | ||
<pre> | <pre> | ||
Revision as of 09:25, 6 August 2013
## 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