How to fix: "Error in CA(dt, graph = FALSE) : The following variables are not quantitative Var1"

1.5k Views Asked by At

I'm trying to use correspondence analysis in R. It seems like the first argument of function "CA" in FactoMineR must be a contingency table. "dt" is a contingency table, but it returns that the variables are not quantitative.

One of the levels of X1 is empty, I dont know if this is a problem in Correspondence Analysis

library("FactoMineR")
tab1 <- table(as.factor(df$X1),as.factor(df$X2))
dt <- as.table(as.matrix(tab1))
res.ca <- CA(dt, graph = FALSE)

The output is:

Error in CA(tab1, graph = FALSE) : 
The following variables are not quantitative:  Var1
The following variables are not quantitative:  Var2
1

There are 1 best solutions below

0
Rushabh Patel On BEST ANSWER

You have to convert your tab1 to data frame using as.data.frame.matrix(), before passing it to CA function.

library("FactoMineR")
tab1 <- as.data.frame.matrix(table(as.factor(df$X1),as.factor(df$X2)))
res.ca <- CA(tab1, graph = FALSE)

Sample Data:

df <- data.frame(X1=as.factor(c(1:101)),X2=as.factor(c(seq(0,100,1))))