Dimensional analysis

Principal compenent analysis (PCA)

There are two function in the basics stats package prcomp() and princomp() and three functions in packages from the French school of data analysis PCA() {FactoMineR} dudi.pca() {ade4} and acp() {amap}.

You will have to look up the documentation for the details, below you will only find some examples for the most common tasks.

princomp (prcomp) performs a principal components analysis on a numeric data matrix and returns the results as an object of class princomp (prcomp).

- princomp(~urb+infmor+lifeem+gnpcap+gnpagr+gnpserv+lit,data=world) Perform a PCA (you can also supply a matrix index of a list of variables (formula style).
- princomp(~urb+infmor+lifeem+gnpcap+gnpagr+gnpserv+lit,data=world, cor=TRUE, scores=TRUE) same, but use correlation matrix (default covariance matrix) and produce factor scores
- pca <- princomp(~urb+infmor+lifeem+gnpcap+gnpagr+gnpserv+lit,data=world, cor=TRUE, scores=TRUE) same, results are stored into pca
- plot(pca) Histogram of the eigenvalues
- summary(pca) display summary of results

Plotting loadings and scores

- plot(pca$scores) simple plot of the scores stored in the princomp object
- plot(pca$loadings) simple plot of the loadings stored in the princomp object
- bibplot(pca) Produce a biplot (with both scores and loadings (Gabriel's biplot)

A nicer plot for the scores (using {ggplot2}

- scores <-as.data.frame(pca$scores) assign the scores to an object (ggplot requires a data frame)
- ggplot(data = scores, aes(x = Comp.1, y = Comp.2, label = rownames(scores))) + geom_text(colour = "blue", alpha = 0.8, size = 2) + ggtitle("PCA of some world data")

A simple loadings plot with labels (using base graphics); plots by default the first two components

- loadings <-as.matrix(pca$loadings)
- plot(loadings)
- text(loadings,labels=rownames(loadings))

Other factor analytical and dimensional techniques

Note this section is very sketchy; there is a lot more in the R Universe

- factanal() {stats} for factor analysis
- Packages FactoMineR and ade4 have many techniques related to correspondence analysis. There is also an explor package for interactive examination and plotting of results from both packages (shiny application).
- cmdscale() {stats} for classical MDS
- isoMDS() {MASS} for Nonmetric MDS
- indscal() {SensoMineR} for individual difference scaling; see also the smacof package).