Diego Aguado
Diego Aguado

Reputation: 1596

0 x 0 matrix when running PCA in FactoMineR

I'm trying to run a principal component analysis (PCA) indicating the quantitative data and the qualitative data, but I get this error when performing:

library(FactoMineR)
pca(data, quanti.sup = 4:12, quali.sup = 1:3, scale.unit = FALSE, ncp=2)

Error in eigen(t(X)%*%X, symmetric = TRUE): = 0x0 matrix

My data is a 2980 x 12 data frame with names, so it's really weird. Any advice would be very much appreciated.

Upvotes: 0

Views: 4553

Answers (1)

LJW
LJW

Reputation: 815

The problem you encountered is because you have specified all of your variables as supplementary variables when you call PCA().

To illustrate with an example we can use the built in dataset USJudgeRatings.

head(USJudgeRatings)
               CONT INTG DMNR DILG CFMG DECI PREP FAMI ORAL WRIT PHYS RTEN
AARONSON,L.H.   5.7  7.9  7.7  7.3  7.1  7.4  7.1  7.1  7.1  7.0  8.3  7.8
ALEXANDER,J.M.  6.8  8.9  8.8  8.5  7.8  8.1  8.0  8.0  7.8  7.9  8.5  8.7
ARMENTANO,A.J.  7.2  8.1  7.8  7.8  7.5  7.6  7.5  7.5  7.3  7.4  7.9  7.8
BERDON,R.I.     6.8  8.8  8.5  8.8  8.3  8.5  8.7  8.7  8.4  8.5  8.8  8.7
BRACKEN,J.J.    7.3  6.4  4.3  6.5  6.0  6.2  5.7  5.7  5.1  5.3  5.5  4.8
BURNS,E.B.      6.2  8.8  8.7  8.5  7.9  8.0  8.1  8.0  8.0  8.0  8.6  8.6

In this data there are 43 judges who were ranked on 11 qualities by lawyers (columns 2:12). Column 1 is the number of contacts the lawyers had with the judge.

The PCA won't work if you specify that all variables are supplementary.

library(FactoMineR)
result <- PCA(USJudgeRatings, ncp = 3, quanti.sup = 1:12)
# Error in eigen(t(X) %*% X, symmetric = TRUE) : 0 x 0 matrix

We have to give the PCA some variables to work with. Instead, we let our 11 variables go into the PCA and specify only the number of contacts the lawyers had with the judges as a quantitative supplementary variable:

result <- PCA(USJudgeRatings, ncp = 3, quanti.sup = 1)

This runs and you can then view the results with summary.PCA(result).

Upvotes: 1

Related Questions