Author: Institute ‘Center of Operations Research’, Miguel Hernández University of Elche

# PEAXAI: Probabilistic Efficiency Analysis using Explainable Artificial Intelligence

#### Institute ‘Center of Operations Research’, Miguel Hernández University of Elche

This vignette introduces the main functions of the `PEAXAI` package.

`PEAXAI` provides a methodology that integrates Data Envelopment Analysis (DEA) with Machine Learning (ML) algorithms to train a classifier that estimates the probability that each decision-making unit (DMU) is (in)efficient.

Once the model is trained, the package offers several functions for post-hoc analysis, including:

- Estimating feature importance,
- Generating counterfactual scenarios for each DMU — that is, determining the minimum changes required for a DMU to be considered efficient along a predefined direction vector and based on a user-defined efficiency threshold,
- Producing efficiency rankings (either based on the predicted probabilities or on attainable improvements), and
- Identifying peer units given a specific efficiency threshold.

These tools facilitate benchmarking and policy simulations in a transparent and explainable framework.

## Example Dataset: Spanish Food Industry Firms

To illustrate the functionality of the `PEAXAI` package, we use a dataset of 917 companies in the food industry sector operating in Spain. The data were retrieved from the SABI (Sistema de Análisis de Balances Ibéricos) database for the year 2023 and include only firms with more than 50 employees.

Each row corresponds to a single firm and includes both financial and operational variables relevant for productivity and efficiency analysis.

The output variable used to measure performance is:

- `operating_income`: Operating income in millions of euros.

The input variables include:

- `total_assets`: Total assets (in millions of euros).
- `employees`: Number of employees.
- `fixed_assets`: Tangible fixed assets (in millions of euros).
- `personnel_expenses`: Personnel-related costs (in millions of euros).

Additionally, the variable `autonomous_community` indicates the geographical location of each firm within one of Spain’s 17 autonomous communities. This allows the analysis to reflect regional institutional and market heterogeneity.

The dataset exhibits a wide dispersion across firms, including both medium-sized and large enterprises. This heterogeneity poses a realistic challenge for evaluating efficiency and provides a rich testing ground for model explainability.

## Load the package and example dataset

For illustration purposes, this vignette focuses on a subset of the data: firms located in the Autonomous Community of Valencia (Comunidad Valenciana).

    library(PEAXAI)
    data("firms", package = "PEAXAI")

For illustration, we focus on firms located in the Comunidad Valenciana (Autonomous Community of Valencia). Filter the dataset to include only firms from the Comunidad Valenciana and remove the `autonomous_community` column.

    data <- subset(firms, autonomous_community == "Comunidad Valenciana")[, -ncol(firms)]
    rm(firms)

Quick structure and summary.

    str(data)
    #> 'data.frame':    97 obs. of  5 variables:
    #>  $ total_assets      : num  259 185 129 104 153 ...
    #>  $ employees         : num  70 261 354 968 1076 ...
    #>  $ fixed_assets      : num  84.15 21.75 5.76 30.55 103.76 ...
    #>  $ personnel_expenses: num  16.7 19.9 13.7 36.8 31.8 ...
    #>  $ operating_income  : num  461 358 357 294 268 ...
    summary(data)
    #>   total_assets       employees       fixed_assets      personnel_expenses
    #>  Min.   :  1.537   Min.   :  50.0   Min.   :  0.1421   Min.   : 1.037
    #>  1st Qu.:  8.989   1st Qu.:  75.0   1st Qu.:  2.6797   1st Qu.: 2.167
    #>  Median : 24.555   Median :  98.0   Median :  6.2578   Median : 3.059
    #>  Mean   : 41.030   Mean   : 201.1   Mean   : 15.2799   Mean   : 6.757
    #>  3rd Qu.: 52.409   3rd Qu.: 240.0   3rd Qu.: 20.0960   3rd Qu.: 8.244
    #>  Max.   :258.825   Max.   :1076.0   Max.   :140.6890   Max.   :36.789
    #>  operating_income
    #>  Min.   :  2.382
    #>  1st Qu.: 12.994
    #>  Median : 29.138
    #>  Mean   : 62.307
    #>  3rd Qu.: 72.688
    #>  Max.   :460.578

