?princomp and found something about Q-mode and R-mode principal component analysis (PCA). But honestly – I don't understand it. Can anybody explain the difference and maybe even explain when to apply which?
The difference between them is nothing to do with the type of PCA they perform, just the method they use. As the help page for
The calculation is done by a singular value decomposition of the (centered and possibly scaled) data matrix, not by using
eigenon the covariance matrix. This is generally the preferred method for numerical accuracy.
On the other hand, the
princomp help page says:
The calculation is done using
eigenon the correlation or covariance matrix, as determined by
cor. This is done for compatibility with the S-PLUS result. A preferred method of calculation is to use
x, as is done in
prcomp is preferred, although in practice you are unlikely to see much difference (for example, if you run the examples on the help pages you should get identical results).
Usually a multivariate analysis (computing correlations, extracting latents, etc.) is done of data columns which are features or questions, - while sample units, the rows, are respondents. Hence this way is called R way analysis. Sometimes, though, you may want to do multivariate analysis of responsents, while questions are treated as sample units. That would be Q way analysis.
There is no formal difference between the two, so you can manage both with the same function, only transpose your data. There are differences, however, in issues of standardization and results interpretation.
This is a general reply: I don't touch specifically the R functions
princomp because I'm not an R user and am not aware of possible differences between them.
A useful and specific documentation from Gregory B. Anderson, titled
PRINCIPAL COMPONENT ANALYSIS IN R AN EXAMINATION OF THE DIFFERENT FUNCTIONS AND METHODS TO PERFORM PCA has given more information on this topic. Updated link (7 Jan 2021).
The following two paragraph were extracted from the introduction:
In R there are two general methods to perform PCA without any missing values: (1) spectral decomposition (R-mode [also known as eigendecomposition]) and (2) singular value decomposition (Q-mode; R Development Core Team 2011). Both of these methods can be performed longhand using the functions eigen (R-mode) and svd (Q-mode), respectively, or can be performed using the many PCA functions found in the stats package and other additional available packages. The spectral decomposition method of analysis examines the covariances and correlations between variables, whereas the singular value decomposition method looks at the covariances and correlations among the samples. While both methods can easily be performed within R, the singular value decomposition method (i.e., Q-mode) is the preferred analysis for numerical accuracy (R Development Core Team 2011).
This document focuses on comparing the different methods to perform PCA in R and provides appropriate visualization techniques to examine normality within the statistical package. More specifically this document compares six different functions either created for or can be used for PCA: eigen, princomp, svd, prcomp, PCA, and pca. Throughout the document the essential R code to perform these functions is embedded within the text using the font Courier New and is color coded using the technique provided in Tinn-R (https://sourceforge.net/projects/tinn-r). Additionally, the results from the functions are compared using simulation procedure to see if the different methods differ in the eigenvalues, eigenvectors, and scores provided from the output.
They are different when both using covariance matrix. When scaling (normalizing) the training data,
prcomp uses $n-1$ as denominator but
princomp uses $n$ as its denominator. Difference of these two denominators is explained in this tutorial on principal component analysis.
Below are my test results:
> job<-read.table("./job_perf.txt", header=TRUE, sep="") > pc.cr<-prcomp(job, scale=TRUE, cor=TRUE, scores=TRUE) > pc.cr1<-princomp(job, scale=TRUE, cor=TRUE, scores=TRUE) > pc.cr$scale commun probl_solv logical learn physical appearance 5.039841 1.689540 2.000000 4.655398 3.770700 4.526689 > pc.cr1$scale commun probl_solv logical learn physical appearance 4.805300 1.610913 1.906925 4.438747 3.595222 4.316028
commun probl_solv logical learn physical appearance
12 52 20 44 48 16
12 57 25 45 50 16
12 54 21 45 50 16
13 52 21 46 51 17
14 54 24 46 51 17
22 52 25 54 58 26
22 56 26 55 58 27
17 52 21 45 52 17
15 53 24 45 53 18
23 54 23 53 57 24
25 54 23 55 58 25