library(vcdExtra) # for mcaplot
library(ca)
data("PreSex", package="vcd")
We want the variables in the order G, P, E, M, with marital status last.
PreSex <- aperm(PreSex, 4:1) # order variables G, P, E, M
presex.mca <- mjca(PreSex, lambda="Burt")
summary(presex.mca)
##
## Principal inertias (eigenvalues):
##
## dim value % cum% scree plot
## 1 0.149930 53.6 53.6 *************
## 2 0.067201 24.0 77.6 ******
## 3 0.035396 12.6 90.2 ***
## 4 0.027365 9.8 100.0 **
## -------- -----
## Total: 0.279892 100.0
##
##
## Columns:
## name mass qlt inr k=1 cor ctr k=2 cor ctr
## 1 | Gender:Men | 87 869 159 | 434 368 109 | -506 501 331 |
## 2 | Gender:Women | 163 869 84 | -231 368 58 | 269 501 176 |
## 3 | PremaritalSex:No | 192 763 61 | -251 714 81 | 66 49 12 |
## 4 | PremaritalSex:Yes | 58 763 200 | 829 714 267 | -217 49 41 |
## 5 | ExtramaritalSex:No | 221 681 29 | -149 596 33 | -56 85 10 |
## 6 | ExtramaritalSex:Yes | 29 681 221 | 1125 596 247 | 424 85 78 |
## 7 | MaritalStatus:Divorced | 119 794 128 | 368 450 108 | 322 344 184 |
## 8 | MaritalStatus:Married | 131 794 117 | -336 450 98 | -294 344 168 |
the basic ca::plot() method doesn’t do a nice job of labeling
plot(presex.mca)
mcaplot(presex.mca)
# add a nice legend
cols <- c("blue", "red", "brown", "black")
legend("bottomright", legend=c("Gender", "PreSex", "ExtraSex", "Marital"),
title="Factor",
title.col="black",
col=cols, text.col=cols,
pch=16:19,
bg="gray95", cex=1.2)