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

## ----setup--------------------------------------------------------------------
library(intraclass)

## ----ci-bootstrap, eval = requireNamespace("glmmTMB", quietly = TRUE)---------
mc <- tidy(icc(ratings, score, subject, rater, seed = 1))
bs <- tidy(icc(ratings, score, subject, rater,
  ci_method = "bootstrap", boot_samples = 999, seed = 1
))

## ----ci-bootstrap-table, echo = FALSE, eval = requireNamespace("glmmTMB", quietly = TRUE) && requireNamespace("gt", quietly = TRUE)----
data.frame(
  term = mc$term, estimate = mc$estimate,
  mc_low = mc$conf.low, mc_high = mc$conf.high,
  bs_low = bs$conf.low, bs_high = bs$conf.high
) |>
  gt::gt() |>
  gt::tab_header(title = "Monte-Carlo and bootstrap 95% intervals on the ratings data") |>
  gt::fmt_number(columns = estimate, decimals = 3) |>
  gt::fmt_number(columns = mc_low:bs_high, decimals = 2) |>
  gt::cols_merge(columns = c(mc_low, mc_high), pattern = "[{1}, {2}]") |>
  gt::cols_merge(columns = c(bs_low, bs_high), pattern = "[{1}, {2}]") |>
  gt::cols_label(
    term = "Coefficient",
    estimate = "Estimate",
    mc_low = "Monte-Carlo",
    bs_low = "Parametric bootstrap"
  )

## ----ci-oneway-optin, eval = requireNamespace("glmmTMB", quietly = TRUE)------
mc <- tidy(icc(ratings, score, subject, rater, model = "oneway", seed = 1))
se <- tidy(icc(ratings, score, subject, rater,
  model = "oneway", ci_method = "searle"
))
bu <- tidy(icc(ratings, score, subject, rater,
  model = "oneway", ci_method = "burch"
))
np <- tidy(icc(ratings, score, subject, rater,
  model = "oneway", ci_method = "npbootstrap", boot_samples = 199, seed = 1
))

## ----ci-oneway-optin-table, echo = FALSE, eval = requireNamespace("glmmTMB", quietly = TRUE) && requireNamespace("gt", quietly = TRUE)----
data.frame(
  term = mc$term, estimate = mc$estimate,
  mc_low = mc$conf.low, mc_high = mc$conf.high,
  se_low = se$conf.low, se_high = se$conf.high,
  bu_low = bu$conf.low, bu_high = bu$conf.high,
  np_low = np$conf.low, np_high = np$conf.high
) |>
  gt::gt() |>
  gt::tab_header(title = "One-way 95% intervals on the ratings data by method") |>
  gt::fmt_number(columns = estimate, decimals = 3) |>
  gt::fmt_number(columns = mc_low:np_high, decimals = 2) |>
  gt::cols_merge(columns = c(mc_low, mc_high), pattern = "[{1}, {2}]") |>
  gt::cols_merge(columns = c(se_low, se_high), pattern = "[{1}, {2}]") |>
  gt::cols_merge(columns = c(bu_low, bu_high), pattern = "[{1}, {2}]") |>
  gt::cols_merge(columns = c(np_low, np_high), pattern = "[{1}, {2}]") |>
  gt::cols_label(
    term = "Coefficient",
    estimate = "Estimate",
    mc_low = "Monte-Carlo",
    se_low = "Searle",
    bu_low = "Burch",
    np_low = "Nonparametric bootstrap"
  )

## ----ci-mpl, eval = requireNamespace("glmmTMB", quietly = TRUE)---------------
mc2 <- tidy(icc(ratings_twoway, score, subject, rater, type = "agreement", seed = 1))
ml <- tidy(icc(ratings_twoway, score, subject, rater, type = "agreement", ci_method = "mpl"))

## ----ci-mpl-table, echo = FALSE, eval = requireNamespace("glmmTMB", quietly = TRUE) && requireNamespace("gt", quietly = TRUE)----
data.frame(
  term = mc2$term, estimate = mc2$estimate,
  mc_low = mc2$conf.low, mc_high = mc2$conf.high,
  ml_low = ml$conf.low, ml_high = ml$conf.high
) |>
  gt::gt() |>
  gt::tab_header(title = "Monte-Carlo and modified profile-likelihood 95% intervals on ratings_twoway") |>
  gt::fmt_number(columns = estimate, decimals = 3) |>
  gt::fmt_number(columns = mc_low:ml_high, decimals = 2) |>
  gt::cols_merge(columns = c(mc_low, mc_high), pattern = "[{1}, {2}]") |>
  gt::cols_merge(columns = c(ml_low, ml_high), pattern = "[{1}, {2}]") |>
  gt::cols_label(
    term = "Coefficient",
    estimate = "Estimate",
    mc_low = "Monte-Carlo",
    ml_low = "Modified profile likelihood"
  )

## ----posterior, eval = FALSE--------------------------------------------------
# icc(ratings, score, subject, rater, engine = "brms", type = "agreement", seed = 1)

## ----posterior-hpdi, eval = FALSE---------------------------------------------
# icc(ratings, score, subject, rater, engine = "brms",
#   type = "agreement", posterior_summary = "hpdi", seed = 1)