## Specify parameters for PEAXAI model fitting

Determine inputs (x) and outputs (y) indices.

    x <- c(1:4)
    y <- c(5)

Determine the technology assumptions.

    RTS <- "vrs"

To address class imbalance, we apply SMOTE based on the best-practice frontier (assuming a convex production technology). First, we identify the combinations of DMUs that define the frontier. Then, we generate one of two types of synthetic DMUs from these combinations: efficient units (on the frontier) and near-frontier inefficient units (inside the frontier’s envelope).

When the efficient class is the minority, efficient-class SMOTE on the best-practice frontier helps the classifier learn the frontier more accurately. Optionally, if the observed imbalance still falls short of the target ratio, we also generate near-frontier inefficient synthetic units derived from the frontier geometry to sharpen the separation between efficient and inefficient regions.

    imbalance_rate <- seq(0.05, 0.4, 0.05)

Define machine learning methods and their tuning parameters. Here we configure a neural network (nnet) with a grid of hyperparameters

    methods <- list(
      "nnet" = list(
        tuneGrid = expand.grid(
          size = c(1, 5, 10, 20),
          decay = 10^seq(-5, -1, by = 1)
        ),
        maxit = 100,
        preProcess = c("center", "scale"),
        # # --- arguments nnet ---
        entropy = TRUE,
        skip = TRUE,
        maxit = 1000,
        MaxNWts = 100000,
        trace = FALSE,
        weights = NULL
      )
    )

Parameters for controlling model training (k-fold cross-validation)

    trControl <- list(
      method = "cv",
      number = 5
    )

Classification metrics to optimize during training (priority order in case of ties)

    metric_priority <- c("Balanced_Accuracy", "F1", "ROC_AUC")

Define hold-out sample to evaluate model performance on unseen data. These samples are excluded from the cross-validation and hyperparameter tuning process. By default, is `NULL`.

    hold_out <- NULL

Set random seed for reproducibility (ensures consistent results across runs).

    seed <- 1

## Apply PEAXAI: from efficiency labeling to ML-based classification

We now apply the full PEAXAI pipeline:

