lb0389
lb0389

Reputation: 127

Visualization for Association of 2 binary variables

What would be a good visualization to use in R to show the association of 2 binary variables?

I understand that phi coefficient would be the best statistic to use, but how can I show it graphically? Considering that if I use a scatterplot, it would be very condensed since there are only 4 possible values.

Upvotes: 0

Views: 994

Answers (1)

mtoto
mtoto

Reputation: 24178

One idea would be to create a mosaicplot from the contigency table of the two binary variables.

Let's assume our data looks like this:

   var1 var2
1     1    1
2     0    0
3     1    1
4     0    0
5     1    1
6     1    1
7     0    0
8     0    1
9     0    1
10    1    0

We could visualize it in the following way:

mosaicplot(table(df))

enter image description here

Data

df <- structure(list(var1 = c(1, 0, 1, 0, 1, 1, 0, 0, 0, 1), var2 = c(1, 
0, 1, 0, 1, 1, 0, 1, 1, 0)), .Names = c("var1", "var2"), row.names = c(NA, 
-10L), class = "data.frame")

Upvotes: 2

Related Questions