4
$\begingroup$

Assume a categorical variable (with states m, o and z) that can be measured for a set of 20 different categories (c01, c02, ..., c20) in a sample. Further, assume that a dataset of six different samples (s01, s02, ..., s06) was generated. Finally, assume that variable state z indicates that the respective category cannot be measured in that sample. The data looks something like this:

c01    m   o   z   ...   m
c02    o   o   m   ...   o
c03    z   o   z   ...   m
...    .   .   .   ...   .
c19    z   m   o   ...   m
c20    m   o   m   ...   o
     s01 s02 s03       s06

What type of plot would you use to visualize this dataset in R, if the objective of such a visualization is to emphasize the differences between states m and o across samples? (The differences within a sample are of lesser importance.)

For example, I could imagine a graph in which the states m and o have explicit fields. Please note that s01 has no letter for c03 in the graph below, because that field has a z in the table above. Likewise, s01 has no letter for c19.

Title   M O   M O   ...
  c01   m       o   ...
  c02     o     o   ...
  c03           o   ...
  ...    .     .    ...
  c19         m     ...
  c20   m       o   ...
        s01   s02   ...

However, other visualizations are possible as well. What would the data visualizers among us consider the most efficient visualization? (Since this is a quick exploratory data analysis, any graph easily implemented via an existing R function would be preferable.)

EDIT 1: Below please find example input data.

dput(inD, file="inD.tmp")
structure(list(s01 = structure(c(2L, 2L, 3L, 3L, 2L, 3L, 2L, 
2L, 2L, 3L, 2L, 3L, 2L, 1L, 1L, 3L, 3L, 3L, 3L, 2L), .Label = c("m", 
"o", "z"), class = "factor"), s02 = structure(c(2L, 2L, 2L, 3L, 
2L, 3L, 3L, 2L, 2L, 2L, 2L, 3L, 2L, 1L, 3L, 1L, 3L, 1L, 1L, 2L
), .Label = c("m", "o", "z"), class = "factor"), s03 = structure(c(2L, 
2L, 3L, 2L, 2L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 3L, 1L, 3L, 
3L, 3L, 2L), .Label = c("m", "o", "z"), class = "factor"), s04 = structure(c(3L, 
3L, 3L, 3L, 2L, 3L, 2L, 2L, 2L, 2L, 2L, 3L, 2L, 1L, 3L, 1L, 3L, 
3L, 3L, 2L), .Label = c("m", "o", "z"), class = "factor"), s05 = structure(c(2L, 
2L, 3L, 3L, 2L, 3L, 3L, 2L, 2L, 2L, 3L, 3L, 2L, 1L, 3L, 1L, 3L, 
3L, 3L, 2L), .Label = c("m", "o", "z"), class = "factor"), s06 = structure(c(2L, 
3L, 3L, 3L, 2L, 2L, 3L, 2L, 3L, 2L, 3L, 3L, 2L, 1L, 3L, 3L, 1L, 
3L, 1L, 2L), .Label = c("m", "o", "z"), class = "factor")), class = "data.frame", row.names = c("c01", 
"c02", "c03", "c04", "c05", "c06", "c07", "c08", "c09", "c10", 
"c11", "c12", "c13", "c14", "c15", "c16", "c17", "c18", "c19", 
"c20"))

> inD
    s01 s02 s03 s04 s05 s06
c01   o   o   o   z   o   o
c02   o   o   o   z   o   z
c03   z   o   z   z   z   z
c04   z   z   o   z   z   z
c05   o   o   o   o   o   o
c06   z   z   z   z   z   o
c07   o   z   o   o   z   z
c08   o   o   o   o   o   o
c09   o   o   o   o   o   z
c10   z   o   o   o   o   o
c11   o   o   o   o   z   z
c12   z   z   o   z   z   z
c13   o   o   o   o   o   o
c14   m   m   m   m   m   m
c15   m   z   z   z   z   z
c16   z   m   m   m   m   z
c17   z   z   z   z   z   m
c18   z   m   z   z   z   z
c19   z   m   z   z   z   m
c20   o   o   o   o   o   o
$\endgroup$
1
  • 1
    $\begingroup$ @StephanKolassa Post has been edited to include example data. $\endgroup$ Commented Sep 19, 2018 at 13:04

1 Answer 1

1
$\begingroup$

You may have given us the data, but there's no context to them. Are they genotypes? Are they endorsements on an ordinal 3 point scale for a 6-item survey?

The most general answer would be to create a mosaic plot. The plot allows the user to (very tediously) evaluate the conditional and marginal probability for any event in the table. It's the default plot.table method. I have never personally used such a plot, it's too busy to be useful.

If you are able to identify outcomes and exposures, it's much better to show conditional probabilities of outcomes over all combinations of stratification variables.

If $z$ represents a missing state, you can calculate the above table(s) using a complete case analysis.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.