1. Estimate efficiency labels using Additive DEA,
2. Balance the data using SMOTE units,
3. Train the machine learning classifier with cross-validation,
4. Select the best model according to multiple performance metrics.

    models <- PEAXAI_fitting(
      data = data,
      x = x,
      y = y,
      RTS = RTS,
      imbalance_rate = imbalance_rate,
      methods = methods,
      trControl = trControl,
      metric_priority = metric_priority,
      hold_out = hold_out,
      verbose = TRUE,
      seed = seed
    )
    #> [1] "Computing maximal friends with 1 DMUs (step 1 of 15 )"
    #> [1] "Computing maximal friends with 2 DMUs (step 2 of 15 )"
    #> [1] "Computing maximal friends with 3 DMUs (step 3 of 15 )"
    #> [1] "Computing maximal friends with 4 DMUs (step 4 of 15 )"
    #> [1] "Computing maximal friends with 5 DMUs (step 5 of 15 )"
    #> [1] "Computing maximal friends with 6 DMUs (step 6 of 15 )"
    #> [1] "Computing maximal friends with 7 DMUs (step 7 of 15 )"
    #> [1] "Computing maximal friends with 8 DMUs (step 8 of 15 )"
    #> [1] "Computing maximal friends with 9 DMUs (step 9 of 15 )"
    #> [1] "Computing maximal friends with 10 DMUs (step 10 of 15 )"
    #> [1] "Computing maximal friends with 11 DMUs (step 11 of 15 )"
    #> [1] "Computing maximal friends with 12 DMUs (step 12 of 15 )"
    #> [1] "Computing maximal friends with 13 DMUs (step 13 of 15 )"
    #> [1] "Computing maximal friends with 14 DMUs (step 14 of 15 )"
    #> [1] "Computing maximal friends with 15 DMUs (step 15 of 15 )"
    #> [1] "Computing maximal friends with 1 DMUs (step 1 of 14 )"
    #> [1] "Computing maximal friends with 2 DMUs (step 2 of 14 )"
    #> [1] "Computing maximal friends with 3 DMUs (step 3 of 14 )"
    #> [1] "Computing maximal friends with 4 DMUs (step 4 of 14 )"
    #> [1] "Computing maximal friends with 5 DMUs (step 5 of 14 )"
    #> [1] "Computing maximal friends with 6 DMUs (step 6 of 14 )"
    #> [1] "Computing maximal friends with 7 DMUs (step 7 of 14 )"
    #> [1] "Computing maximal friends with 8 DMUs (step 8 of 14 )"
    #> [1] "Computing maximal friends with 9 DMUs (step 9 of 14 )"
    #> [1] "Computing maximal friends with 10 DMUs (step 10 of 14 )"
    #> [1] "Computing maximal friends with 11 DMUs (step 11 of 14 )"
    #> [1] "Computing maximal friends with 12 DMUs (step 12 of 14 )"
    #> [1] "Computing maximal friends with 13 DMUs (step 13 of 14 )"
    #> [1] "Computing maximal friends with 14 DMUs (step 14 of 14 )"
    #> [1] "Computing maximal friends with 1 DMUs (step 1 of 12 )"
    #> [1] "Computing maximal friends with 2 DMUs (step 2 of 12 )"
    #> [1] "Computing maximal friends with 3 DMUs (step 3 of 12 )"
    #> [1] "Computing maximal friends with 4 DMUs (step 4 of 12 )"
    #> [1] "Computing maximal friends with 5 DMUs (step 5 of 12 )"
    #> [1] "Computing maximal friends with 6 DMUs (step 6 of 12 )"
    #> [1] "Computing maximal friends with 7 DMUs (step 7 of 12 )"
    #> [1] "Computing maximal friends with 8 DMUs (step 8 of 12 )"
    #> [1] "Computing maximal friends with 9 DMUs (step 9 of 12 )"
    #> [1] "Computing maximal friends with 10 DMUs (step 10 of 12 )"
    #> [1] "Computing maximal friends with 11 DMUs (step 11 of 12 )"
    #> [1] "Computing maximal friends with 12 DMUs (step 12 of 12 )"
    #> [1] "Computing maximal friends with 1 DMUs (step 1 of 14 )"
    #> [1] "Computing maximal friends with 2 DMUs (step 2 of 14 )"
    #> [1] "Computing maximal friends with 3 DMUs (step 3 of 14 )"
    #> [1] "Computing maximal friends with 4 DMUs (step 4 of 14 )"
    #> [1] "Computing maximal friends with 5 DMUs (step 5 of 14 )"
    #> [1] "Computing maximal friends with 6 DMUs (step 6 of 14 )"
    #> [1] "Computing maximal friends with 7 DMUs (step 7 of 14 )"
    #> [1] "Computing maximal friends with 8 DMUs (step 8 of 14 )"
    #> [1] "Computing maximal friends with 9 DMUs (step 9 of 14 )"
    #> [1] "Computing maximal friends with 10 DMUs (step 10 of 14 )"
    #> [1] "Computing maximal friends with 11 DMUs (step 11 of 14 )"
    #> [1] "Computing maximal friends with 12 DMUs (step 12 of 14 )"
    #> [1] "Computing maximal friends with 13 DMUs (step 13 of 14 )"
    #> [1] "Computing maximal friends with 14 DMUs (step 14 of 14 )"
    #> [1] "Computing maximal friends with 1 DMUs (step 1 of 13 )"
    #> [1] "Computing maximal friends with 2 DMUs (step 2 of 13 )"
    #> [1] "Computing maximal friends with 3 DMUs (step 3 of 13 )"
    #> [1] "Computing maximal friends with 4 DMUs (step 4 of 13 )"
    #> [1] "Computing maximal friends with 5 DMUs (step 5 of 13 )"
    #> [1] "Computing maximal friends with 6 DMUs (step 6 of 13 )"
    #> [1] "Computing maximal friends with 7 DMUs (step 7 of 13 )"
    #> [1] "Computing maximal friends with 8 DMUs (step 8 of 13 )"
    #> [1] "Computing maximal friends with 9 DMUs (step 9 of 13 )"
    #> [1] "Computing maximal friends with 10 DMUs (step 10 of 13 )"
    #> [1] "Computing maximal friends with 11 DMUs (step 11 of 13 )"
    #> [1] "Computing maximal friends with 12 DMUs (step 12 of 13 )"
    #> [1] "Computing maximal friends with 13 DMUs (step 13 of 13 )"
    #> [1] "Computing maximal friends with 1 DMUs (step 1 of 14 )"
    #> [1] "Computing maximal friends with 2 DMUs (step 2 of 14 )"
    #> [1] "Computing maximal friends with 3 DMUs (step 3 of 14 )"
    #> [1] "Computing maximal friends with 4 DMUs (step 4 of 14 )"
    #> [1] "Computing maximal friends with 5 DMUs (step 5 of 14 )"
    #> [1] "Computing maximal friends with 6 DMUs (step 6 of 14 )"
    #> [1] "Computing maximal friends with 7 DMUs (step 7 of 14 )"
    #> [1] "Computing maximal friends with 8 DMUs (step 8 of 14 )"
    #> [1] "Computing maximal friends with 9 DMUs (step 9 of 14 )"
    #> [1] "Computing maximal friends with 10 DMUs (step 10 of 14 )"
    #> [1] "Computing maximal friends with 11 DMUs (step 11 of 14 )"
    #> [1] "Computing maximal friends with 12 DMUs (step 12 of 14 )"
    #> [1] "Computing maximal friends with 13 DMUs (step 13 of 14 )"
    #> [1] "Computing maximal friends with 14 DMUs (step 14 of 14 )"

    #> $nnet
    #> Neural Network
    #>
    #> 137 samples
    #>   5 predictor
    #>   2 classes: 'efficient', 'not_efficient'
    #>
    #> Pre-processing: centered (5), scaled (5)
    #> Resampling: None

    #> $nnet
    #>     Imbalance_rate size decay Accuracy Kappa Recall Specificity Precision   F1
    #> 163            0.4   10 1e-05     0.92  0.71   0.87        0.93       0.7 0.76
    #>     Balanced_Accuracy G_mean ROC_AUC PR_AUC Cross_Entropy
    #> 163               0.9   0.88     0.9   0.69          1.59
    #>     Cross_Entropy_Efficient_class Cross_Entropy_not_Efficient_class AccuracySD
    #> 163                          4.61                              1.06       0.07
    #>     KappaSD RecallSD SpecificitySD PrecisionSD F1SD Balanced_AccuracySD
    #> 163    0.27      0.3          0.07        0.21 0.23                0.15
    #>     G_meanSD ROC_AUCSD PR_AUCSD Cross_EntropySD Cross_Entropy_Efficient_classSD
    #> 163     0.18       0.2     0.07            2.14                            10.3
    #>     Cross_Entropy_not_Efficient_classSD diff_imbalance
    #> 163                                1.01         0.7546

