Skip to content

Add Gini coefficient, Kurtosis, Percentile rank, and Atkinson index to unsorted module#16

Closed
jqnatividad with Copilot wants to merge 1 commit into
addl-unsorted-gini_kurtosis_percentil-on-rank_atkinson_indexfrom
copilot/sub-pr-15
Closed

Add Gini coefficient, Kurtosis, Percentile rank, and Atkinson index to unsorted module#16
jqnatividad with Copilot wants to merge 1 commit into
addl-unsorted-gini_kurtosis_percentil-on-rank_atkinson_indexfrom
copilot/sub-pr-15

Conversation

Copilot AI commented Dec 20, 2025

Copy link
Copy Markdown
Contributor

Adds four inequality and distribution shape statistics to the unsorted module, completing the statistical analysis toolkit for streaming data.

New Functions

  • gini() - Gini coefficient for measuring inequality (0 = perfect equality, 1 = perfect inequality)
  • kurtosis() - Excess kurtosis for measuring distribution tailedness (0 = normal, positive = heavy tails, negative = light tails)
  • percentile_rank() - Percentile rank of a value within a distribution (0-100 scale)
  • atkinson() - Atkinson index with configurable inequality aversion parameter ε

Implementation Details

  • All functions use O(n log n) sorting with O(n) space complexity
  • Adaptive parallel processing: sequential for <10k elements, parallel for ≥10k
  • Proper edge case handling: empty data, single elements, zero variance, zero sums
  • Binary search optimization in percentile_rank() for efficient lookups
  • Special-case geometric mean computation in atkinson() when ε=1

Usage

use stats::unsorted::{gini, kurtosis, percentile_rank, atkinson};

// Measure income inequality
let incomes = vec![20_000, 30_000, 45_000, 80_000, 200_000];
let inequality = gini(incomes.iter().copied()).unwrap();  // ~0.34

// Check distribution shape
let returns = vec![-2.1, -0.5, 0.3, 0.8, 1.2, 5.7];
let tail_heaviness = kurtosis(returns.iter().copied()).unwrap();

// Find relative position
let score_rank = percentile_rank(scores.iter().copied(), 85).unwrap();

// Inequality with aversion to low-end gaps (ε=1.5)
let adjusted_inequality = atkinson(incomes.iter().copied(), 1.5).unwrap();

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add unsorted module stats: Gini coefficient, Kurtosis, Percentile rank, Atkinson index Add Gini coefficient, Kurtosis, Percentile rank, and Atkinson index to unsorted module Dec 20, 2025
Copilot AI requested a review from jqnatividad December 20, 2025 21:16
@jqnatividad

Copy link
Copy Markdown
Collaborator

Thanks for your review @copilot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants