estim_ncpPCA error - length of 'dimnames' [2] not equal to array extent

348 views
Skip to first unread message

Mach Heydt

unread,
Apr 6, 2017, 12:07:26 PM4/6/17
to FactoMineR users
Hi everyone

I was recently looking for a method to impute missing data, and found missMDA.
I've read the paper and the code provided works as a charm.
I've also performed the same exact code on one of my datasets and it also works.
The dataset I'm currently using throws some errors, however.

The first I get is : Error in eigen(crossprod(X, X), symmetric = TRUE) : infinite or missing values in 'x'
I should really read up about the math behind PCA, but since there's a column consisting of only 0 and NA I assume the method doesn't work on such columns.

I assume this because, when I perform na.omit on my data (there's some columns left consisting of 0 only) and run the prcomp function it throws a similar error:
Error in prcomp.default(frame_pca, scale = T, center = T) : cannot rescale a constant/zero column to unit variance

So when removing that column and running ncpPCA again, I get the error:
Error in matrix(unlist(value, recursive = FALSE, use.names = FALSE), nrow = nr,  : length of 'dimnames' [2] not equal to array extent

Googling the error I stumble upon a lot of problems involving matrix operations, and mainly people trying to perform operations with unequal matrices etc.
So why does this pop up here? I've seen a couple of these posts in this group already, but I know I haven't got any columns that represent the rownames or ids or anything, and I checked that all my data is numeric.
I don't know how I can copy an example, but I would rather like to know what this error means, than have a direct solution, although that is also very helpful ofcourse!
Thanks!

Mach Heydt

unread,
Apr 13, 2017, 10:51:15 AM4/13/17
to FactoMineR users
So

A colleague who came back from holiday took a look at my code and data, but had no experience with the missMDA package. 
The column I removed, who gave the 'Error in eigen(crossprod(X, X), symmetric = TRUE) : infinite or missing values in 'x'' error, was actually the only column with missing data (and zeros), and I did not notice that.

When my colleague noticed that he asked why I would still use the missMDA package to perform pca if I had no missing values. We then added a random missing value in the set and the code worked again without throwing errors.
However, the help window of R shows that for estim_ncpPCA x can be data with or without missing data.

So, apparently the package doesn't work on data without missing values? Is that possible? 
grtz

Alex Adler

unread,
Apr 26, 2018, 11:19:37 AM4/26/18
to FactoMineR users
I was running into the same strange issue and came across your post (a year later!).

I had a perfectly formed/cleaned data.frame with no missing values and received the length of dimnames error. So I tried your fix and added a random NA to one cell in the data frame.

Lo and behold, that let it run. Strange bug!

// AA

Alex Adler

unread,
Apr 26, 2018, 1:48:10 PM4/26/18
to factomin...@googlegroups.com
Actually, for what it’s worth, I posted on the author’s blog and he recommended using FactoMineR’s estim_ncp() for cases where the data frame is not missing values.

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "FactoMineR users".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse factominer-use...@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages