What does “argument to 'which' is not logical” mean in FactoMineR MCA?

前端 未结 4 472
后悔当初
后悔当初 2021-01-04 10:40

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 &         


        
相关标签:
4条回答
  • 2021-01-04 10:48

    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

    0 讨论(0)
  • 2021-01-04 10:52

    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"
    i=0
    while(i < ncol(aux.da)){
      i=i+1  aux.da[,i] = as.factor(aux.da[,i])
    }
    
    0 讨论(0)
  • 2021-01-04 10:52

    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.

    0 讨论(0)
  • 2021-01-04 10:57

    It's difficult to tell without further input, but what you can do is:

    • 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
    0 讨论(0)
提交回复
热议问题