Statistics
AuraScore 81/100

Non-Parametric Regulatory Disparate Impact and Parity Audit Script

Author a forensic Python script to calculate statistical parity, disparate impact ratios, and bootstrap confidence intervals for compliance audits.

Use this template when conducting statistical fairness, pay equity, or algorithmic compliance audits under regulatory frameworks. It creates an automated Python script applying non-parametric bootstrapping and permutation testing.

Template

Role: Lead Forensic Statistician and Regulatory Compliance Data Scientist.

Context

  • Protected demographic variable: {{protected_attribute}}
  • Regulated outcome metric: {{outcome_variable}}
  • Statutory equity threshold: {{benchmark_threshold}}
  • Input table structure: {{dataset_schema}}
  • Control confounding factors: {{confounding_covariates}}
  • Bootstrap sample size: {{resample_iterations}}

Task

Construct a comprehensive Python forensic audit script that calculates adverse impact ratios, performs non-parametric permutation tests, and computes bootstrap confidence intervals on {{outcome_variable}} across groups defined by {{protected_attribute}}.

Method

  1. Ingest input data conforming to {{dataset_schema}} using pandas with schema validation and type coercion.
  2. Compute empirical group summary distributions, cross-tabulations, and adverse impact ratios against {{protected_attribute}}.
  3. Evaluate the 4/5ths (80%) rule and custom {{benchmark_threshold}} statutory compliance metrics.
  4. Build a non-parametric bootstrapping engine with {{resample_iterations}} iterations to calculate 95% bias-corrected accelerated (BCa) confidence intervals.
  5. Execute two-sample permutation tests to determine exact non-parametric p-values without assuming normality.
  6. Fit a propensity-score or regression-stratified model controlling for {{confounding_covariates}}.
  7. Evaluate whether raw disparities remain statistically significant after conditioning on {{confounding_covariates}}.
  8. Generate a structured JSON audit artifact containing test statistics, odds ratios, and compliance flags.

Constraints

  • Code MUST execute deterministically using configurable random seeds across all {{resample_iterations}}.
  • The script MUST NOT rely on unstated asymptotic normality assumptions for small subgroup slices.
  • Implement strict vectorized computations in numpy/scipy to optimize resampling loops.
  • Output variables and summary keys MUST match exact regulatory terminology (e.g., adverse_impact_ratio, p_value, ci_lower, ci_upper).

Output format

Provide a production Python script containing:

  1. Input Data Contract & Validation Function (min 20 lines).
  2. Bootstrap & Permutation Testing Core Engine (min 45 lines).
  3. Covariate-Adjusted Disparity Analyzer incorporating {{confounding_covariates}} (min 30 lines).
  4. Report Dispatcher printing both formatted console tables and returning a structured dictionary.

Self-review

  • Confirm that both raw and adjusted disparity measures are calculated and logged.
  • Ensure {{resample_iterations}} is parameterized with a reasonable fallback for fast dry-runs.
  • Verify vectorization prevents memory exhaustion during heavy bootstrap matrix expansion.
AuraScore breakdown
81/100Provisional
Instruction clarity15/15 · Strong

Explicit role, a named task, and discrete steps the model can follow.

Context architecture12/12 · Strong

Background, inputs and variables the model needs before it starts.

Constraint engineering10/12 · Adequate

Hard boundaries — what the model must and must not do.

Output specification6/14 · Thin

A named, field-level shape for the response.

Reasoning structure10/10 · Strong

Ordered work items that force analysis before an answer.

Model compatibility10/10 · Strong

Length and structure that travel across frontier models.

Token efficiency5/10 · Thin

Signal density — instruction weight without padding.

Reusability7/7 · Strong

Documented variables so the scaffold adapts to new inputs.

Robustness5/5 · Strong

Quality bar, assumptions and behaviour when inputs are thin.

Observed performance1/5 · Thin

How much real usage the template has behind it.

data-analytics
data-statistics
research-productivity-operations
statistics
compliance
equity-audit