## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
ready <- all(vapply(
  c("randomForest", "ranger", "rsample"),
  requireNamespace, logical(1), quietly = TRUE
))
knitr::opts_chunk$set(eval = ready)

## ----data---------------------------------------------------------------------
library(rankimp)

truth <- sort(attr(applications, "effects"), decreasing = TRUE)
truth

## ----panel--------------------------------------------------------------------
library(randomForest)
library(ranger)

set.seed(1)
rf_fit <- randomForest(default ~ ., data = applications, ntree = 300)
set.seed(1)
rgr_fit <- ranger(default ~ ., data = applications, num.trees = 300,
                  importance = "impurity", probability = TRUE)

J <- importance_judges(
  fit_list  = list(rf = rf_fit, ranger = rgr_fit),
  methods   = c("permutation", "mdi"),
  data      = applications,
  target    = "default",
  resamples = rsample::vfold_cv(applications, v = 3),
  seeds     = 1:2
)
J

## ----consensus----------------------------------------------------------------
cr <- consensus_rank(J)
cr

## ----confsets-----------------------------------------------------------------
cb <- rank_confsets(cr, n_boot = 500)
cb

## ----select-------------------------------------------------------------------
rank_select(cb, threshold = 2)

## ----select-more--------------------------------------------------------------
rank_select(cb, threshold = 4)

## ----plot, fig.width = 6, fig.height = 4--------------------------------------
autoplot(cb)

## ----clusters-----------------------------------------------------------------
het <- judge_clusters(J)
het

## ----composition--------------------------------------------------------------
provenance <- attr(J, "provenance")
table(method = provenance$method, cluster = het$cluster)
table(model = provenance$model, cluster = het$cluster)

## ----centres------------------------------------------------------------------
het$centres

