| Title: | Probabilistic Efficiency Analysis Using Explainable Artificial Intelligence |
|---|---|
| Description: | Provides a probabilistic framework that integrates Data Envelopment Analysis (DEA) (Banker et al., 1984) <doi:10.1287/mnsc.30.9.1078> with machine learning classifiers (Kuhn, 2008) <doi:10.18637/jss.v028.i05> to estimate both the (in)efficiency status and the probability of efficiency for decision-making units. The approach trains predictive models on DEA-derived efficiency labels (Charnes et al., 1985) <doi:10.1016/0304-4076(85)90133-2>, enabling explainable artificial intelligence (XAI) workflows with global and local interpretability tools, including permutation importance (Molnar et al., 2018) <doi:10.21105/joss.00786>, Shapley value explanations (Strumbelj & Kononenko, 2014) <doi:10.1007/s10115-013-0679-x>, and sensitivity analysis (Cortez, 2011) <https://CRAN.R-project.org/package=rminer>. The framework also supports probability-threshold peer selection and counterfactual improvement recommendations for benchmarking and policy evaluation. The probabilistic efficiency framework is detailed in González-Moyano et al. (2025) "Probability-based Technical Efficiency Analysis through Machine Learning", in review for publication. |
| Authors: | Ricardo González Moyano [cre, aut] (ORCID: <https://orcid.org/0009-0002-8608-5545>), Juan Aparicio [aut] (ORCID: <https://orcid.org/0000-0002-0867-0004>), José Luis Zofío [aut] (ORCID: <https://orcid.org/0000-0003-1170-9501>), Víctor España [aut] (ORCID: <https://orcid.org/0000-0002-1807-6180>) |
| Maintainer: | Ricardo González Moyano <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.3 |
| Built: | 2026-11-17 14:59:12 UTC |
| Source: | https://github.com/rgonzalezmoyano/peaxai |
Identifies the maximal subsets of efficient Decision-Making Units (DMUs) that lie on the same face (facet) of the efficient frontier. It relies on the concept of "maximal friends" to determine which efficient units can be grouped together to form convex combinations under the chosen returns-to-scale assumption.
convex_facets(data, x, y, RTS = "vrs", verbose)convex_facets(data, x, y, RTS = "vrs", verbose)
data |
A |
x |
Integer vector indicating the column indexes of the input variables in |
y |
Integer vector indicating the column indexes of the output variables in |
RTS |
Text string or number defining the underlying DEA technology /
returns-to-scale assumption (default:
|
verbose |
Logical; if |
A matrix where each row represents a maximal facet, and the values are the row indices of the efficient DMUs in data that form that facet. Returns an empty matrix if there are no efficient units.
Dataset with 100 simulated decision-making units (DMUs) used to illustrate the basic workflow of PEAXAI in a simple single-input/single-output setting.
data(data)data(data)
A data.frame with 100 rows and 3 columns:
Input of the DMU (e.g., resource use, cost or effort).
Observed output, potentially affected by technical inefficiency.
Deterministic (theoretical) output on the efficient frontier.
Each DMU uses one input x1 to produce an output y. The variable
yD represents the theoretical output on the deterministic frontier,
that is, the output level that would be observed in the absence of
technical inefficiency.
The dataset is purely simulated and is intended for examples and vignettes.
It contains 100 DMUs with heterogeneous input levels and corresponding
output levels. The observed output y can be interpreted as
y <= yD, where the gap between yD and y reflects
technical inefficiency (plus possible noise, depending on how the data
were generated).
Simulated data generated by the authors for illustrative purposes.
data(data) str(data) summary(data) if (requireNamespace("ggplot2", quietly = TRUE)) { ggplot2::ggplot(data, ggplot2::aes(x = x1)) + ggplot2::geom_point(ggplot2::aes(y = y), alpha = 0.6) + ggplot2::geom_line(ggplot2::aes(y = yD), color = "red") + ggplot2::labs( x = "Input x1", y = "Output", title = "Simulated DMUs and theoretical frontier" ) + ggplot2::theme_minimal() }data(data) str(data) summary(data) if (requireNamespace("ggplot2", quietly = TRUE)) { ggplot2::ggplot(data, ggplot2::aes(x = x1)) + ggplot2::geom_point(ggplot2::aes(y = y), alpha = 0.6) + ggplot2::geom_line(ggplot2::aes(y = yD), color = "red") + ggplot2::labs( x = "Input x1", y = "Output", title = "Simulated DMUs and theoretical frontier" ) + ggplot2::theme_minimal() }
Dataset with 100 simulated decision-making units (DMUs) used to illustrate the basic workflow of PEAXAI in a simple single-input/single-output setting.
data(data_example)data(data_example)
A data.frame with 100 rows and 3 columns:
Input of the DMU (e.g., resource use, cost or effort).
Observed output, potentially affected by technical inefficiency.
Deterministic (theoretical) output on the efficient frontier.
Each DMU uses one input x1 to produce an output y. The variable
yD represents the theoretical output on the deterministic frontier,
that is, the output level that would be observed in the absence of
technical inefficiency.
The dataset is purely simulated and is intended for examples and vignettes.
It contains 100 DMUs with heterogeneous input levels and corresponding
output levels. The observed output y can be interpreted as
y <= yD, where the gap between yD and y reflects
technical inefficiency (plus possible noise, depending on how the data
were generated).
Simulated data generated by the authors for illustrative purposes.
data(data_example) str(data_example) summary(data_example) if (requireNamespace("ggplot2", quietly = TRUE)) { ggplot2::ggplot(data_example, ggplot2::aes(x = x1)) + ggplot2::geom_point(ggplot2::aes(y = y), alpha = 0.6) + ggplot2::geom_line(ggplot2::aes(y = yD), color = "red") + ggplot2::labs( x = "Input x1", y = "Output", title = "Simulated DMUs and theoretical frontier" ) + ggplot2::theme_minimal() }data(data_example) str(data_example) summary(data_example) if (requireNamespace("ggplot2", quietly = TRUE)) { ggplot2::ggplot(data_example, ggplot2::aes(x = x1)) + ggplot2::geom_point(ggplot2::aes(y = y), alpha = 0.6) + ggplot2::geom_line(ggplot2::aes(y = yD), color = "red") + ggplot2::labs( x = "Input x1", y = "Output", title = "Simulated DMUs and theoretical frontier" ) + ggplot2::theme_minimal() }
Dataset containing information on food industry companies located in Spain, used to illustrate efficiency analysis within the PEAXAI package.
data(data_SABI)data(data_SABI)
A data.frame with 1267 rows and 4 columns:
Tangible fixed assets (euros).
Personnel expenses (euros).
Operating income (euros).
Anonymized firm identifier identifying each DMU.
The dataset includes 1267 food industry firms, collected from the SABI database for the year 2024. Each observation corresponds to a single company. Variables reflect both operational and financial dimensions relevant for productivity and efficiency assessment.
The output variable is:
operating_income — Operating income (in euros), measuring revenues generated
from core business activities.
The input variables are:
fixed_assets — Tangible fixed assets (euros), such as buildings and machinery.
personnel_expenses — Personnel expenses (millions of euros), including salaries, benefits, and training.
The sample displays substantial dispersion across variables, encompassing both small and large firms. This heterogeneity affects measures of central tendency—mean and median values differ considerably—thus providing a realistic challenge for efficiency and explainability analyses.
SABI (Sistema de Análisis de Balances Ibéricos) database, 2024.
data(data_SABI) str(data_SABI) summary(data_SABI) if (requireNamespace("ggplot2", quietly = TRUE)) { ggplot2::ggplot(data_SABI, ggplot2::aes(x = personnel_expenses, y = operating_income)) + ggplot2::geom_point(alpha = 0.6) + ggplot2::labs( x = "Personnel expenses", y = "Operating income (euros)", title = "Spanish Food Industry Firms (2024)" ) + ggplot2::theme_minimal() + ggplot2::theme( plot.title = ggplot2::element_text(face = "bold"), axis.line = ggplot2::element_line(color = "black"), axis.ticks = ggplot2::element_line(color = "black"), panel.grid.minor = ggplot2::element_blank() ) }data(data_SABI) str(data_SABI) summary(data_SABI) if (requireNamespace("ggplot2", quietly = TRUE)) { ggplot2::ggplot(data_SABI, ggplot2::aes(x = personnel_expenses, y = operating_income)) + ggplot2::geom_point(alpha = 0.6) + ggplot2::labs( x = "Personnel expenses", y = "Operating income (euros)", title = "Spanish Food Industry Firms (2024)" ) + ggplot2::theme_minimal() + ggplot2::theme( plot.title = ggplot2::element_text(face = "bold"), axis.line = ggplot2::element_line(color = "black"), axis.ticks = ggplot2::element_line(color = "black"), panel.grid.minor = ggplot2::element_blank() ) }
Dataset containing information on food industry companies located in Spain, used to illustrate efficiency analysis within the PEAXAI package. The dataset reflects the institutional and market heterogeneity that shapes firm-level efficiency across Spain’s 17 autonomous communities.
data(firms)data(firms)
A data.frame with 917 rows and 6 columns:
Total assets (millions of euros).
Number of employees.
Tangible fixed assets (millions of euros).
Personnel expenses (millions of euros).
Operating income (millions of euros).
Autonomous community where the firm operates.
The dataset includes 917 food industry firms with more than 50 employees, collected from the SABI database for the year 2023. Each observation corresponds to a single company. Variables reflect both operational and financial dimensions relevant for productivity and efficiency assessment.
The output variable is:
operating_income — Operating income (in millions of euros), measuring revenues generated
from core business activities.
The input variables are:
total_assets — Total assets (millions of euros), representing resources employed.
employees — Number of employees, indicating workforce size (only firms with more than 50 workers are included).
fixed_assets — Tangible fixed assets (millions of euros), such as buildings and machinery.
personnel_expenses — Personnel expenses (millions of euros), including salaries, benefits, and training.
The variable autonomous_community identifies the territorial location of each firm within Spain.
The sample displays substantial dispersion across variables, encompassing both small and large firms. This heterogeneity affects measures of central tendency—mean and median values differ considerably—thus providing a realistic challenge for efficiency and explainability analyses.
SABI (Sistema de Análisis de Balances Ibéricos) database, 2023. Firms with more than 50 employees in the Spanish food industry.
data(firms) str(firms) summary(firms) if (requireNamespace("ggplot2", quietly = TRUE)) { ggplot2::ggplot(firms, ggplot2::aes(x = employees, y = operating_income)) + ggplot2::geom_point(alpha = 0.6) + ggplot2::labs( x = "Number of employees", y = "Operating income (millions of euros)", title = "Spanish Food Industry Firms (2023)" ) + ggplot2::theme_minimal() + ggplot2::theme( plot.title = ggplot2::element_text(face = "bold"), axis.line = ggplot2::element_line(color = "black"), axis.ticks = ggplot2::element_line(color = "black"), panel.grid.minor = ggplot2::element_blank() ) }data(firms) str(firms) summary(firms) if (requireNamespace("ggplot2", quietly = TRUE)) { ggplot2::ggplot(firms, ggplot2::aes(x = employees, y = operating_income)) + ggplot2::geom_point(alpha = 0.6) + ggplot2::labs( x = "Number of employees", y = "Operating income (millions of euros)", title = "Spanish Food Industry Firms (2023)" ) + ggplot2::theme_minimal() + ggplot2::theme( plot.title = ggplot2::element_text(face = "bold"), axis.line = ggplot2::element_line(color = "black"), axis.ticks = ggplot2::element_line(color = "black"), panel.grid.minor = ggplot2::element_blank() ) }
This function creates new DMUs to address data imbalances. If the majority class is efficient, it generates new inefficient DMUs by worsering the observed units. Conversely, if the majority class is inefficient, it projects inefficient DMUs to the frontier. Finally, a random selection if performed to keep a proportion of 0.65 for the majority class and 0.35 for the minority class.
get_SMOTE_DMUs( data, facets = NULL, x, y, RTS = "vrs", balance_data = NULL, SMOTE_DDF = FALSE, z_numeric = NULL, z_factor = NULL, alpha = FALSE, bandwidth = NULL, seed )get_SMOTE_DMUs( data, facets = NULL, x, y, RTS = "vrs", balance_data = NULL, SMOTE_DDF = FALSE, z_numeric = NULL, z_factor = NULL, alpha = FALSE, bandwidth = NULL, seed )
data |
A |
facets |
A |
x |
Column indexes of the input variables in the |
y |
Column indexes of the output variables in the |
RTS |
Text string or number defining the underlying DEA technology /
returns-to-scale assumption (default:
|
balance_data |
A numeric vector indicating the different levels of balance required (e.g., c(0.1, 0.45, 0.6)). |
SMOTE_DDF |
Logical. Determines how synthetic efficient units are
generated. By default, |
z_numeric |
Column indexes of the continuous environment variables (z) in the |
z_factor |
Column indexes of the factor environment variables (z) in the |
alpha |
This allow to choose the size of the Confidence Intervals computed. By defaulta alpha = FALSE. In this case no confidence interval are computed. |
bandwidth |
the bandwidth parameters for the unconditional kernel density estimator used in the conditional DEA framework. It is typically obtained using |
seed |
Integer. Seed for reproducibility. |
A list where each element corresponds to a balance level, containing a single data.frame
with the real and synthetic DMUs, correctly labeled.
Computes efficiency projections for each observation based on a trained
classifier from caret that provides class probabilities via
predict(type = "prob"). For each probability threshold, the function
finds the direction and magnitude of change in input–output space required
for a unit to reach a specified efficiency level, following a directional
distance approach.
PEAXAI_counterfactuals( data, x, y, z_numeric = NULL, z_factor = NULL, final_model, efficiency_thresholds, directional_vector, n_expand, n_grid, max_y = 1, min_x = 1 )PEAXAI_counterfactuals( data, x, y, z_numeric = NULL, z_factor = NULL, final_model, efficiency_thresholds, directional_vector, n_expand, n_grid, max_y = 1, min_x = 1 )
data |
A |
x |
A numeric vector indicating the column indexes of input variables in |
y |
A numeric vector indicating the column indexes of output variables in |
z_numeric |
Integer vector with column indices of numeric environment variables in |
z_factor |
Integer vector with column indices of factor environment variables in |
final_model |
A fitted caret model of class |
efficiency_thresholds |
A numeric vector of probability levels in (0,1)
that define the efficiency classes (e.g., |
directional_vector |
A
|
n_expand |
Numeric. Number of expansion steps used to enlarge the initial
search range for |
n_grid |
Integer. Number of grid points evaluated during each iteration
to refine the cutoff value of |
max_y |
Numeric. Upper-limit multiplier for output expansion in the search procedure (default = 1). |
min_x |
Numeric. Lower-limit multiplier for input contraction in the search procedure (default = 1). |
For each observation and for each probability level in efficiency_thresholds,
the function searches for the smallest directional distance such that
the predicted probability of belonging to the efficient class reaches the target.
A named list with one element per threshold (names are the thresholds
as character strings). Each element contains:
counterfactual_dataset: A data.frame of projected
input-output values at that threshold.
inefficiencies: A data.frame with the optimal
and the corresponding predicted probability.
find_beta_maxmin for initializing search bounds;
train for model training.
data("firms", package = "PEAXAI") # Firms of the Valencian Community: four inputs and one output data <- subset( firms, autonomous_community == "Comunidad Valenciana" ) x <- 1:4 y <- 5 models <- PEAXAI_fitting( data = data, x = x, y = y, RTS = "vrs", imbalance_rate = NULL, methods = list("glm" = list(weights = "dinamic")), trControl = list(method = "cv", number = 3), metric_priority = c("Balanced_Accuracy", "F1", "ROC_AUC"), seed = 1, verbose = FALSE ) final_model <- models[["best_model_fit"]][["glm"]] # The direction of the counterfactual search is given by the global # importance of the variables, rescaled around the sample mean. relative_importance <- PEAXAI_global_importance( final_model = final_model, x = x, y = y, explain_data = data, reference_data = final_model$trainingData, importance_method = list(name = "PI", n.repetitions = 5), seed = 1 ) directional_vector <- list( relative_importance = relative_importance, baseline = "mean" ) efficiency_thresholds <- c(0.75, 0.90) targets <- PEAXAI_counterfactuals( data = data, x = x, y = y, final_model = final_model, efficiency_thresholds = efficiency_thresholds, directional_vector = directional_vector, n_expand = 0.5, n_grid = 50, max_y = 2, min_x = 1 ) # One element per threshold, each with the projected DMUs and their beta names(targets) head(targets[["0.75"]][["counterfactual_dataset"]]) head(targets[["0.75"]][["inefficiencies"]])data("firms", package = "PEAXAI") # Firms of the Valencian Community: four inputs and one output data <- subset( firms, autonomous_community == "Comunidad Valenciana" ) x <- 1:4 y <- 5 models <- PEAXAI_fitting( data = data, x = x, y = y, RTS = "vrs", imbalance_rate = NULL, methods = list("glm" = list(weights = "dinamic")), trControl = list(method = "cv", number = 3), metric_priority = c("Balanced_Accuracy", "F1", "ROC_AUC"), seed = 1, verbose = FALSE ) final_model <- models[["best_model_fit"]][["glm"]] # The direction of the counterfactual search is given by the global # importance of the variables, rescaled around the sample mean. relative_importance <- PEAXAI_global_importance( final_model = final_model, x = x, y = y, explain_data = data, reference_data = final_model$trainingData, importance_method = list(name = "PI", n.repetitions = 5), seed = 1 ) directional_vector <- list( relative_importance = relative_importance, baseline = "mean" ) efficiency_thresholds <- c(0.75, 0.90) targets <- PEAXAI_counterfactuals( data = data, x = x, y = y, final_model = final_model, efficiency_thresholds = efficiency_thresholds, directional_vector = directional_vector, n_expand = 0.5, n_grid = 50, max_y = 2, min_x = 1 ) # One element per threshold, each with the projected DMUs and their beta names(targets) head(targets[["0.75"]][["counterfactual_dataset"]]) head(targets[["0.75"]][["inefficiencies"]])
Trains one or multiple classification algorithms to identify Pareto-efficient decision-making units (DMUs). It jointly searches model hyperparameters and the class-balancing level (synthetic samples via SMOTE) using k-fold cross- validation or a train/validation/test split, selecting the configuration that maximizes the specified metric(s). Returns, for each technique, the best fitted model together with training summaries, performance metrics, and the selected balancing level.
PEAXAI_fitting( data, x, y, RTS = "vrs", imbalance_rate = NULL, trControl, methods, metric_priority = "Balanced_Accuracy", hold_out = NULL, seed = 314, verbose = TRUE, z_numeric = NULL, z_factor = NULL, B = NULL, alpha = NULL, m = NULL )PEAXAI_fitting( data, x, y, RTS = "vrs", imbalance_rate = NULL, trControl, methods, metric_priority = "Balanced_Accuracy", hold_out = NULL, seed = 314, verbose = TRUE, z_numeric = NULL, z_factor = NULL, B = NULL, alpha = NULL, m = NULL )
data |
A |
x |
Integer vector with column indices of input variables in |
y |
Integer vector with column indices of output variables in |
RTS |
Text string or number defining the underlying DEA technology /
returns-to-scale assumption (default:
|
imbalance_rate |
Optional target(s) for class balance via SMOTE. If |
trControl |
A |
methods |
A |
metric_priority |
A |
hold_out |
Numeric proportion in (0,1) for validation split (default |
seed |
Integer. Seed for reproducibility. |
verbose |
Logical; if |
z_numeric |
Integer vector with column indices of numeric environment variables in |
z_factor |
Integer vector with column indices of factor environment variables in |
B |
number of bootstrap replicates in Conditional DEA. |
alpha |
This allow to choose the size of the Confidence Intervals computed. By defaulta alpha = FALSE. In this case no confidence interval are computed. |
m |
number of units to be included in the reference set. |
A "PEAXAI" (list) with the best technique, best fitted models and their performance and the results by fold.
data("firms", package = "PEAXAI") # Firms of the Valencian Community: 97 DMUs described by four inputs # (columns 1 to 4) and one output (column 5). data <- subset( firms, autonomous_community == "Comunidad Valenciana" ) x <- 1:4 y <- 5 # Resampling scheme: stratified 3-fold cross-validation trControl <- list( method = "cv", number = 3 ) # Candidate algorithm: logistic regression with dynamic class weights methods <- list( "glm" = list( weights = "dinamic" ) ) models <- PEAXAI_fitting( data = data, x = x, y = y, RTS = "vrs", imbalance_rate = NULL, methods = methods, trControl = trControl, metric_priority = c("Balanced_Accuracy", "F1", "ROC_AUC"), seed = 1, verbose = FALSE ) # Best fitted model for the 'glm' technique final_model <- models[["best_model_fit"]][["glm"]]data("firms", package = "PEAXAI") # Firms of the Valencian Community: 97 DMUs described by four inputs # (columns 1 to 4) and one output (column 5). data <- subset( firms, autonomous_community == "Comunidad Valenciana" ) x <- 1:4 y <- 5 # Resampling scheme: stratified 3-fold cross-validation trControl <- list( method = "cv", number = 3 ) # Candidate algorithm: logistic regression with dynamic class weights methods <- list( "glm" = list( weights = "dinamic" ) ) models <- PEAXAI_fitting( data = data, x = x, y = y, RTS = "vrs", imbalance_rate = NULL, methods = methods, trControl = trControl, metric_priority = c("Balanced_Accuracy", "F1", "ROC_AUC"), seed = 1, verbose = FALSE ) # Best fitted model for the 'glm' technique final_model <- models[["best_model_fit"]][["glm"]]
Computes global feature importance for a fitted classification model that separates Pareto-efficient DMUs, using one of three XAI backends:
"SA" — Sensitivity Analysis via rminer.
"SHAP" — Model-agnostic SHAP approximations via kernelshap.
"PI" — Permutation Importance via iml.
Importance is computed on the DMUs supplied in explain_data, using
reference_data (typically final_model$trainingData) as the reference
distribution. Importances are returned normalized to sum to 1.
PEAXAI_global_importance( final_model, x, y, z_numeric = NULL, z_factor = NULL, explain_data, reference_data, importance_method, seed = 314 )PEAXAI_global_importance( final_model, x, y, z_numeric = NULL, z_factor = NULL, explain_data, reference_data, importance_method, seed = 314 )
final_model |
A fitted model. If it is a base- |
x |
Integer or character vector with the columns used as inputs (predictors). |
y |
Integer or character vector with the columns used as outputs (targets used
to define |
z_numeric |
Integer vector with column indices of numeric environment variables in |
z_factor |
Integer vector with column indices of factor environment variables in |
explain_data |
A |
reference_data |
A |
importance_method |
A named list (or data.frame-like) with the backend and its args:
|
seed |
Integer. Seed for reproducibility. |
Internally, the function builds background/target sets with xai_prepare_sets().
For glm models, the positive class is assumed to be the second level
("efficient") and probabilities are extracted with type = "response".
For other models (e.g., caret), predict(type = "prob")[, "efficient"] is used.
A named numeric vector (or 1-row data.frame) of normalized importances, with names matching the predictor columns; the values sum to 1.
kernelshap, FeatureImp,
Importance
data("firms", package = "PEAXAI") # Firms of the Valencian Community: four inputs and one output data <- subset( firms, autonomous_community == "Comunidad Valenciana" ) x <- 1:4 y <- 5 models <- PEAXAI_fitting( data = data, x = x, y = y, RTS = "vrs", imbalance_rate = NULL, methods = list("glm" = list(weights = "dinamic")), trControl = list(method = "cv", number = 3), metric_priority = c("Balanced_Accuracy", "ROC_AUC"), seed = 1, verbose = FALSE ) final_model <- models[["best_model_fit"]][["glm"]] # Permutation importance (iml). Use list(name = "SHAP", bg_n = 50) for # kernelshap, or list(name = "SA", method = "1D-SA") for rminer. importance_method <- list(name = "PI", n.repetitions = 5) relative_importance <- PEAXAI_global_importance( final_model = final_model, x = x, y = y, explain_data = data, reference_data = final_model$trainingData, importance_method = importance_method, seed = 1 ) # One normalized weight per input and output; they add up to 1 relative_importancedata("firms", package = "PEAXAI") # Firms of the Valencian Community: four inputs and one output data <- subset( firms, autonomous_community == "Comunidad Valenciana" ) x <- 1:4 y <- 5 models <- PEAXAI_fitting( data = data, x = x, y = y, RTS = "vrs", imbalance_rate = NULL, methods = list("glm" = list(weights = "dinamic")), trControl = list(method = "cv", number = 3), metric_priority = c("Balanced_Accuracy", "ROC_AUC"), seed = 1, verbose = FALSE ) final_model <- models[["best_model_fit"]][["glm"]] # Permutation importance (iml). Use list(name = "SHAP", bg_n = 50) for # kernelshap, or list(name = "SA", method = "1D-SA") for rminer. importance_method <- list(name = "PI", n.repetitions = 5) relative_importance <- PEAXAI_global_importance( final_model = final_model, x = x, y = y, explain_data = data, reference_data = final_model$trainingData, importance_method = importance_method, seed = 1 ) # One normalized weight per input and output; they add up to 1 relative_importance
Computes local feature importance (i.e., per-observation explanations) for a fitted classification model that separates Pareto-efficient DMUs, using one of three XAI backends:
"SA" — Local Sensitivity Analysis via rminer.
"SHAP" — Model-agnostic SHAP approximations via kernelshap.
"LIME" — Model-agnostic LIME approximations via lime
You can compute local importance on specific DMUs provided in explain_data,
using reference_data as the reference distribution or training background.
For each target DMU, importances are returned normalized to sum to 1 within that DMU.
PEAXAI_local_importance( final_model, x, y, z_numeric = NULL, z_factor = NULL, explain_data, reference_data, importance_method, seed = 314 )PEAXAI_local_importance( final_model, x, y, z_numeric = NULL, z_factor = NULL, explain_data, reference_data, importance_method, seed = 314 )
final_model |
A fitted model. If it is a base- |
x |
Integer or character vector with the columns used as inputs (predictors). |
y |
Integer or character vector with the columns used as outputs (targets used
to define |
z_numeric |
Integer vector with column indices of numeric environment variables in |
z_factor |
Integer vector with column indices of factor environment variables in |
explain_data |
A |
reference_data |
A |
importance_method |
A named list (or data.frame-like) with the backend and its args:
|
seed |
Integer. Seed for reproducibility. |
Local explanations are produced for the predicted probability .
For glm models, the positive class is assumed to be the second level
("efficient") and probabilities are extracted with type = "response".
For other models (e.g., caret), predict(type = "prob")[, "efficient"] is used.
The meaning of “local importance” depends on the backend:
"SHAP" returns per-observation SHAP attributions; importances are computed
from attribution magnitudes (e.g., abs(SHAP)) and normalized to sum to 1 per DMU.
"LIME" fits a local surrogate linear model around the DMU using
permutations from the reference distribution; the absolute weights of the local
model are used as importance scores, normalized per DMU.
"SA" computes local sensitivity of to each feature around
the DMU (using the chosen SA method/measure) and normalizes sensitivities per DMU.
A numeric matrix (or data.frame) with one row per target observation and one
column per predictor. Each row is a normalized importance profile whose values sum to 1.
Column names match the predictor columns in x.
data("firms", package = "PEAXAI") # Firms of the Valencian Community: four inputs and one output data <- subset( firms, autonomous_community == "Comunidad Valenciana" ) x <- 1:4 y <- 5 models <- PEAXAI_fitting( data = data, x = x, y = y, RTS = "vrs", imbalance_rate = NULL, methods = list("glm" = list(weights = "dinamic")), trControl = list(method = "cv", number = 3), metric_priority = c("Balanced_Accuracy", "ROC_AUC"), seed = 1, verbose = FALSE ) final_model <- models[["best_model_fit"]][["glm"]] # SHAP attributions via kernelshap. 'bg_n' is the background sample size # (default 200); a smaller value keeps the example fast. importance_method <- list( name = "SHAP", bg_n = 50 ) imp_local <- PEAXAI_local_importance( final_model = final_model, x = x, y = y, explain_data = data, reference_data = final_model$trainingData, importance_method = importance_method, seed = 1 ) # One row per DMU; the absolute weights of each row add up to 1 head(imp_local)data("firms", package = "PEAXAI") # Firms of the Valencian Community: four inputs and one output data <- subset( firms, autonomous_community == "Comunidad Valenciana" ) x <- 1:4 y <- 5 models <- PEAXAI_fitting( data = data, x = x, y = y, RTS = "vrs", imbalance_rate = NULL, methods = list("glm" = list(weights = "dinamic")), trControl = list(method = "cv", number = 3), metric_priority = c("Balanced_Accuracy", "ROC_AUC"), seed = 1, verbose = FALSE ) final_model <- models[["best_model_fit"]][["glm"]] # SHAP attributions via kernelshap. 'bg_n' is the background sample size # (default 200); a smaller value keeps the example fast. importance_method <- list( name = "SHAP", bg_n = 50 ) imp_local <- PEAXAI_local_importance( final_model = final_model, x = x, y = y, explain_data = data, reference_data = final_model$trainingData, importance_method = importance_method, seed = 1 ) # One row per DMU; the absolute weights of each row add up to 1 head(imp_local)
Identifies peer units (i.e., reference benchmarks) for each decision-making unit (DMU) based on predicted probabilities of technical efficiency. Given a fitted classification model that estimates the probability of being efficient, the function selects, for each DMU, its nearest efficient peer according to Euclidean or weighted distances. Multiple efficiency thresholds can be specified to assess different levels of benchmarking stringency.
PEAXAI_peer( data, x, y, final_model, efficiency_thresholds, targets, weighted = FALSE, relative_importance = NULL )PEAXAI_peer( data, x, y, final_model, efficiency_thresholds, targets, weighted = FALSE, relative_importance = NULL )
data |
A |
x |
Integer vector indicating the column indices of input variables in |
y |
Integer vector indicating the column indices of output variables in |
final_model |
A fitted classification model used to estimate efficiency probabilities. Supported classes: |
efficiency_thresholds |
Numeric vector indicating the minimum probability values required to consider a DMU as efficient. |
targets |
The object returned by |
weighted |
Logical. If |
relative_importance |
Optional named numeric vector indicating the relative importance of each input/output variable (used when |
This function enables probabilistic peer identification under uncertainty, supporting flexible definitions of efficiency based on thresholds over estimated probabilities.
When weighted = TRUE, variable weights (e.g., derived from feature importance) modulate the peer selection process, allowing for context-aware benchmarking.
A data.frame with one row per DMU. The first column, DMU, is the
row index in data; the remaining columns are named after the efficiency thresholds
and contain, for each DMU, the index of its closest efficient peer at that threshold.
Distances are unweighted when weighted = FALSE and importance-weighted when
weighted = TRUE.
data("firms", package = "PEAXAI") # Firms of the Valencian Community: four inputs and one output data <- subset( firms, autonomous_community == "Comunidad Valenciana" ) x <- 1:4 y <- 5 models <- PEAXAI_fitting( data = data, x = x, y = y, RTS = "vrs", imbalance_rate = NULL, methods = list("glm" = list(weights = "dinamic")), trControl = list(method = "cv", number = 3), metric_priority = c("Balanced_Accuracy", "ROC_AUC"), seed = 1, verbose = FALSE ) final_model <- models[["best_model_fit"]][["glm"]] # Peers are searched among the counterfactual projections, so the # counterfactuals must be computed first. relative_importance <- PEAXAI_global_importance( final_model = final_model, x = x, y = y, explain_data = data, reference_data = final_model$trainingData, importance_method = list(name = "PI", n.repetitions = 5), seed = 1 ) efficiency_thresholds <- c(0.75, 0.90) targets <- PEAXAI_counterfactuals( data = data, x = x, y = y, final_model = final_model, efficiency_thresholds = efficiency_thresholds, directional_vector = list( relative_importance = relative_importance, baseline = "mean" ), n_expand = 0.5, n_grid = 50, max_y = 2, min_x = 1 ) # Unweighted (Euclidean) peers peers <- PEAXAI_peer( data = data, x = x, y = y, final_model = final_model, efficiency_thresholds = efficiency_thresholds, targets = targets, weighted = FALSE ) head(peers) # Peers weighted by the global importance of each variable peers_weighted <- PEAXAI_peer( data = data, x = x, y = y, final_model = final_model, efficiency_thresholds = efficiency_thresholds, targets = targets, weighted = TRUE, relative_importance = relative_importance )data("firms", package = "PEAXAI") # Firms of the Valencian Community: four inputs and one output data <- subset( firms, autonomous_community == "Comunidad Valenciana" ) x <- 1:4 y <- 5 models <- PEAXAI_fitting( data = data, x = x, y = y, RTS = "vrs", imbalance_rate = NULL, methods = list("glm" = list(weights = "dinamic")), trControl = list(method = "cv", number = 3), metric_priority = c("Balanced_Accuracy", "ROC_AUC"), seed = 1, verbose = FALSE ) final_model <- models[["best_model_fit"]][["glm"]] # Peers are searched among the counterfactual projections, so the # counterfactuals must be computed first. relative_importance <- PEAXAI_global_importance( final_model = final_model, x = x, y = y, explain_data = data, reference_data = final_model$trainingData, importance_method = list(name = "PI", n.repetitions = 5), seed = 1 ) efficiency_thresholds <- c(0.75, 0.90) targets <- PEAXAI_counterfactuals( data = data, x = x, y = y, final_model = final_model, efficiency_thresholds = efficiency_thresholds, directional_vector = list( relative_importance = relative_importance, baseline = "mean" ), n_expand = 0.5, n_grid = 50, max_y = 2, min_x = 1 ) # Unweighted (Euclidean) peers peers <- PEAXAI_peer( data = data, x = x, y = y, final_model = final_model, efficiency_thresholds = efficiency_thresholds, targets = targets, weighted = FALSE ) head(peers) # Peers weighted by the global importance of each variable peers_weighted <- PEAXAI_peer( data = data, x = x, y = y, final_model = final_model, efficiency_thresholds = efficiency_thresholds, targets = targets, weighted = TRUE, relative_importance = relative_importance )
Predicts probabilities for new decision-making units (DMUs) using a fitted
caret classification model. If calibration_model is provided,
the raw classifier probabilities are post-processed to obtain calibrated
probability estimates (e.g., Platt scaling via logistic regression or
isotonic calibration via a monotone mapping).
PEAXAI_predict(data, final_model)PEAXAI_predict(data, final_model)
data |
A |
final_model |
A fitted caret model provided by PEAXAI_fitting(). |
A numeric vector of predicted probabilities (raw or calibrated), one per
row of data.
data("firms", package = "PEAXAI") # Firms of the Valencian Community: four inputs and one output data <- subset( firms, autonomous_community == "Comunidad Valenciana" ) x <- 1:4 y <- 5 models <- PEAXAI_fitting( data = data, x = x, y = y, RTS = "vrs", imbalance_rate = NULL, methods = list("glm" = list(weights = "dinamic")), trControl = list(method = "cv", number = 3), metric_priority = c("Balanced_Accuracy", "ROC_AUC"), seed = 1, verbose = FALSE ) final_model <- models[["best_model_fit"]][["glm"]] # 'data' must contain every variable the model was trained on probabilities <- PEAXAI_predict( data = data[, c(x, y)], final_model = final_model ) head(probabilities)data("firms", package = "PEAXAI") # Firms of the Valencian Community: four inputs and one output data <- subset( firms, autonomous_community == "Comunidad Valenciana" ) x <- 1:4 y <- 5 models <- PEAXAI_fitting( data = data, x = x, y = y, RTS = "vrs", imbalance_rate = NULL, methods = list("glm" = list(weights = "dinamic")), trControl = list(method = "cv", number = 3), metric_priority = c("Balanced_Accuracy", "ROC_AUC"), seed = 1, verbose = FALSE ) final_model <- models[["best_model_fit"]][["glm"]] # 'data' must contain every variable the model was trained on probabilities <- PEAXAI_predict( data = data[, c(x, y)], final_model = final_model ) head(probabilities)
Produces efficiency rankings of decision-making units (DMUs) according to the probabilities estimated by a fitted classification model. Two ranking modes are supported:
"predicted": ranks DMUs solely by their predicted probability of being efficient.
"attainable": ranks DMUs hierarchically according to:
(1) the attainable (target) efficiency probability,
(2) the size of the improvement parameter (smaller is better),
and (3) the predicted efficiency probability (higher is better).
This allows to integrate both predictive and counterfactual (attainable) information into the efficiency ranking.
PEAXAI_ranking( data, x, y, final_model, efficiency_thresholds, targets = NULL, rank_basis )PEAXAI_ranking( data, x, y, final_model, efficiency_thresholds, targets = NULL, rank_basis )
data |
A |
x |
Integer vector specifying the column indices of input variables in |
y |
Integer vector specifying the column indices of output variables in |
final_model |
A fitted classification model used to estimate efficiency probabilities. Supported types are:
|
efficiency_thresholds |
Numeric vector defining one or more efficiency probability thresholds to determine the attainable frontier or peer set. |
targets |
The object returned by |
rank_basis |
Character string specifying the ranking criterion. Options are:
|
The attainable-based ranking combines predictive efficiency with the modeled potential
for improvement () and the probability of reaching a target frontier level.
This approach yields a more nuanced and interpretable prioritization of DMUs, reflecting
both their current and achievable performance under the estimated model.
When rank_basis = "attainable", ties in attainable probability are broken first
by the magnitude of (ascending), and then by the predicted probability
(descending).
If rank_basis = "predicted": a data.frame sorted by predicted efficiency probability.
If rank_basis = "attainable": a named list of data.frames, one per efficiency threshold,
each sorted according to the hierarchical ranking scheme described above.
data("firms", package = "PEAXAI") # Firms of the Valencian Community: four inputs and one output data <- subset( firms, autonomous_community == "Comunidad Valenciana" ) x <- 1:4 y <- 5 models <- PEAXAI_fitting( data = data, x = x, y = y, RTS = "vrs", imbalance_rate = NULL, methods = list("glm" = list(weights = "dinamic")), trControl = list(method = "cv", number = 3), metric_priority = c("Balanced_Accuracy", "ROC_AUC"), seed = 1, verbose = FALSE ) final_model <- models[["best_model_fit"]][["glm"]] # (1) Ranking by predicted probability: neither 'efficiency_thresholds' # nor 'targets' are needed. ranking <- PEAXAI_ranking( data = data, x = x, y = y, final_model = final_model, rank_basis = "predicted" ) head(ranking) # (2) Ranking by attainable probability: both arguments become mandatory. relative_importance <- PEAXAI_global_importance( final_model = final_model, x = x, y = y, explain_data = data, reference_data = final_model$trainingData, importance_method = list(name = "PI", n.repetitions = 5), seed = 1 ) efficiency_thresholds <- c(0.75, 0.90) targets <- PEAXAI_counterfactuals( data = data, x = x, y = y, final_model = final_model, efficiency_thresholds = efficiency_thresholds, directional_vector = list( relative_importance = relative_importance, baseline = "mean" ), n_expand = 0.5, n_grid = 50, max_y = 2, min_x = 1 ) ranking_attainable <- PEAXAI_ranking( data = data, x = x, y = y, final_model = final_model, efficiency_thresholds = efficiency_thresholds, targets = targets, rank_basis = "attainable" ) head(ranking_attainable[["0.75"]])data("firms", package = "PEAXAI") # Firms of the Valencian Community: four inputs and one output data <- subset( firms, autonomous_community == "Comunidad Valenciana" ) x <- 1:4 y <- 5 models <- PEAXAI_fitting( data = data, x = x, y = y, RTS = "vrs", imbalance_rate = NULL, methods = list("glm" = list(weights = "dinamic")), trControl = list(method = "cv", number = 3), metric_priority = c("Balanced_Accuracy", "ROC_AUC"), seed = 1, verbose = FALSE ) final_model <- models[["best_model_fit"]][["glm"]] # (1) Ranking by predicted probability: neither 'efficiency_thresholds' # nor 'targets' are needed. ranking <- PEAXAI_ranking( data = data, x = x, y = y, final_model = final_model, rank_basis = "predicted" ) head(ranking) # (2) Ranking by attainable probability: both arguments become mandatory. relative_importance <- PEAXAI_global_importance( final_model = final_model, x = x, y = y, explain_data = data, reference_data = final_model$trainingData, importance_method = list(name = "PI", n.repetitions = 5), seed = 1 ) efficiency_thresholds <- c(0.75, 0.90) targets <- PEAXAI_counterfactuals( data = data, x = x, y = y, final_model = final_model, efficiency_thresholds = efficiency_thresholds, directional_vector = list( relative_importance = relative_importance, baseline = "mean" ), n_expand = 0.5, n_grid = 50, max_y = 2, min_x = 1 ) ranking_attainable <- PEAXAI_ranking( data = data, x = x, y = y, final_model = final_model, efficiency_thresholds = efficiency_thresholds, targets = targets, rank_basis = "attainable" ) head(ranking_attainable[["0.75"]])
This function arranges the data in the required format and displays some error messages.
preprocessing(data, x, y)preprocessing(data, x, y)
data |
A |
x |
Column indexes of input variables in |
y |
Column indexes of output variables in |
It returns a matrix in the required format and displays some error messages.
This function is used to simulate a data.frame with some given Data Generation Process.
reffcy(DGP, parms)reffcy(DGP, parms)
DGP |
Data Generation Process:
|
parms |
|
Please refer to the help manuals of the mentioned functions for usage examples and more detailed information on the parameters.
data.frame simulated with the selected Data Generation Process.
set.seed(1) # 100 DMUs with 3 inputs and 1 output under variable returns to scale simulated_data <- reffcy( DGP = "cobb_douglas_XnY1", parms = list( N = 100, nX = 3, RTS = "vrs" ) ) # x1 ... x3 are the inputs, 'y' the observed output and 'yD' the # theoretical frontier head(simulated_data) # A stochastic frontier is obtained by setting sd_v > 0 noisy_data <- reffcy( DGP = "cobb_douglas_XnY1", parms = list(N = 100, nX = 1, RTS = "crs", sd_u = 0.4, sd_v = 0.1) ) str(noisy_data)set.seed(1) # 100 DMUs with 3 inputs and 1 output under variable returns to scale simulated_data <- reffcy( DGP = "cobb_douglas_XnY1", parms = list( N = 100, nX = 3, RTS = "vrs" ) ) # x1 ... x3 are the inputs, 'y' the observed output and 'yD' the # theoretical frontier head(simulated_data) # A stochastic frontier is obtained by setting sd_v > 0 noisy_data <- reffcy( DGP = "cobb_douglas_XnY1", parms = list(N = 100, nX = 1, RTS = "crs", sd_u = 0.4, sd_v = 0.1) ) str(noisy_data)
This function trains a set of models and selects best hyperparameters for each of them.
train_PEAXAI(data, method, parameters, trControl, metric_priority, seed)train_PEAXAI(data, method, parameters, trControl, metric_priority, seed)
data |
A |
method |
Parameters for controlling the training process (from the |
parameters |
A |
trControl |
A |
metric_priority |
A |
seed |
Integer. Seed for reproducibility. |
It returns a list with the chosen model.
Extracts and formats the training and/or target datasets from a machine learning model trained with caret::train,
allowing for distinction between using the full training data or only the original subset used for modeling.
It standardizes the class column to be named "class_efficiency" and positions it as the last column.
xai_prepare_sets( data, x, y, final_model, background, target, type, threshold, levels_order )xai_prepare_sets( data, x, y, final_model, background, target, type, threshold, levels_order )
data |
A |
x |
Not currently used. Reserved for future input variable selection. |
y |
Not currently used. Reserved for future output variable specification. |
final_model |
A trained model object of class |
background |
A character string, either |
target |
A character string, either |
type |
Not currently used. Reserved for future prediction types. |
threshold |
Not currently used. Reserved for future thresholding logic. |
levels_order |
A character vector specifying the levels of the response factor, typically |
A list with two elements:
train_dataA data.frame representing the background dataset, with the class column renamed to "class_efficiency" and positioned last.
target_dataA data.frame representing the target dataset, formatted in the same way.