1

I've been applying PCA to some data sets and in all previous cases, the number of principal components generated by prcomp() was always equal to the number of original variables (m). However, I've stumbled upon this case where the number of PCs computed is less than m.

In this case, my data set has 40 variables (including the class label in the m-th column) and 36 observations. My code for applying PCA is:

data = read.csv("datasets/chemical/chocolate.csv", sep=",", dec=".")
m = length(data)
n = nrow(data)

pca = prcomp(data[,-m], scale=FALSE)
loadings = pca$rotation
scores = pca$x

But only 36 principal components were computed this time. So the loadings matrix returned by pca$rotation was 39x36.

Why does it happen? Why did prcomp() compute fewer principal components than the number of original variables in this particular case? Is this an issue with my code or with my data?

Camila
  • 11
  • 3
  • Please do not re-post your question: improve the original instead. – whuber Aug 21 '18 at 15:48
  • 1
    @whuber I tried to, but it has been blocked and I couldn't edit it. – Camila Aug 21 '18 at 19:34
  • I am very sorry about that, Camila. This happened automatically because your original post arrived here *via* migration from another SE site, and I didn't catch it. I believe I have now "unlocked" the post, which ought to enable you to modify it as you wish. If you cannot, please flag the post for further moderator attention. – whuber Aug 21 '18 at 19:58

0 Answers0