correspondence_analysis: Correspondence Analysis of a Crosstab

View source: R/ca.R

correspondence_analysisR Documentation

Correspondence Analysis of a Crosstab

Description

Makes the correspondence analysis of a crosstab with FactoMineR::CA: first make the table with tabxplor::tab(), then analyse it. The analysis reads the (weighted) counts of the table, whatever it displays, without its Total rows and columns. To leave out some rows or columns, filter the table before, with dplyr::filter() and dplyr::select().

Supplementary variables are given in the table itself: in a 'tab()' of several row variables, or several column variables, the first row variable and the first column variable make the active table, and the other variables are supplementary, placed on the axes without taking part in them. 'tab(data, c(relig, marital), c(partyid, race))' analyses 'relig' by 'partyid', and places the levels of 'marital' by their profile over 'partyid', and the levels of 'race' by their profile over 'relig'.

Usage

correspondence_analysis(table, ncp = Inf, ...)

Arguments

table

A crosstab made with tabxplor::tab(), with one or several row variables and one or several column variables. A matrix or a table of counts works too, with its supplementary rows and columns given as in FactoMineR::CA() ('row.sup', 'col.sup').

ncp

The number of axes to keep. All of them by default.

...

Additional arguments to pass to CA.

Value

A 'CA' object from FactoMineR, which remembers the names of the two active variables, so that interpret can print them, and, in 'source', the variable and the name of every row and column of the table.

Examples

gss <- forcats::gss_cat |>
  dplyr::filter(!relig %in% c("No answer", "Don't know", "Not applicable"),
                !partyid %in% c("No answer", "Don't know"))
crosstab <- tabxplor::tab(gss, relig, partyid)
res.ca <- correspondence_analysis(crosstab)
interpret(res.ca)                            # the eigenvalues, then the axes

ggfacto(res.ca)                              # the graph
ggfacto(res.ca, interactive = TRUE)          # hover: the profile of each level

# the size of the deviations, which the graph does not show
tabxplor::tab(gss, relig, partyid, pct = "row", color = "contrib")

# marital (rows) and race (columns) are supplementary
res.ca2 <- tabxplor::tab(gss, c(relig, marital), c(partyid, race)) |>
  correspondence_analysis()
ggfacto(res.ca2)

ggfacto documentation built on Sept. 23, 2026, 1:08 a.m.