liveBook · Manning

Ineq() function

As explained in Statistics Slam Dunk

The ineq() function from the ineq R package computes inequality measures such as the Gini coefficient from numeric data.

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

How Statistics Slam Dunk covers it

How deep it goes
Demonstrates vector input, missing-value handling, rounding, grouped summaries, and visualization without explaining the underlying Gini formula.
Examples
Uses team salaries, team win shares, annual summaries, and a labeled season-over-season line chart.
What it assumes
Assumes R data-wrangling familiarity while teaching package installation, importing, numeric-vector input, and missing-value handling.
What you can do after
Apply it via the ineq package to calculate and compare rounded Gini coefficients across grouped sports data.
How it connects
Connects Gini coefficient calculations with numeric vectors, missing values, dplyr grouping, salary distributions, win shares, and Lorenz curves.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.