## XAI method for global importance

This example uses SHAP (SHapley Additive exPlanations) computed with the fastshap package to estimate global feature importance with `PEAXAI_global_importance`. We approximate Shapley values via Monte Carlo sampling (`nsim`) and obtain a global importance score by aggregating absolute SHAP values across observations (and then normalizing to relative importance). For alternative XAI methods and options, see the package documentation.

    importance_method <- list(
        name = "SHAP",
        nsim = 200
    )

## Apply XAI method on the model fine-tuned.

If the method needs a reference distribution or to train a surrogate, use `background` to choose that dataset. `target` selects the dataset on which explanations are computed.

If `target` = `train`, relative importances are computed on the training distribution and thus reflect what the model actually learned during fitting.

If `target` = `real`, relative importances are computed on a dataset intended to approximate the real-world (deployment) distribution, yielding importances that better represent the underlying problem as observed in practice.

    relative_importance <- PEAXAI_global_importance(
      final_model = models[["best_model_fit"]][["nnet"]],
      x = x,
      y = y,
      explain_data = data,
      reference_data = data,
      importance_method = importance_method
    )
    #>   |                                                                              |                                                                      |   0%  |                                                                              |=                                                                     |   1%  |                                                                              |=                                                                     |   2%  |                                                                              |==                                                                    |   3%  |                                                                              |===                                                                   |   4%  |                                                                              |====                                                                  |   5%  |                                                                              |====                                                                  |   6%  |                                                                              |=====                                                                 |   7%  |                                                                              |======                                                                |   8%  |                                                                              |======                                                                |   9%  |                                                                              |=======                                                               |  10%  |                                                                              |========                                                              |  11%  |                                                                              |=========                                                             |  12%  |                                                                              |=========                                                             |  13%  |                                                                              |==========                                                            |  14%  |                                                                              |===========                                                           |  15%  |                                                                              |============                                                          |  16%  |                                                                              |============                                                          |  18%  |                                                                              |=============                                                         |  19%  |                                                                              |==============                                                        |  20%  |                                                                              |==============                                                        |  21%  |                                                                              |===============                                                       |  22%  |                                                                              |================                                                      |  23%  |                                                                              |=================                                                     |  24%  |                                                                              |=================                                                     |  25%  |                                                                              |==================                                                    |  26%  |                                                                              |===================                                                   |  27%  |                                                                              |===================                                                   |  28%  |                                                                              |====================                                                  |  29%  |                                                                              |=====================                                                 |  30%  |                                                                              |======================                                                |  31%  |                                                                              |======================                                                |  32%  |                                                                              |=======================                                               |  33%  |                                                                              |========================                                              |  34%  |                                                                              |=========================                                             |  35%  |                                                                              |=========================                                             |  36%  |                                                                              |==========================                                            |  37%  |                                                                              |===========================                                           |  38%  |                                                                              |===========================                                           |  39%  |                                                                              |============================                                          |  40%  |                                                                              |=============================                                         |  41%  |                                                                              |==============================                                        |  42%  |                                                                              |==============================                                        |  43%  |                                                                              |===============================                                       |  44%  |                                                                              |================================                                      |  45%  |                                                                              |================================                                      |  46%  |                                                                              |=================================                                     |  47%  |                                                                              |==================================                                    |  48%  |                                                                              |===================================                                   |  49%  |                                                                              |===================================                                   |  51%  |                                                                              |====================================                                  |  52%  |                                                                              |=====================================                                 |  53%  |                                                                              |======================================                                |  54%  |                                                                              |======================================                                |  55%  |                                                                              |=======================================                               |  56%  |                                                                              |========================================                              |  57%  |                                                                              |========================================                              |  58%  |                                                                              |=========================================                             |  59%  |                                                                              |==========================================                            |  60%  |                                                                              |===========================================                           |  61%  |                                                                              |===========================================                           |  62%  |                                                                              |============================================                          |  63%  |                                                                              |=============================================                         |  64%  |                                                                              |=============================================                         |  65%  |                                                                              |==============================================                        |  66%  |                                                                              |===============================================                       |  67%  |                                                                              |================================================                      |  68%  |                                                                              |================================================                      |  69%  |                                                                              |=================================================                     |  70%  |                                                                              |==================================================                    |  71%  |                                                                              |===================================================                   |  72%  |                                                                              |===================================================                   |  73%  |                                                                              |====================================================                  |  74%  |                                                                              |=====================================================                 |  75%  |                                                                              |=====================================================                 |  76%  |                                                                              |======================================================                |  77%  |                                                                              |=======================================================               |  78%  |                                                                              |========================================================              |  79%  |                                                                              |========================================================              |  80%  |                                                                              |=========================================================             |  81%  |                                                                              |==========================================================            |  82%  |                                                                              |==========================================================            |  84%  |                                                                              |===========================================================           |  85%  |                                                                              |============================================================          |  86%  |                                                                              |=============================================================         |  87%  |                                                                              |=============================================================         |  88%  |                                                                              |==============================================================        |  89%  |                                                                              |===============================================================       |  90%  |                                                                              |================================================================      |  91%  |                                                                              |================================================================      |  92%  |                                                                              |=================================================================     |  93%  |                                                                              |==================================================================    |  94%  |                                                                              |==================================================================    |  95%  |                                                                              |===================================================================   |  96%  |                                                                              |====================================================================  |  97%  |                                                                              |===================================================================== |  98%  |                                                                              |===================================================================== |  99%  |                                                                              |======================================================================| 100%

    #>            total_assets  employees fixed_assets personnel_expenses
    #> importance    0.1662237 0.05413211    0.1393984          0.2186649
    #>            operating_income
    #> importance        0.4215809

