The ineq() function from the ineq R package computes inequality measures from numeric data, including the Gini coefficient. In NBA analysis, it turns player salaries or win shares into a single inequality score for a team-season or an entire league. section 12.2 section 13.4
Use ineq() when the analytical question asks how unevenly a quantity is distributed:
- Pass a numeric vector to compute its Gini coefficient; values near 0 indicate greater equality, while values near 1 indicate greater inequality. section 12.2 section 13.4
- Set na.rm = TRUE to skip missing values; leaving missing values included can return NA when a team has fewer than the maximum 14 observations. section 12.7.1 section 13.8.1
- Combine ineq() with dplyr grouping and summarization to calculate one inequality value per team-season or one value per league season. section 12.7.1 section 13.4
Team salary inequality
After reshaping up to 14 salaries into s1 through s14, calculate and round each team-season coefficient with: gini_index = round(ineq(c(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, na.rm = TRUE)), digits = 2). The resulting gini_index can be joined to team records for comparisons with wins, winning percentage, or championships. section 12.7.1
League-wide win-share trend
Group win-share data by Year and summarize gc = round(ineq(WS), digits = 2). A line chart of gc then displays season-over-season inequality; the reported values range from 0.53 to 0.56 in the first ten seasons shown. section 13.4
library(tidyverse) library(sqldf) library(ineq) library(gglorenz) library(scales) library(effsize)
Load ineq before calling ineq(); install the package first when it is not already installed. section 12.2
