| Title: | Pre-Modeling Statistical Audit Framework |
|---|---|
| Description: | Introduces a statistical validation layer between data preprocessing and predictive modeling. Evaluates the statistical readiness of tabular datasets through data quality assessment, leakage detection, transformation analysis, and feature stability. |
| Authors: | Arshit Choudhary [aut, cre, cph], Vanshika Sharma [aut, ctb], Amrit Pal [ths] |
| Maintainer: | Arshit Choudhary <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.0 |
| Built: | 2026-10-28 19:19:26 UTC |
| Source: | https://github.com/cran/PrismR |
Identifies potential sources of data leakage prior to predictive modeling. The assessment includes identifier columns, duplicate columns, high-cardinality features, predictors identical to the target, and predictors showing an almost perfect correlation with the target.
detect_leakage(data, target = NULL)detect_leakage(data, target = NULL)
data |
A data.frame to assess. |
target |
Optional name of the target variable. If supplied, predictors identical to the target or nearly perfectly correlated with the target are flagged as potential leakage. |
A named list containing:
Names of columns identified as potential identifiers.
Names of duplicated columns.
Names of high-cardinality columns.
Names of predictors identical to the target variable.
Numeric predictors with near-perfect correlation to the target.
Overall leakage score ranging from 0 to 100.
A data frame containing variable-level leakage diagnostics, including identifier, duplicate, high-cardinality, target leakage, correlation leakage, and leakage score.
# Supervised leakage detection res <- detect_leakage(airquality, target = "Ozone") res$leakage_score res$correlation_leakage # Unsupervised check for IDs and duplicates res_unsupervised <- detect_leakage(iris) res_unsupervised$identifier_columns# Supervised leakage detection res <- detect_leakage(airquality, target = "Ozone") res$leakage_score res$correlation_leakage # Unsupervised check for IDs and duplicates res_unsupervised <- detect_leakage(iris) res_unsupervised$identifier_columns
Evaluates feature distribution drift between reference and current datasets (or across sequential time partitions of a single dataset) using the Population Stability Index (PSI) and scale-normalized Wasserstein distance across both numeric and categorical variables.
feature_stability( data, current = NULL, split_ratio = 0.5, partition_col = NULL, verbose = FALSE )feature_stability( data, current = NULL, split_ratio = 0.5, partition_col = NULL, verbose = FALSE )
data |
A data.frame used as the reference baseline dataset (or the full dataset for single-dataset drift evaluation). |
current |
Optional current data.frame to compare against |
split_ratio |
Numeric. Proportion of rows to allocate to the reference dataset in single-dataset mode. Defaults to 0.5 (first 50% vs. last 50%). |
partition_col |
Optional character. Column name to order by before partitioning in single-dataset mode (e.g., a timestamp or sequence ID). |
verbose |
Logical. If TRUE, prints a formatted console stability report. Defaults to FALSE. |
Feature drift is evaluated using standard industry thresholds:
Stable (PSI < 0.10): Insignificant distributional shift.
Moderate Drift (0.10 <= PSI < 0.25): Noticeable shift; monitoring recommended.
Unstable / Severe Drift (PSI >= 0.25): Severe distributional divergence; retraining or feature review required.
For categorical variables and discrete bins, Bayesian Laplace smoothing is applied to prevent division-by-zero errors when frequencies are zero in one partition.
If only one dataset is supplied, the function performs a sequential
partition-based stability assessment (comparing the first partition to the
second partition of observations). For production monitoring, users should
provide reference and current datasets separately via data and current.
A list containing:
Overall stability score from 0 to 100.
Categorical stability verdict: "Stable", "Moderate Drift", or "Unstable".
A data frame of feature-level diagnostics containing variable, type, psi, wasserstein, stability_score, and status.
Character vector of features flagged with severe drift (PSI >= 0.25).
Character vector of features flagged with moderate drift (0.10 <= PSI < 0.25).
Character vector of features exhibiting stable distributions (PSI < 0.10).
Character string describing the assessment method used ("two_sample_comparison" or "sequential_partition").
# Single-dataset sequential drift evaluation res <- feature_stability(airquality) res$stability_score res$verdict # Comparing reference baseline vs current dataset ref <- data.frame(val = rnorm(100, 0, 1)) cur <- data.frame(val = rnorm(100, 2, 1)) res2 <- feature_stability(ref, current = cur) res2$verdict# Single-dataset sequential drift evaluation res <- feature_stability(airquality) res$stability_score res$verdict # Comparing reference baseline vs current dataset ref <- data.frame(val = rnorm(100, 0, 1)) cur <- data.frame(val = rnorm(100, 2, 1)) res2 <- feature_stability(ref, current = cur) res2$verdict
Visualises the results of a Prism Analysis using one of several diagnostic plots.
## S3 method for class 'PrismReport' plot( x, y = NULL, type = c("radial", "circular", "bubble", "radar"), feature = NULL, ... )## S3 method for class 'PrismReport' plot( x, y = NULL, type = c("radial", "circular", "bubble", "radar"), feature = NULL, ... )
x |
A |
y |
Ignored; included for compatibility with generic plot. |
type |
Character string specifying the plot to
display. One of |
feature |
Character string specifying the variable to
display when |
... |
Additional graphical arguments reserved for future extensions. |
Available visualisations include:
radial: Radial/gauge chart summarising the overall health of each PrismR module and dataset readiness.
circular: Feature Diagnostic Rose (coxcomb) displaying feature Completeness (petal length), Redundancy & Leakage Status (petal color), and Recommended Transformation (outer rim cap) around an open donut center.
bubble: Statistical feature map displaying Data Completeness (100% - Missing%) versus Distribution Skewness, with leakage vector colors and transformation shapes.
radar: Spider/radar chart displaying the raw statistical diagnostic profile of a selected variable (Completeness, Symmetry, Tail Normalcy, Uniqueness, Leakage Safety, and Feature Stability).
A ggplot object.
report <- prism(airquality, target = "Ozone") plot(report, type = "radial") plot(report, type = "circular") plot(report, type = "bubble") plot(report, type = "radar", feature = "Solar.R")report <- prism(airquality, target = "Ozone") plot(report, type = "radial") plot(report, type = "circular") plot(report, type = "bubble") plot(report, type = "radar", feature = "Solar.R")
Print a PrismReport
## S3 method for class 'PrismReport' print(x, ...)## S3 method for class 'PrismReport' print(x, ...)
x |
A |
... |
Additional arguments passed to print methods. |
Invisibly returns the input PrismReport object.
report <- prism(airquality, target = "Ozone") print(report)report <- prism(airquality, target = "Ozone") print(report)
Evaluates dataset readiness for predictive modeling across four foundational statistical pillars: data quality, data leakage, distribution transformations, and feature stability. Produces an overall Model Readiness score (0-100) and a gatekeeping verdict.
prism(data, target = NULL, current = NULL)prism(data, target = NULL, current = NULL)
data |
A data.frame to assess. |
target |
Optional character string specifying the name of the target/label variable. |
current |
Optional current data.frame to evaluate distribution drift against baseline |
The four evaluation dimensions include:
Data Quality: Evaluates missingness, duplicate rows, and constant features.
Data Leakage: Identifies identifier keys, duplicate features, high-cardinality columns, and target correlation leakers.
Transformations: Evaluates skewness and excess kurtosis to recommend variance-stabilizing transforms (Box-Cox, Yeo-Johnson, Log).
Feature Stability: Assesses covariate distribution drift via Population Stability Index (PSI) and Wasserstein distance.
A PrismReport S3 object containing:
List of data quality metrics returned by quality_score.
List of data leakage diagnostics returned by detect_leakage.
List of transformation recommendations returned by recommend_transform.
List of stability metrics returned by feature_stability.
Overall composite Model Readiness score (0-100).
Gatekeeping verdict: "Model Ready", "Proceed with Caution", or "Action Required".
report <- prism(airquality, target = "Ozone") print(report) summary(report)report <- prism(airquality, target = "Ozone") print(report) summary(report)
Computes basic data quality metrics for a dataset, including missing values, duplicate rows, constant columns, and an overall quality score.
quality_score(data)quality_score(data)
data |
A data.frame to assess. |
A named list containing:
Percentage of missing values.
Number of duplicated rows.
Names of constant columns.
Number of constant columns.
Overall quality score (0-100).
A data frame containing variable-level quality metrics, including missing percentage, constant feature indicator, and quality score.
res <- quality_score(airquality) res$quality_score res$missing_percentres <- quality_score(airquality) res$quality_score res$missing_percent
Analyses numeric variables in a data frame and recommends suitable transformations based on skewness and excess kurtosis. The function does not modify the data; it only provides transformation recommendations to assist with preprocessing before statistical modelling or machine learning.
recommend_transform(data)recommend_transform(data)
data |
A data.frame containing predictor variables. |
Recommendations are based on:
Distribution skewness.
Excess kurtosis (tail heaviness).
Whether the variable contains non-positive values.
Possible recommendations include:
None
Log
Box-Cox
Yeo-Johnson
A list containing:
A data frame of features requiring transformation (excluding "None").
Number of numeric variables analysed.
Number of variables for which a transformation was recommended.
A complete data frame of all analysed numeric features and their metrics.
recommend_transform(iris)recommend_transform(iris)
Summarize a PrismReport
## S3 method for class 'PrismReport' summary(object, ...)## S3 method for class 'PrismReport' summary(object, ...)
object |
A |
... |
Additional arguments passed to summary methods. |
Invisibly returns the input PrismReport object.
report <- prism(airquality, target = "Ozone") summary(report)report <- prism(airquality, target = "Ozone") summary(report)