# ROBOSRMSMOTE

<!-- badges: start -->
![R](https://img.shields.io/badge/R-%3E%3D4.0.0-blue)
![License](https://img.shields.io/badge/License-GPL--3-green)
<!-- badges: end -->

## Overview

**ROBOSRMSMOTE** (Robust Oversampling with RM-SMOTE) provides a framework for 
imbalanced classification tasks. This package extends Mahalanobis distance-based 
oversampling techniques by integrating robust covariance estimators to 
better handle outliers and complex data distributions. The implemented 
methodology builds upon and significantly expands the RM-SMOTE algorithm 
originally proposed by Taban et al. (2025).

Seven robust covariance estimators are supported.

> Taban, R., Nunes, C. and Oliveira, M.R. (2025).
> *RM-SMOTE: a new robust balancing technique.*
> Statistical Methods & Applications.
> <https://doi.org/10.1007/s10260-025-00819-8>

---

## Installation

```r
install.packages("ROBOSRMSMOTE")
```

---

## Core Functions

| Function | Description |
|----------|-------------|
| `ROBOS_RM_SMOTE()` | Main function — generates synthetic minority observations |
| `weighting()` | Computes robust Mahalanobis weights for minority class |
| `get_robust_cov()` | Fits one of 7 robust covariance estimators |

---

## Supported Covariance Estimators

| `cov_method` | Estimator |
|---|---|
| `"mcd"` | Minimum Covariance Determinant *(default)* |
| `"mve"` | Minimum Volume Ellipsoid |
| `"mest"` | M-estimator |
| `"mmest"` | MM-estimator |
| `"sde"` | Stahel-Donoho Estimator |
| `"sest"` | S-estimator |
| `"ogk"` | Orthogonalized Gnanadesikan-Kettenring |

---

## Quick Start

```r
library(ROBOSRMSMOTE)

# Load the example dataset (haberman: IR ≈ 2.78, n = 306)
data(haberman)
table(haberman$class)
#> negative positive
#>      225       81

# Balance with ROBOS_RM_SMOTE using MCD (default)
balanced <- ROBOS_RM_SMOTE(dt = haberman, target = "positive", eIR = 1)
table(balanced$class)
#> negative positive
#>      225      225

# Use a different robust estimator
balanced_ogk <- ROBOS_RM_SMOTE(dt     = haberman,
                                target = "positive",
                                eIR    = 1,
                                cov_method  = "ogk",
                                weight_func = 2)   # omega_B weighting
table(balanced_ogk$class)
```

---

## Weighting Functions

| `weight_func` | Formula | Behaviour |
|---|---|---|
| `1` | ω_A: weight = 0 | Hard exclusion of outliers |
| `2` | ω_B: weight = 1/MD² | Soft down-weighting |
| `3` | ω_C: weight = τ/MD² | Minimal down-weighting |

---

## License

GPL-3 © Emre Dunder, Mehmet Ali Cengiz, Zainab Subhi Mahmood Hawrami, Abdulmohsen Alharthi
