I've checked multiple threads about handling or visualizing contingency tables, but can't find one that can help my current question. I have a 2x3 contingency table: "group" variable has 3 levels not necessarily ordered, "level" variable has 2 levels (could be 3, but for simplicity, let's say 2). I would like to test independence between group and level variables, and visualize the pairwise relationship between groups as well (group 1 vs 3, 2 vs 3, etc). I'm using
vcd::mosaic which runs
loglm (which wraps
loglin) to visualize individual significance of cells in the contingency table. I like it that the area of each tile reflects the cell frequency and color reflects the statistical significance (residual).
My question is: when I put the full dataset with all 3 groups in loglm, group 3 does not seem to deviate from the null, but when I use the partial datasets with group 1 and 3, or 2 and 3 only, then each pair significantly deviates from the null. What is the best way to perform the test, visualize and interpret the relationship between the 3 groups? Should I use two plots with the pair of groups or one plot with 3 groups? I provide a dummy example dataset and mosaic plot results below:
set.seed(123) d <- data.frame(group = c(rep(1,20),rep(2,20),rep(3,20)), level = c(1, rep(0,19),rep(1,19),0, rep(1,10),rep(0,10))) # 3 groups tbl123 <- table(d) vcd::mosaic( ~ group + level, data = tbl123, gp=shading_max, split_vertical=T) # 2 group tbl13 <- table(d[d$group %in% c(1,3), ]) vcd::mosaic( ~ group + level, data = tbl13, gp=shading_max, split_vertical=T) tbl23 <- table(d[d$group %in% c(2,3), ]) vcd::mosaic( ~ group + level, data = tbl23, gp=shading_max, split_vertical=T)