## Selected efficiency thresholds

We evaluate results at three efficiency cutoffs: 0.75, 0.85, and 0.95.

    efficiency_thresholds <- seq(0.75, 0.95, 0.1)

## Directional vector for target setting

We define a global, model-aware direction for improving inputs/outputs.

`relative_importance` guides the direction using the model’s global importance.

`scope` = `global` applies a single direction to all DMUs.

The argument `relative_importance` is the direction to make the counterfactual analysis. The directional vector can be custom or provided by PEAXAI_global_importance funtion.

For example, if the directional vector is custom: If it not possible (or we do not want) to change a specific input (like `employees`), we need to write:

    relative_importance_custom <- t(matrix(
      data = c(0.2, 0, 0.2, 0.2, 0.4),
    ))
    relative_importance_custom <- as.data.frame(relative_importance_custom)
    names(relative_importance_custom) <- names(data)[c(x,y)]

    #>   total_assets employees fixed_assets personnel_expenses operating_income
    #> 1          0.2         0          0.2                0.2              0.4

But, if we do not know which direction define, we can use the relative importace by the model fitted:

    directional_vector <- list(
      relative_importance = relative_importance,
      baseline  = "mean"
    )

## Compute targets at selected thresholds

Given the thresholds and directional vector, we compute feasible improvement targets for each DMU. Key controls:

