# Clustering a contingency table

I have a contingency table listing individuals with certain traits. For the sake of simplicity, let's say the table has individuals in rows, and the type of food they like in columns:

        | Pizza | Spinach | Cheese |
|-------|-------|---------|--------|
| Tom   |   0   |    1    |    1   |
| Jerry |   1   |    0    |    0   |
| Marie |   0   |    0    |    1   |
| Alex  |   1   |    0    |    1   |


I want to cluster individuals with similar tastes together. What's the best approach for this? Would hierarchical clustering be appropriate for this kind of data? Would k-modes work?

I also want to know which foods are the best separators for the clusters. Could correspondence analysis help me with that?

Finally, I want to know which foods are correlated. Can I use Spearman's coefficient on this kind of data?

• You can plot them using tsne or PCA or kmeans... And them.make sense of the data and the clusters Apr 3 '18 at 7:37
• This does not appear to be a proper contingency table, which would contain the multivariate frequency distribution between two variables (i.e. counts of co-occurrence). That table is just data! May 3 '18 at 20:38

You can use the Latent Class Model (see Goodman, L., 1974. Exploratory latent structure analysis using both identifiable and unidentifiable models. Biometrika 61 (2), 215–231). This approach achieves the clustering purpose by a mixture of multinomial distributions.

If you want to know which foods are the best separators for the clustering, you can check the parameters of the multinomial distributions for each component. Moreover, you can perform a variable selection simultanously with model estimation.

This approach (with and without variable selection) is implemented in the R package VarSelLCM. Here is an example (considering that your data are stored in object "x".

library(VarSelLCM)

x <- as.data.frame(x)
for (j in 1:ncol(x)) x[,j] <- as.factor(x[,j])

# Clustering with variable selection and a number of cluster between 1 and 4
# Model selection is BIC (to use MICL, the option must be specified)
out <- VarSelCluster(x, 1:4, nbcores = 2)

# partition
out@partition@zMAP

# summary
summary(out)