Code co-occurrence: which codes appear together, and how often
Source:R/cooccurrence.R
qda_cooccurrence.RdCounts for every pair of codes how often they appear together: in the
same segment (default, e.g. the same speaker turn), in the same document,
or as overlapping codings. Typical questions: which themes are talked
about together? Which categories are hard to tell apart (they are always
coded together)? The result is the basis of the heatmap
(qda_plot_cooccurrence()) and the code network (qda_plot_network()).
Arguments
- unit
"segment"(both codes in the same segment),"document"(somewhere in the same document) or"overlap"(the codings share text).- level
"code"(every code and subcode) or"top"(code families: a code together with its subcodes).- source
Optional documents (ids or names); default all.
- min_overlap
Minimum number of characters a coding must overlap a unit (or, with
unit = "overlap", the other coding).
Value
A tibble with one row per pair of codes that occur together,
most frequent first: code_a, code_b (paths), n (units – or, with
unit = "overlap", pairs of codings – with both), n_a, n_b (units
with each code, or its number of codings), jaccard (n / (n_a + n_b - n): 1 = always together; NA for unit = "overlap"). Attribute
"codes": one row per code (code, label, depth, color, n);
attribute "info": unit, level, number of units and documents.
Examples
qda_open(file.path(tempfile(), "example.jellyqda"))
qda_import(system.file("extdata", "interview_01.txt", package = "jellyqda"))
#> # A tibble: 1 × 5
#> id name format chars status
#> <int> <chr> <chr> <int> <chr>
#> 1 1 interview_01.txt txt 856 ok
qda_code_add("Career path"); qda_code_add("Motivation"); qda_code_add("Team")
qda_code(1, "Career path", segment = 5)
qda_code(1, "Motivation", start = 300, end = 420)
qda_code(1, "Motivation", segment = 7)
qda_code(1, "Team", segment = 7)
qda_cooccurrence()
#> # A tibble: 2 × 6
#> code_a code_b n n_a n_b jaccard
#> <chr> <chr> <int> <int> <int> <dbl>
#> 1 Career path Motivation 1 1 4 0.25
#> 2 Motivation Team 1 4 1 0.25
qda_cooccurrence(unit = "overlap")
#> # A tibble: 2 × 6
#> code_a code_b n n_a n_b jaccard
#> <chr> <chr> <int> <int> <int> <dbl>
#> 1 Career path Motivation 1 1 2 NA
#> 2 Motivation Team 1 2 1 NA
qda_close()