`n_expand` = 0.5: expansion factor for the search neighborhood.

`n_grid` = 50: grid resolution for exploring adjustments.

`max_y` = 2, `min_x` = 1: bounds that cap output expansion and input contraction.

    targets <- PEAXAI_counterfactuals(
      data = data,
      x = x,
      y = y,
      final_model = models[["best_model_fit"]][["nnet"]],
      efficiency_thresholds = efficiency_thresholds,
      directional_vector = directional_vector,
      n_expand = 0.25,
      n_grid = 50,
      max_y = 1,
      min_x = 1
    )

    head(targets[["0.85"]][["counterfactual_dataset"]], 10)
    #>    total_assets employees fixed_assets personnel_expenses operating_income
    #> 1     258.53448   70.0000     84.15178           16.70692         460.5779
    #> 2     184.97800  261.0000     21.75500           19.92400         358.1300
    #> 3     128.93344  354.0000      5.75535           13.70937         356.9468
    #> 4      95.80099  954.5654     27.92053           34.96642         326.3438
    #> 5     141.12114 1056.6725     99.97868           29.13057         314.9019
    #> 6     146.45658  732.2426     73.71216           31.12281         313.9639
    #> 7     107.18140  754.8348     50.36552           21.87231         242.2955
    #> 8     228.13283  596.9995    131.10345           21.22260         307.5810
    #> 9      53.41076  442.0000     24.98992           19.24766         170.1763
    #> 10     82.34361  684.9669     20.26212           19.71057         203.9894

    head(targets[["0.85"]][["inefficiencies"]], 10)
    #>        betas probability
    #> 1  0.0000000        0.85
    #> 2  0.0000000        0.85
    #> 3  0.0000000        0.85
    #> 4  0.1683254        0.85
    #> 5  0.2421594        0.85
    #> 6  0.2851336        0.85
    #> 7  0.2526553        0.85
    #> 8  0.6139409        0.85
    #> 9  0.0000000        0.85
    #> 10 0.1883544        0.85

## Efficiency rankings

We compute efficiency rankings at each threshold using two bases:

