## -----------------------------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")

## -----------------------------------------------------------------------------
library(misskappa)

## -----------------------------------------------------------------------------
fit <- agreement(dat.gwet2014, weight = "linear")
fit

## -----------------------------------------------------------------------------
coef(fit)
sqrt(diag(vcov(fit)))

## -----------------------------------------------------------------------------
confint(fit)
confint(fit, transform = "fisher")

## -----------------------------------------------------------------------------
agreement(dat.zapf2016, estimator = "pairwise")
agreement(dat.zapf2016, estimator = "nt_fiml", categories = 1:5)

## -----------------------------------------------------------------------------
agreement_counts(dat.fleiss1971)

## -----------------------------------------------------------------------------
agreement_test(agreement(dat.gwet2014, estimator = "ipw"), value = 0.5)

## -----------------------------------------------------------------------------
agreement_test(
  gwet  = agreement(dat.gwet2014,  estimator = "ipw"),
  klein = agreement(dat.klein2018, estimator = "ipw")
)

## -----------------------------------------------------------------------------
to_counts <- function(attribute) {
  m <- with(dat.mcduff2019,
            tapply(get(attribute), list(item, judge), function(z) z[1]))
  ratings_to_counts(matrix(as.numeric(m), nrow = nrow(m)))
}
smile    <- agreement_counts(to_counts("rating_smile"),    weight = "quadratic")
positive <- agreement_counts(to_counts("rating_positive"), weight = "quadratic")

agreement_test(smile = smile, positive = positive, paired = TRUE)

## -----------------------------------------------------------------------------
pairs <- combn(4, 2)
pair_fits <- apply(pairs, 2, function(rs)
  agreement(dat.zapf2016[, rs], estimator = "pairwise"), simplify = FALSE)
names(pair_fits) <- apply(pairs, 2, paste0, collapse = "")
do.call(agreement_test, c(pair_fits, list(paired = TRUE)))

## -----------------------------------------------------------------------------
fit <- agreement(dat.tenhove2025, estimator = "nt_fiml_cs", categories = 1:5)
psi <- influence(fit)
est <- coef(fit)[["Conger"]] - coef(fit)[["Brennan-Prediger"]]
se  <- sqrt(sum((psi[, "Conger"] - psi[, "Brennan-Prediger"])^2)) / nrow(psi)
c(estimate = est, se = se, z = est / se)

