# RPWNSC

**Run Purity Weighted Nearest Shrunken Centroid Feature Selection** for high-dimensional gene-expression classification.

RPWNSC is a simple filter-based feature ranking method. It is designed for settings where the number of features is much larger than the number of samples, such as microarray and other gene-expression classification datasets.

## What the method does

RPWNSC ranks each feature using two complementary ideas:

1. **Run purity score**: samples are sorted by a feature value, and the method checks whether samples from the same class appear in compact contiguous runs. A high score means the sorted labels are less mixed.
2. **Nearest shrunken centroid score**: the method measures standardized separation between each class centroid and the overall centroid, while accounting for within-class variation.

The final score is computed as:

```text
RPWNSC_score_j = run_purity_j * scaled_centroid_score_j
```

This product rewards features that show both compact class-label ordering and strong class discrimination. It also penalizes features that are strong according to only one of the two criteria.

## Why use RPWNSC?

- Works as a classifier-independent filter feature-selection method.
- Supports binary and multiclass class labels.
- Does not require wrapper search, feature clustering, or classifier-specific training during ranking.
- Returns the top feature indices and the final RPWNSC score for every feature.
- Includes a Huntington's disease gene-expression example dataset for demonstration.

## Installation

Install the source package file from your working directory:

```r
install.packages("RPWNSC_0.1.0.tar.gz", repos = NULL, type = "source")
library(RPWNSC)
```

## Quick example

```r
library(RPWNSC)

data(Huntington)

# Use the first 100 genes for a small demonstration.
out <- RPWNSC(Huntington$X[, 1:100], Huntington$Y, topK = 10)

# Top selected feature indices.
out$topK

# Scores for every feature.
out$Scores
```

## Output

`RPWNSC()` returns a list containing:

| Component | Description |
| --- | --- |
| `topK` | Integer vector containing the indices of the selected top ranked features. |
| `Scores` | Numeric vector containing the final RPWNSC score for every feature. |

## Example dataset

The package includes the Huntington's disease gene-expression dataset used for demonstration. It contains 31 samples, 22,283 gene-expression features, and 2 classes.

```r
data(Huntington)
dim(Huntington$X)
table(Huntington$Y)
```

## Reference

Ali, A., Khan, Z., and Aldahmani, S. (2026). *A run purity weighted nearest shrunken centroid feature selection for high-dimensional gene-expression classification*. Machine Learning with Applications, 25, 100947. DOI: https://doi.org/10.1016/j.mlwa.2026.100947. URL: https://www.sciencedirect.com/science/article/pii/S266682702600112X.