`Predicted`: ranks by the model’s predicted probability of being efficient (`rank_basis` = `predicted`).

`Attainable`: ranks by attainable improvements/targets implied by the model (`rank_basis` = `attainable`).

    ranking <- PEAXAI_ranking(
      data = data,
      x = x,
      y = y,
      final_model = models[["best_model_fit"]][["nnet"]],
      rank_basis = "predicted"
    )

    ranking2 <- PEAXAI_ranking(
        data = data,
        x = x,
        y = y,
        final_model = models[["best_model_fit"]][["nnet"]],
        efficiency_thresholds = efficiency_thresholds,
        targets = targets,
        rank_basis = "attainable"
      )

    head(round(ranking, 4), 50)
    #>    Ranking DMU Probability_predicted
    #> 1        1   1                1.0000
    #> 2        2   2                1.0000
    #> 3        3   3                1.0000
    #> 4        4  17                1.0000
    #> 5        5  20                1.0000
    #> 6        6  46                1.0000
    #> 7        7  18                0.9999
    #> 8        8  62                0.9998
    #> 9        9  92                0.9998
    #> 10      10  97                0.9990
    #> 11      11   9                0.9987
    #> 12      12  56                0.9963
    #> 13      13  93                0.9937
    #> 14      14  36                0.9909
    #> 15      15  26                0.9786
    #> 16      16  25                0.0252
    #> 17      17  85                0.0056
    #> 18      18  42                0.0047
    #> 19      19  95                0.0045
    #> 20      20  75                0.0014
    #> 21      21  43                0.0013
    #> 22      22  31                0.0000
    #> 23      23  89                0.0000
    #> 24      24  91                0.0000
    #> 25      25  80                0.0000
    #> 26      26   4                0.0000
    #> 27      27   5                0.0000
    #> 28      28   6                0.0000
    #> 29      29   7                0.0000
    #> 30      30   8                0.0000
    #> 31      31  10                0.0000
    #> 32      32  11                0.0000
    #> 33      33  12                0.0000
    #> 34      34  13                0.0000
    #> 35      35  14                0.0000
    #> 36      36  15                0.0000
    #> 37      37  16                0.0000
    #> 38      38  19                0.0000
    #> 39      39  21                0.0000
    #> 40      40  22                0.0000
    #> 41      41  23                0.0000
    #> 42      42  24                0.0000
    #> 43      43  27                0.0000
    #> 44      44  28                0.0000
    #> 45      45  29                0.0000
    #> 46      46  30                0.0000
    #> 47      47  32                0.0000
    #> 48      48  33                0.0000
    #> 49      49  34                0.0000
    #> 50      50  35                0.0000

    head(round(ranking2[["0.85"]], 4), 50)
    #>    Ranking DMU Probability_predicted  betas Probability_target
    #> 1        1   1                1.0000 0.0000               0.85
    #> 2        2   2                1.0000 0.0000               0.85
    #> 3        3   3                1.0000 0.0000               0.85
    #> 4        4  17                1.0000 0.0000               0.85
    #> 5        5  20                1.0000 0.0000               0.85
    #> 6        6  46                1.0000 0.0000               0.85
    #> 7        7  18                0.9999 0.0000               0.85
    #> 8        8  62                0.9998 0.0000               0.85
    #> 9        9  92                0.9998 0.0000               0.85
    #> 10      10  97                0.9990 0.0000               0.85
    #> 11      11   9                0.9987 0.0000               0.85
    #> 12      12  56                0.9963 0.0000               0.85
    #> 13      13  93                0.9937 0.0000               0.85
    #> 14      14  36                0.9909 0.0000               0.85
    #> 15      15  26                0.9786 0.0000               0.85
    #> 16      16  85                0.0056 0.0049               0.85
    #> 17      17  95                0.0045 0.0068               0.85
    #> 18      18  75                0.0014 0.0076               0.85
    #> 19      19  91                0.0000 0.0107               0.85
    #> 20      20  31                0.0000 0.0116               0.85
    #> 21      21  44                0.0000 0.0136               0.85
    #> 22      22  43                0.0013 0.0155               0.85
    #> 23      23  71                0.0000 0.0173               0.85
    #> 24      24  25                0.0252 0.0177               0.85
    #> 25      25  73                0.0000 0.0201               0.85
    #> 26      26  94                0.0000 0.0234               0.85
    #> 27      27  59                0.0000 0.0279               0.85
    #> 28      28  42                0.0047 0.0303               0.85
    #> 29      29  70                0.0000 0.0320               0.85
    #> 30      30  88                0.0000 0.0352               0.85
    #> 31      31  67                0.0000 0.0431               0.85
    #> 32      32  64                0.0000 0.0453               0.85
    #> 33      33  86                0.0000 0.0459               0.85
    #> 34      34  69                0.0000 0.0511               0.85
    #> 35      35  22                0.0000 0.0529               0.85
    #> 36      36  66                0.0000 0.0599               0.85
    #> 37      37  77                0.0000 0.0627               0.85
    #> 38      38  61                0.0000 0.0633               0.85
    #> 39      39  48                0.0000 0.0637               0.85
    #> 40      40  68                0.0000 0.0672               0.85
    #> 41      41  23                0.0000 0.0674               0.85
    #> 42      42  76                0.0000 0.0687               0.85
    #> 43      43  72                0.0000 0.0701               0.85
    #> 44      44  16                0.0000 0.0726               0.85
    #> 45      45  53                0.0000 0.0732               0.85
    #> 46      46  58                0.0000 0.0749               0.85
    #> 47      47  54                0.0000 0.0857               0.85
    #> 48      48  49                0.0000 0.0947               0.85
    #> 49      49  55                0.0000 0.0976               0.85
    #> 50      50  15                0.0000 0.1071               0.85

