| correspondence_analysis | R Documentation |
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'.
correspondence_analysis(table, ncp = Inf, ...)
table |
A crosstab made with |
ncp |
The number of axes to keep. All of them by default. |
... |
Additional arguments to pass to |
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.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.