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

## -----------------------------------------------------------------------------
library(combinat)
library(rankingQ)

set.seed(100)
tab <- lapply(permn(seq(3)), paste0, collapse = "") |>
  sample(30, replace = TRUE) |>
  unlist() |>
  table() |>
  table_to_tibble()
plot_dist_ranking(tab, ylim = 0.5)

## -----------------------------------------------------------------------------
data(identity)

# First compute bias-corrected estimates
out_direct <- imprr_direct(
  data = identity,
  J = 4,
  main_q = c("party", "religion", "gender", "race"),
  anc_correct = "anc_correct_identity",
  n_bootstrap = 10
)

# Plot average ranks
library(dplyr)
out_direct$results |>
  filter(qoi == "average rank") |>
  mutate(
    item = factor(
      item,
      levels = c("party", "religion", "gender", "race"),
      labels = c("Party", "Religion", "Gender", "Race")
    )
  ) |>
  plot_avg_ranking()