## Peers by efficiency thresholds

For each threshold, we identify peer DMUs that serve as reference comparators.

`weighted` = FALSE treats peers uniformly; set TRUE to weight importance given `relative_importance`.

    peers <- PEAXAI_peer(
      data = data,
      x = x,
      y = y,
      final_model = models[["best_model_fit"]][["nnet"]],
      targets = targets,
      efficiency_thresholds = efficiency_thresholds,
      weighted = FALSE,
      relative_importance = relative_importance
    )

    head(peers, 50)
    #>    DMU 0.75 0.85 0.95
    #> 1    1    1    1    1
    #> 2    2    2    2    2
    #> 3    3    3    3    3
    #> 4    4    9    9    9
    #> 5    5    9    9    9
    #> 6    6    9    9    9
    #> 7    7    9    9    9
    #> 8    8    9    9    9
    #> 9    9    9    9    9
    #> 10  10    9    9    9
    #> 11  11    9    9    9
    #> 12  12   18   18   18
    #> 13  13    9    9    9
    #> 14  14    9    9    9
    #> 15  15   18   18   18
    #> 16  16    9    9    9
    #> 17  17   17   17   17
    #> 18  18   18   18   18
    #> 19  19    9    9    9
    #> 20  20   20   20   20
    #> 21  21    9    9    9
    #> 22  22   18   18   18
    #> 23  23    9    9    9
    #> 24  24   18   18   18
    #> 25  25   26   26   26
    #> 26  26   26   26   26
    #> 27  27   18   18   18
    #> 28  28   20   20   20
    #> 29  29   18   18   18
    #> 30  30   18   18   18
    #> 31  31   18   18   18
    #> 32  32   18   18   18
    #> 33  33    9    9    9
    #> 34  34   18   18   18
    #> 35  35   18   18   18
    #> 36  36   36   36   36
    #> 37  37   17   17   17
    #> 38  38    9    9    9
    #> 39  39   18   18   18
    #> 40  40   18   18   18
    #> 41  41   18   18   18
    #> 42  42   36   36   36
    #> 43  43   46   46   46
    #> 44  44   56   56   56
    #> 45  45   18   18   18
    #> 46  46   46   46   46
    #> 47  47   56   56   56
    #> 48  48   46   46   46
    #> 49  49   18   18   18
    #> 50  50   46   46   46