2
$\begingroup$

I have a dataframe with 100k rows and 20 binary variables, one of which is my target.

I would like to apply a Correspondence Analysis (CA) on it, but I have a few doubts:

  1. should the target column be included into the CA?

  2. CA is a way to analyze a large contingency table. The command table is used to get the contingency table but I get as many 2x2 tables as there are pairwise combinations of variables. Instead, correct me if I'm wrong, I need just one table with the counts for each column relative to my target variable, like:

            var1    var2   ...  var19 
    target
    
      0      73k     45k   ...   60k
    
      1      37k     55k   ...   40k
    

    Is there an R function that does this?

$\endgroup$
1
  • 2
    $\begingroup$ CA is similar to PCA, but used with categorical variables. Just like PCA, CA does not have independent and dependent variables, they are all treated as one. For PCA you could use PLS to condition the X's on the Y's. I do not know of such an alternative for CA. $\endgroup$ Commented Feb 16, 2022 at 13:35

2 Answers 2

2
$\begingroup$

Correspondence analysis is a multivariate technique that does not (as with PCA, principal component analysis) bother about target or predictor variables, but treats all variables symmetrically. But you have 20 binary variables, which, as you say, makes for a lot of ($20\cdot 19/2$) contingency tables. Correspondence analysis (CA) is for a single contingency table, so you are really asking about Multiple Correspondence Analysis (MCA). There are functions for both in R, in many different packages!

But you seem to want to give special prominence to your target variable, so only some version of MCA for only the 19 contingency tables involving that. Such an analysis ought to be possible, but I doubt you will find a specific R function for it.

What you really should do is tell us more about your problem and data (as an edit to your post, not only as comments!) and then maybe we can give some more useful answer. But there are many variants of correspondence analysis, and maybe some will serve you. This paper by Michael Greenacre seems to be interesting and may be of help!

$\endgroup$
2
$\begingroup$

It is unclear why you want to use (multiple) correspondence analysis, but here are a couple of additional points to consider, to add to Kjetil's answer (+1):

  • If you use multiple correspondence analysis (MCA) as a dimension reduction method, and plan to use these dimensions as predictors in another model (e.g. logistic regression), then do not include the target variable in the computation of the dimensions, at the risk otherwise of data leakage and overfitting.
  • MCA allows projecting supplementary variables on the axes. Supplementary variables are variables not used for computing the dimensions (contrary to active variables), but their projection on the axes may be useful for further interpretation and exploration (e.g. to see how they relate to the MCA dimensions). So you could use your target variable as a supplementary variable while using your predictors as active variables - but that really depends on what you're trying to do ultimately.
  • If you want to include your target variable in the computation of the dimensions (so not as a supplementary variable) but also want to give it more "weight" than other variables, you could use multiple factor analysis -with one group including only your target variable, and another group including your predictor variables. Note that you could also group your predictors themselves in multiple different groups. But again, choosing this method depends on the question you're trying to answer ultimately.

If you are using R, there are a several packages offering multiple correspondence analysis, with an option for supplementary variables. Look at FactoMiner and GDATools for instance. Multiple factor analysis is also available for these packages. The form under which your data should be depends on the tool you're using, though the two packages I mentioned ask for the raw data, not for a contingency table or a combination of contingency tables (these packages internally convert your raw dataset into an indicator matrix or into a Burt table, on which the calculations for the MCA are then performed -which should make your life easier). So your second question is more a question for https://stackoverflow.com, and would depend on the package or software you choose to use.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.