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

## ----setup--------------------------------------------------------------------
library(contentValidity)

## -----------------------------------------------------------------------------
data(cvi_example)
head(cvi_example)

## -----------------------------------------------------------------------------
icvi(cvi_example)

## -----------------------------------------------------------------------------
mod_kappa(cvi_example)

## -----------------------------------------------------------------------------
aiken_v(cvi_example, lo = 1, hi = 4)

## -----------------------------------------------------------------------------
scvi_ave(cvi_example)   # average of I-CVIs
scvi_ua(cvi_example)    # proportion of items with universal agreement

## -----------------------------------------------------------------------------
result <- content_validity(cvi_example)
result

## -----------------------------------------------------------------------------
result$items
result$scale

## -----------------------------------------------------------------------------
apa_table(result)

## ----results = "asis"---------------------------------------------------------
apa_table(result, format = "markdown")

## -----------------------------------------------------------------------------
# 10 experts rating 3 items on Lawshe's scale
lawshe_ratings <- matrix(
  c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2,    # 8 of 10 essential
    1, 1, 1, 2, 2, 2, 2, 3, 3, 3,    # 3 of 10 essential
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1),   # 10 of 10 essential
  nrow = 10,
  dimnames = list(NULL, paste0("item", 1:3))
)

cvr(lawshe_ratings)

## -----------------------------------------------------------------------------
cvr_critical(n_experts = 10)        # one-tailed alpha = 0.05
cvr_critical(n_experts = 10, alpha = 0.01)

## -----------------------------------------------------------------------------
icvi(cvi_example, ci = TRUE, n_boot = 1000, seed = 1)

## -----------------------------------------------------------------------------
gwet_ac1(cvi_example)
gwet_ac2(cvi_example, categories = 1:4)

## -----------------------------------------------------------------------------
# Anticipating I-CVI ≈ 0.85 with target half-width ≤ 0.10
cv_sample_size_icvi(expected = 0.85, half_width = 0.10)

# Sensitivity table across plausible expected I-CVI values
sapply(seq(0.70, 0.95, by = 0.05), function(p) {
  cv_sample_size_icvi(expected = p, half_width = 0.10)
})

## -----------------------------------------------------------------------------
# Treat items 1-5 as subscale "Cognitive" and 6-10 as "Somatic"
result_multi <- content_validity(
  cvi_example,
  subscale = c(rep("Cognitive", 5), rep("Somatic", 5))
)
result_multi$subscales

## ----fig.width = 6, fig.height = 4--------------------------------------------
plot(result_multi, y_index = "gwet_ac2")

## ----fig.width = 6, fig.height = 4--------------------------------------------
# Flag only items below the AC2 threshold (ignores I-CVI verdict)
plot(result_multi, y_index = "gwet_ac2", flag_logic = "y_index")

# Flag only items below the I-CVI threshold (ignores AC2 verdict)
plot(result_multi, y_index = "gwet_ac2", flag_logic = "icvi")

## -----------------------------------------------------------------------------
apa_table(result_multi, interpretation_index = "gwet_ac2")

## ----eval = FALSE-------------------------------------------------------------
# citation("contentValidity")

