Articles - Principal Component Methods in R: Practical Guide

Correspondence Analysis in R: Million Ways

This article describes the multiple ways to compute correspondence analysis in R (CA). Recall that, correspondence analysis is used to study the association between two categorical variables by analyzing the contingency table formed by these two variables.

There are many R functions/packages for computing CA. No matter what functions you decide to use, in the list hereafter, the factoextra package can handle the output.

Correspondence Analysis in R: A Million Ways

Contents:


Data format

  • Demo data: housetasks [in factoextra package]
  • Data contents: housetasks repartition in the couple.
    • rows are the different tasks
    • values are the frequencies of the tasks done by the i) wife only, ii) alternatively, iii) husband only, iv) jointly.
  • Data illustration:

Load the data:

library(factoextra)
data(housetasks)
# head(housetasks)

Compute

  1. Using CA() [FactoMineR]
library(FactoMineR)
res.ca <- CA(housetasks, graph = FALSE)
  1. Using dudi.coa() [ade4]
library("ade4")
res.ca <- dudi.coa(housetasks, scannf = FALSE, nf = 5)
  1. Using ca() [ca]
library(ca)
res.ca <- ca(housetasks)
  1. Using corresp() [MASS]
library(MASS)
res.ca <- corresp(housetasks, nf = 3)
  1. Using epCA() [ExPosition]
library("ExPosition")
res.ca <- epCA(housetasks, graph = FALSE)

Visualize

  • Required packages
library(factoextra)
  • Scree plot
fviz_eig(res.ca) 

  • Biplot of rows and columns:
fviz_ca_biplot(res.ca, repel = TRUE)

Results

You can access to the results as follow:

library(factoextra)
# Eigenvalues
eig.val <- get_eigenvalue(res.ca)
eig.val
# Results for row variables
res.row <- get_ca_row(res.ca)
res.row$coord          # Coordinates
res.row$contrib        # Contributions to the PCs
res.row$cos2           # Quality of representation 
# Results for column variables
res.col <- get_ca_col(res.ca)
res.col$coord          # Coordinates
res.col$contrib        # Contributions to the PCs
res.col$cos2           # Quality of representation 

Read more