## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 6,
                      fig.height = 3.5)

## ----setup--------------------------------------------------------------------
library(qdaR)

## -----------------------------------------------------------------------------
qda_formats()[, c("format", "file", "grain")]

## -----------------------------------------------------------------------------
frag <- qda_read_fragments(qda_example("zotqda-fragments.csv"))
attr(frag, "qda_format")
attr(frag, "qda_grain")

## -----------------------------------------------------------------------------
frag[, c("code", "codeId")]

## -----------------------------------------------------------------------------
qda_plot_frequencies(frag)

## -----------------------------------------------------------------------------
hist <- qda_read_history(qda_example("zotqda-history.csv"))
qda_plot_saturation(hist)

## -----------------------------------------------------------------------------
res <- suppressWarnings(qda_chisq(frag, group = "citekey"))
res$table
res$cramers_v
res$expected_ok

## -----------------------------------------------------------------------------
qda_code_distance(frag, min_n = 1)

## -----------------------------------------------------------------------------
cl <- qda_cluster(frag, min_n = 1)
cl$cophenetic

## -----------------------------------------------------------------------------
map <- qda_read_mapping(qda_example("zotqda-konsens-abbildung.csv"))
head(qda_apply_mapping(frag, map)[, c("code", "consensusCode")])

## -----------------------------------------------------------------------------
frag2 <- data.frame(
  annotationKey = rep(paste0("s", 1:6), each = 2),
  codedBy = rep(c("ann", "bob"), 6),
  code = c("A", "A", "A", "A", "A", "A",
           "A", "A", "A", "A", "B", "A")
)
u <- qda_units(frag2)
qda_agreement(u)

## ----fig.alt = "Agreement measures against the number of code-system levels kept"----
u2 <- cbind(ann = c("A/x", "A/y", "B/x", "B/y"),
            bob = c("A/y", "A/y", "B/x", "B/x"))
qda_level_agreement(u2)
qda_plot_level_agreement(u2)

## -----------------------------------------------------------------------------
qda_confusion(u2, only_disagreements = TRUE)

