添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm trying to run an MCA on a datatable using FactoMineR. It contains only 0/1 numerical columns, and its size is 200.000 * 20.

require(FactoMineR)
result <- MCA(data[, colnames, with=F], ncp = 3)

I get the following error :

Error in which(unlist(lapply(listModa, is.numeric))) : argument to 'which' is not logical

I didn't really know what to do with this error. Then I tried to turn every column to character, and everything worked. I thought it could be useful to someone else, and that maybe someone would be able to explain the error to me ;)

Cheers

Are the classes of your variables character or factor?I was having this problem. My solution was to change al variables to factor.

#my data.frame was "aux.da"
while(i < ncol(aux.da)){
  i=i+1  aux.da[,i] = as.factor(aux.da[,i])
  • Find the function where the error occurred (via traceback()),
  • Set a breakpoint and debug it:

    trace(tab.disjonctif, browser)
    

    I did the following (offline) to find the name of tab.disjonctif:

  • Found the package on the CRAN mirror on GitHub
  • Search for that particular expression that gives the error
  • I just started to learn R yesterday, but the error comes from the fact that the MCA is for categorical data, so that's why your data cannot be numeric. Then to be more precise, before the MCA a "tableau disjonctif" (sorry i don't know the word in english : Complete disjunctive matrix) is created. So FactomineR is using this function :

    https://github.com/cran/FactoMineR/blob/master/R/tab.disjonctif.R

    Where i think it's looking for categorical values that can be matched to a numerical value (like Y = 1, N = 0).

    For others ; be careful : for R categorical data is related to factor type, so even if you have characters you could get this error.

    To build off @marques, @Khaled, and @Pierre Gourseaud:

    Yes, changing the format of your variables to factor should address the error message, but you shouldn't change the format of numerical data to factor if it's supposed to be continuous numerical data. Rather, if you have both continuous and categorical variables, try running a Factor Analysis for Mixed Data (FAMD) in the same FactoMineR package.

    If you go the FAMD route, you can change the format of just your categorical variable columns to factor with this:

    data[,c(3:5,10)] <- lapply(data[,c(3:5,10)] , factor) (assuming column numbers 3,4,5 and 10 need to be changed).

    Same problem as well and changing to factor did not solve my answer either, because I had put every variable as supplementary.

    What I did first was transform all my numeric data to factor :

    Xfac = factor(X[,1], ordered = TRUE)
    for (i in 2:29){
      tfac = factor(X[,i], ordered = TRUE)
      Xfac = data.frame(Xfac, tfac)
    colnames(Xfac)=labels(X[1,])
    

    Still, it would not work. But my 2nd problem was that I included EVERY factor as supplementary variable ! So these :

    MCA(Xfac, quanti.sup = c(1:29), graph=TRUE)
    MCA(Xfac, quali.sup = c(1:29), graph=TRUE)
    

    Would generate the same error, but this one works :

    MCA(Xfac, graph=TRUE)
    

    Not transforming the data to factors also generated the problem.

    I posted the same answer to a related topic : https://stackoverflow.com/a/40737335/7193352

  •