| Title: | Interpretable Contextual-Accountable and Responsible Machine Learning |
|---|---|
| Description: | A general-purpose framework for Interpretable Contextual-Accountable and Responsible Machine Learning (ICARM) that works with any clean tabular data across any application domain including healthcare, finance, social science, business, and education. Automatically detects whether a prediction task is binary classification, multi-class classification, or regression from the target variable type. Provides a unified entry point icarm_fit() supporting both interpretable learners (Classification and Regression Trees (CART), logistic regression, linear regression, Generalized Additive Models (GAM)) and extended learners (random forest, 'XGBoost', Support Vector Machines (SVM)) with consistent interfaces for global and local model explanation, group-level fairness auditing across protected attributes, probability calibration, threshold analysis, multi-model comparison, reproducible JavaScript Object Notation (JSON) audit trails, and accountability scorecards. The contextual accountability framing emphasises that algorithmic fairness and interpretability requirements depend on the deployment domain and must be evaluated accordingly. Extends the 'civic.icarm' framework (Awe 2025) <https://cran.r-project.org/package=civic.icarm> to general-purpose applications beyond civic and political education. |
| Authors: | Olushina Olawale Awe [aut, cre], Ludwigsburg University of Education [fnd] |
| Maintainer: | Olushina Olawale Awe <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-07-01 07:32:41 UTC |
| Source: | https://github.com/cran/icarm |
Generate a JSON audit trail
icarm_audit( object, metrics = NULL, fairness = NULL, notes = NULL, analyst = NULL, path = NULL )icarm_audit( object, metrics = NULL, fairness = NULL, notes = NULL, analyst = NULL, path = NULL )
object |
An 'icarm_model'. |
metrics |
Named numeric vector from [icarm_metrics()]. |
fairness |
An 'icarm_fairness' from [icarm_fairness()]. |
notes |
Character analyst notes. |
analyst |
Character analyst name. |
path |
File path to write JSON (optional). |
Invisibly, the JSON string.
m <- icarm_fit(Species ~ ., iris) trail <- icarm_audit(m, analyst = "O. O. Awe") cat(trail)m <- icarm_fit(Species ~ ., iris) trail <- icarm_audit(m, analyst = "O. O. Awe") cat(trail)
Probability calibration diagnostics
icarm_calibrate(object, data, outcome, positive = NULL, n_bins = 10L)icarm_calibrate(object, data, outcome, positive = NULL, n_bins = 10L)
object |
An 'icarm_model' (binary only). |
data |
A data frame. |
outcome |
Character outcome column. |
positive |
Positive class label. |
n_bins |
Number of bins (default 10). |
An object of class 'icarm_calibration'.
m <- icarm_fit( Petal.Width ~ Sepal.Length + Sepal.Width, iris, model = "linear") # calibration only for binary: data(icarm_medical) m2 <- icarm_fit(readmitted ~ ., icarm_medical) cal <- icarm_calibrate(m2, icarm_medical, "readmitted", "Yes") print(cal)m <- icarm_fit( Petal.Width ~ Sepal.Length + Sepal.Width, iris, model = "linear") # calibration only for binary: data(icarm_medical) m2 <- icarm_fit(readmitted ~ ., icarm_medical) cal <- icarm_calibrate(m2, icarm_medical, "readmitted", "Yes") print(cal)
Compare multiple icarm_models
icarm_compare( models, test_data, outcome, protected = NULL, positive = NULL, threshold = 0.5 )icarm_compare( models, test_data, outcome, protected = NULL, positive = NULL, threshold = 0.5 )
models |
A named list of 'icarm_model' objects. |
test_data |
A data frame for evaluation. |
outcome |
Character outcome column. |
protected |
Optional protected attribute for fairness. |
positive |
Positive class (binary). |
threshold |
Decision threshold (binary, default 0.5). |
A tibble of class 'icarm_comparison'.
sp <- icarm_split(iris, stratify = "Species") m1 <- icarm_fit(Species ~ ., sp$train, model = "cart") m2 <- icarm_fit(Species ~ ., sp$train, model = "multinomial") cmp <- icarm_compare(list(CART=m1, Multinom=m2), sp$test, outcome="Species") print(cmp)sp <- icarm_split(iris, stratify = "Species") m1 <- icarm_fit(Species ~ ., sp$train, model = "cart") m2 <- icarm_fit(Species ~ ., sp$train, model = "multinomial") cmp <- icarm_compare(list(CART=m1, Multinom=m2), sp$test, outcome="Species") print(cmp)
Equalized odds curves across thresholds
icarm_equalized_odds_curve( object, data, outcome, protected, positive = NULL, thresholds = seq(0.05, 0.95, 0.05) )icarm_equalized_odds_curve( object, data, outcome, protected, positive = NULL, thresholds = seq(0.05, 0.95, 0.05) )
object |
An 'icarm_model' (binary only). |
data |
A data frame. |
outcome |
Character outcome column. |
protected |
Character protected attribute column. |
positive |
Positive class label. |
thresholds |
Numeric threshold vector. |
A tibble with threshold, group, tpr, fpr, tnr.
Equity summary from a fairness report
icarm_equity_summary(fairness)icarm_equity_summary(fairness)
fairness |
An 'icarm_fairness' from [icarm_fairness()]. |
A named list of scalar equity indicators.
Generate global model explanations
icarm_explain(object, data = NULL, label = NULL)icarm_explain(object, data = NULL, label = NULL)
object |
An 'icarm_model' from [icarm_fit()]. |
data |
Optional data frame for DALEX explainer. |
label |
Optional label for DALEX explainer. |
An object of class 'icarm_explainer'.
m <- icarm_fit(Species ~ ., iris) ex <- icarm_explain(m) print(ex) icarm_plot_importance(ex)m <- icarm_fit(Species ~ ., iris) ex <- icarm_explain(m) print(ex) icarm_plot_importance(ex)
Local explanation for individual observations
icarm_explain_local(explainer, newdata, n_features = 10L)icarm_explain_local(explainer, newdata, n_features = 10L)
explainer |
An 'icarm_explainer' from [icarm_explain()]. |
newdata |
A data frame of observations to explain. |
n_features |
Max features to show (default 10). |
A list of tibbles, one per row of newdata.
m <- icarm_fit(Species ~ ., iris) ex <- icarm_explain(m) icarm_explain_local(ex, iris[1:2, ])m <- icarm_fit(Species ~ ., iris) ex <- icarm_explain(m) icarm_explain_local(ex, iris[1:2, ])
Group-level fairness audit
icarm_fairness( object, data, outcome, protected, positive = NULL, threshold = 0.5 )icarm_fairness( object, data, outcome, protected, positive = NULL, threshold = 0.5 )
object |
An 'icarm_model'. |
data |
A data frame with outcome and protected column. |
outcome |
Character. Outcome column name. |
protected |
Character. Protected attribute column name. |
positive |
Positive class (binary). |
threshold |
Decision threshold (binary, default 0.5). |
A tibble of class 'icarm_fairness'.
m <- icarm_fit(Species ~ ., iris) iris$size <- factor(ifelse(iris$Sepal.Length > 5.8, "large","small")) icarm_fairness(m, iris, "Species", "size")m <- icarm_fit(Species ~ ., iris) iris$size <- factor(ifelse(iris$Sepal.Length > 5.8, "large","small")) icarm_fairness(m, iris, "Species", "size")
A synthetic dataset of 1,000 loan applicants with financial and demographic variables. Suitable for binary classification (predicting loan default) and fairness auditing across gender and ethnicity — a classic algorithmic fairness benchmark.
icarm_financialicarm_financial
A tibble with 1,000 rows and 12 variables:
Integer. Applicant age (20-75).
Numeric. Annual income (USD).
Integer. Credit score (300-850).
Numeric. Requested loan amount (USD).
Integer. Loan term in months.
Factor. Employment category.
Factor. Yes or No.
Integer. Number of credit accounts.
Numeric. Debt-to-income ratio (0-1).
Factor. male or female.
Factor. Ethnicity category.
Factor. Yes (defaulted) or No.
Synthetic data generated by the icarm team.
data(icarm_financial) m <- icarm_fit(default ~ credit_score + income + loan_amount + debt_ratio, icarm_financial, model = "logistic", positive = "Yes")data(icarm_financial) m <- icarm_fit(default ~ credit_score + income + loan_amount + debt_ratio, icarm_financial, model = "logistic", positive = "Yes")
Single unified entry point for all icarm modelling. Automatically detects the prediction task from your target variable and supports both interpretable and extended (black-box) model families.
**Task auto-detection:** | Target type | Task | |—|—| | numeric / integer | regression | | factor / character, 2 levels | binary classification | | factor / character, 3+ levels | multi-class classification |
**Interpretable models (ICARM-compliant):** - '"cart"' — Classification/Regression Tree (rpart) - '"logistic"' — Logistic regression (binary) - '"logistic_l1"' — L1-penalised logistic (glmnet) - '"linear"' — Linear regression - '"gam"' — Generalised Additive Model (mgcv) - '"multinomial"' — Multinomial logistic (nnet)
**Extended models (requires post-hoc explanation):** - '"random_forest"' — Random forest (randomForest) - '"xgboost"' — Gradient boosting (xgboost) - '"svm"' — Support vector machine (e1071)
icarm_fit( formula, data, task = "auto", model = "auto", seed = 2025L, positive = NULL, cart_control = NULL, ... )icarm_fit( formula, data, task = "auto", model = "auto", seed = 2025L, positive = NULL, cart_control = NULL, ... )
formula |
A model formula, e.g. 'outcome ~ .' or 'outcome ~ x1 + x2'. |
data |
A 'data.frame' or 'tibble'. |
task |
One of '"auto"' (default), '"binary"', '"multiclass"', or '"regression"'. |
model |
Character. Model type. Use '"auto"' for CART (default), or specify any model from the list above. |
seed |
Integer random seed for reproducibility (default 2025). |
positive |
Positive class label for binary classification. |
cart_control |
Optional [rpart::rpart.control()] for CART. |
... |
Additional arguments passed to the underlying fitter. |
An S3 object of class 'icarm_model' with full provenance.
# Works on any data — task auto-detected m1 <- icarm_fit(Species ~ ., iris) # multiclass m2 <- icarm_fit(Sepal.Length ~ ., iris) # regression # Extended models m3 <- icarm_fit(Species ~ ., iris, model = "random_forest") # Built-in datasets data(icarm_medical) m4 <- icarm_fit(readmitted ~ ., icarm_medical, model = "cart")# Works on any data — task auto-detected m1 <- icarm_fit(Species ~ ., iris) # multiclass m2 <- icarm_fit(Sepal.Length ~ ., iris) # regression # Extended models m3 <- icarm_fit(Species ~ ., iris, model = "random_forest") # Built-in datasets data(icarm_medical) m4 <- icarm_fit(readmitted ~ ., icarm_medical, model = "cart")
A synthetic dataset of 500 hospital patients with clinical and administrative variables, designed for binary classification (predicting 30-day readmission) and fairness auditing across gender and insurance type.
icarm_medicalicarm_medical
A tibble with 500 rows and 12 variables:
Integer. Patient age (18-90).
Factor. male or female.
Numeric. Body mass index.
Integer. Systolic blood pressure (mmHg).
Integer. Diastolic blood pressure (mmHg).
Integer. Fasting glucose (mg/dL).
Factor. Yes or No.
Factor. Yes or No.
Factor. Public, Private, or None.
Integer. Prior hospital visits.
Integer. Current stay in days.
Factor. Yes (readmitted within 30 days) or No.
Synthetic data generated by the icarm team.
data(icarm_medical) m <- icarm_fit(readmitted ~ ., icarm_medical, model = "logistic", positive = "Yes")data(icarm_medical) m <- icarm_fit(readmitted ~ ., icarm_medical, model = "logistic", positive = "Yes")
Compute performance metrics for any task
icarm_metrics(y_true, y_pred, y_prob = NULL, positive = NULL, type = "auto")icarm_metrics(y_true, y_pred, y_prob = NULL, positive = NULL, type = "auto")
y_true |
True outcome values. |
y_pred |
Predicted values. |
y_prob |
Numeric probability for positive class (binary, for AUC). |
positive |
Positive class label (binary classification). |
type |
One of '"auto"', '"binary"', '"multiclass"', '"regression"'. |
A named numeric vector of metrics.
# Classification y <- factor(c("yes","no","yes","yes","no")) yhat <- factor(c("yes","no","no","yes","no")) icarm_metrics(y, yhat, positive = "yes") # Regression icarm_metrics(c(1,2,3,4,5), c(1.1,2.2,2.9,4.1,4.8)) # Multiclass m <- icarm_fit(Species ~ ., iris) icarm_metrics(iris$Species, predict(m, iris))# Classification y <- factor(c("yes","no","yes","yes","no")) yhat <- factor(c("yes","no","no","yes","no")) icarm_metrics(y, yhat, positive = "yes") # Regression icarm_metrics(c(1,2,3,4,5), c(1.1,2.2,2.9,4.1,4.8)) # Multiclass m <- icarm_fit(Species ~ ., iris) icarm_metrics(iris$Species, predict(m, iris))
Plot calibration curve
icarm_plot_calibration(calibration, title = NULL)icarm_plot_calibration(calibration, title = NULL)
calibration |
An 'icarm_calibration' from [icarm_calibrate()]. |
title |
Optional title. |
A ggplot2 object.
Plot multi-model comparison
icarm_plot_comparison( comparison, metrics = c("accuracy", "f1", "max_tpr_gap", "min_dp_ratio"), title = NULL )icarm_plot_comparison( comparison, metrics = c("accuracy", "f1", "max_tpr_gap", "min_dp_ratio"), title = NULL )
comparison |
An 'icarm_comparison' from [icarm_compare()]. |
metrics |
Character vector of metric columns. |
title |
Optional title. |
A ggplot2 object.
Plot confusion matrix
icarm_plot_confusion(y_true, y_pred, title = NULL)icarm_plot_confusion(y_true, y_pred, title = NULL)
y_true |
Factor of true outcomes. |
y_pred |
Factor of predicted outcomes. |
title |
Optional title. |
A ggplot2 object.
m <- icarm_fit(Species ~ ., iris) yhat <- predict(m, iris) icarm_plot_confusion(iris$Species, yhat)m <- icarm_fit(Species ~ ., iris) yhat <- predict(m, iris) icarm_plot_confusion(iris$Species, yhat)
Plot group-level fairness metric
icarm_plot_fairness(fairness, metric = "acc", title = NULL, ref_line = NULL)icarm_plot_fairness(fairness, metric = "acc", title = NULL, ref_line = NULL)
fairness |
An 'icarm_fairness' from [icarm_fairness()]. |
metric |
Character. Column to plot. |
title |
Optional title. |
ref_line |
Optional numeric reference line. |
A ggplot2 object.
m <- icarm_fit(Species ~ ., iris) iris$size <- factor(ifelse(iris$Sepal.Length>5.8,"large","small")) f <- icarm_fairness(m, iris, "Species", "size") icarm_plot_fairness(f, metric = "acc")m <- icarm_fit(Species ~ ., iris) iris$size <- factor(ifelse(iris$Sepal.Length>5.8,"large","small")) f <- icarm_fairness(m, iris, "Species", "size") icarm_plot_fairness(f, metric = "acc")
Plot feature importance
icarm_plot_importance(explainer, n_features = 15L, title = NULL)icarm_plot_importance(explainer, n_features = 15L, title = NULL)
explainer |
An 'icarm_explainer' from [icarm_explain()]. |
n_features |
Max features to display (default 15). |
title |
Optional plot title. |
A ggplot2 object.
m <- icarm_fit(Species ~ ., iris) ex <- icarm_explain(m) icarm_plot_importance(ex)m <- icarm_fit(Species ~ ., iris) ex <- icarm_explain(m) icarm_plot_importance(ex)
Plot per-group ROC curves
icarm_plot_roc_groups(eoc_tbl, title = NULL)icarm_plot_roc_groups(eoc_tbl, title = NULL)
eoc_tbl |
A tibble from [icarm_equalized_odds_curve()]. |
title |
Optional title. |
A ggplot2 object.
Plot threshold performance curves
icarm_plot_thresholds( thresholds_tbl, metrics = c("accuracy", "recall", "precision", "f1"), title = NULL )icarm_plot_thresholds( thresholds_tbl, metrics = c("accuracy", "recall", "precision", "f1"), title = NULL )
thresholds_tbl |
A tibble from [icarm_thresholds()]. |
metrics |
Character vector of metric columns. |
title |
Optional title. |
A ggplot2 object.
A synthetic dataset of 150 individuals capturing experiences of racism, policing, migration, and civic participation across multiple demographic groups. Suitable for fairness auditing, regression, binary, and multi-class classification.
icarm_racism_surveyicarm_racism_survey
A tibble with 150 rows and 16 variables:
Integer. Age in years (18-75).
Factor. male, female, diverse.
Factor. blonde, brown, black, other.
Factor. light, medium, dark.
Factor. single, engaged, married.
Integer 0-10. Perceived racism impact.
Factor. 0 times, 1 time, 2 or more.
Factor. Yes or No.
Numeric. Monthly income (EUR).
Ordered factor. Education level.
Factor. Employment category.
Factor. Urban or Rural.
Factor. Religion category.
Ordered factor. Language level.
Integer 0-10.
Integer 0-3 (left to right).
Synthetic data generated by the icarm team.
data(icarm_racism_survey) m <- icarm_fit(racism_impact ~ ., icarm_racism_survey, model = "linear")data(icarm_racism_survey) m <- icarm_fit(racism_impact ~ ., icarm_racism_survey, model = "linear")
Generate a full accountability scorecard
icarm_scorecard( object, test_data, outcome, protected = NULL, positive = NULL, analyst = NULL, project = "icarm", path = NULL )icarm_scorecard( object, test_data, outcome, protected = NULL, positive = NULL, analyst = NULL, project = "icarm", path = NULL )
object |
An 'icarm_model'. |
test_data |
Data frame of test data. |
outcome |
Character outcome column. |
protected |
Optional protected attribute column. |
positive |
Positive class (binary). |
analyst |
Character analyst name. |
project |
Character project name. |
path |
Optional JSON output path. |
Invisibly, the scorecard list.
sp <- icarm_split(iris, stratify = "Species") m <- icarm_fit(Species ~ ., sp$train) iris_test <- sp$test iris_test$size <- factor( ifelse(iris_test$Sepal.Length > 5.8, "large","small")) icarm_scorecard(m, iris_test, outcome="Species", protected="size", project="Iris Demo")sp <- icarm_split(iris, stratify = "Species") m <- icarm_fit(Species ~ ., sp$train) iris_test <- sp$test iris_test$size <- factor( ifelse(iris_test$Sepal.Length > 5.8, "large","small")) icarm_scorecard(m, iris_test, outcome="Species", protected="size", project="Iris Demo")
Reproducible train/test split
icarm_split(data, prop = 0.75, seed = 2025L, stratify = NULL)icarm_split(data, prop = 0.75, seed = 2025L, stratify = NULL)
data |
A data.frame or tibble. |
prop |
Proportion for training (default 0.75). |
seed |
Integer seed (default 2025). |
stratify |
Optional column name for stratified split. |
A named list with train, test, seed, prop.
splits <- icarm_split(iris, prop = 0.8, stratify = "Species") nrow(splits$train)splits <- icarm_split(iris, prop = 0.8, stratify = "Species") nrow(splits$train)
Threshold sweep for binary classification
icarm_thresholds( y_true, y_prob, positive = NULL, thresholds = seq(0.1, 0.9, 0.05) )icarm_thresholds( y_true, y_prob, positive = NULL, thresholds = seq(0.1, 0.9, 0.05) )
y_true |
Factor of true class labels. |
y_prob |
Numeric probability vector for positive class. |
positive |
Positive class label. |
thresholds |
Numeric vector of thresholds to evaluate. |
A tibble with one row per threshold.
y <- factor(sample(c("yes","no"), 200, replace = TRUE)) p <- runif(200) thr <- icarm_thresholds(y, p, positive = "yes") icarm_plot_thresholds(thr)y <- factor(sample(c("yes","no"), 200, replace = TRUE)) p <- runif(200) thr <- icarm_thresholds(y, p, positive = "yes") icarm_plot_thresholds(thr)
Predict from an icarm_model
## S3 method for class 'icarm_model' predict(object, newdata, type = c("class", "prob"), threshold = 0.5, ...)## S3 method for class 'icarm_model' predict(object, newdata, type = c("class", "prob"), threshold = 0.5, ...)
object |
An 'icarm_model'. |
newdata |
A data frame for prediction. |
type |
For classification: '"class"' or '"prob"'. For regression: ignored. |
threshold |
Decision threshold for binary (default 0.5). |
... |
Ignored. |
Factor vector, probability matrix, or numeric vector.
m <- icarm_fit(Species ~ ., iris) predict(m, iris[1:5, ], type = "class")m <- icarm_fit(Species ~ ., iris) predict(m, iris[1:5, ], type = "class")
Print an icarm_model
## S3 method for class 'icarm_model' print(x, ...)## S3 method for class 'icarm_model' print(x, ...)
x |
An icarm_model object. |
... |
Further arguments passed to or from other methods. |
Invisibly returns the icarm_model object x. Called for its side effect of printing a formatted summary to the console.
Summary of an icarm_model
## S3 method for class 'icarm_model' summary(object, ...)## S3 method for class 'icarm_model' summary(object, ...)
object |
An icarm_model object. |
... |
Further arguments passed to or from other methods. |
Invisibly returns the summary of the underlying fitted model object. Called for its side effect of printing a detailed model summary to the console.