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

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

## ----engine, eval = requireNamespace("lme4", quietly = TRUE) && requireNamespace("merDeriv", quietly = TRUE)----
glmmtmb <- tidy(icc(ratings, score, subject, rater, engine = "glmmTMB", seed = 1))
lme4 <- tidy(icc(ratings, score, subject, rater, engine = "lme4", seed = 1))

## ----engine-table, echo = FALSE, eval = requireNamespace("lme4", quietly = TRUE) && requireNamespace("merDeriv", quietly = TRUE) && requireNamespace("gt", quietly = TRUE)----
data.frame(term = glmmtmb$term, glmmTMB = glmmtmb$estimate, lme4 = lme4$estimate) |>
  gt::gt() |>
  gt::tab_header(title = "Point estimates on the ratings data by engine") |>
  gt::cols_label(term = "Coefficient", glmmTMB = "glmmTMB", lme4 = "lme4") |>
  gt::fmt_number(columns = c(glmmTMB, lme4), decimals = 4)

## ----lavaan, eval = requireNamespace("lavaan", quietly = TRUE)----------------
glmmtmb <- tidy(icc(ratings, score, subject, rater, engine = "glmmTMB", seed = 1))
lavaan <- tidy(icc(ratings, score, subject, rater, engine = "lavaan", seed = 1))

## ----lavaan-table, echo = FALSE, eval = requireNamespace("lavaan", quietly = TRUE) && requireNamespace("gt", quietly = TRUE)----
data.frame(term = glmmtmb$term, glmmTMB = glmmtmb$estimate, lavaan = lavaan$estimate) |>
  gt::gt() |>
  gt::tab_header(title = "Point estimates on the ratings data: mixed model and SEM") |>
  gt::cols_label(term = "Coefficient", glmmTMB = "glmmTMB (mixed model)", lavaan = "lavaan (SEM)") |>
  gt::fmt_number(columns = c(glmmTMB, lavaan), decimals = 4)

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

## ----brms-prior, eval = FALSE-------------------------------------------------
# library(brms)
# icc(ratings, score, subject, rater, engine = "brms",
#   prior = set_prior("normal(0, 0.1)", class = "sd"), seed = 1)
# #> Warning message:
# #> Using a custom `prior` instead of the sourced half-t(4, 0, 1).
# #> ! This VOIDS the package's coverage guarantees: the credible-interval coverage
# #>   results (ten Hove et al. 2020) hold only for the sourced prior.
# #> ℹ A vague or flat SD prior can WORSEN small-`k` boundary bias. The half-t is
# #>   weakly informative on purpose (Principle #3's regime).
# #> ℹ Leave `prior` unset for the sourced default unless you are running
# #>   prior-sensitivity or method-comparison work.

