inequality: Inequality Indices

inequalityR Documentation

Inequality Indices

Description

Computes inequality indices: gini calculates the Gini coefficient for individual sample data. gini2 calculates the Gini coefficient for grouped data using income and population shares. theil0 calculates the Theil index for individual sample data. theil calculates the Theil index for grouped average data. theil0_g calculates the Theil index and decomposition for grouped sample data. theil_g calculates the Theil index and decomposition for grouped average data. theil_g2 calculates the Theil index and decomposition for two-level grouped average data.

Usage

gini(x)

gini2(income, pop)

theil0(y)

theil(y, p)

theil0_g(data, group, y)

theil_g(data, group, y, p)

theil_g2(data, group1, group2, y, pop)

Arguments

x

For gini: Numeric vector of non-negative values (e.g., income).

income

For gini2: Numeric vector of group incomes or income shares.

pop

For gini2: Numeric vector of group populations or population shares. For theil, theil_g: Name of population variable (character). For theil_g2: Name of population variable (character, aliased as pop).

y

For theil0: Numeric vector of individual incomes. For theil, theil0_g, theil_g, theil_g2: Name of income variable (character).

data

For theil0_g, theil_g, theil_g2: Data frame containing variables.

group

For theil0_g, theil_g: Name of grouping variable (e.g., province).

group1

For theil_g2: Name of first grouping variable (e.g., region).

group2

For theil_g2: Name of second grouping variable (e.g., type).

Value

For gini, gini2: Numeric Gini coefficient (0 to 1). For theil0, theil: Numeric Theil index. For theil0_g, theil_g: List with total Theil index (theil), between-group (Tb), within-group (Tw), within-group components (Twi), and contribution rates (Rb, Rw, Rwi). For theil_g2: List with total Theil index and decomposition (Theil) and within-group components (Within).

Examples

# Sample data
income = c(10, 20, 30, 40, 100)
pop = c(100, 150, 200, 250, 300)

# Gini coefficient (individual data)
gini(income)

# Gini coefficient (grouped data)
gini2(income, pop)

data = data.frame(g = c("A","A",rep("B",10),rep("A",6)),
                  y = c(10,10,rep(8,4),rep(6,6),rep(4,4),2,2))

data2 = data |>
  dplyr::count(g, y, name = "p")

# Theil index (individual sample)
theil0(data$y)

# Theil index (grouped average)
theil(data2$y, data2$p)

# Theil index with grouping (sample data)
theil0_g(data, "g", "y")

# Theil index with grouping (average data)
theil_g(data2, "g", "y", "p")

# Theil index with two-level grouping
data3 = data.frame(
  region = c("Eastern", "Eastern", "Central", "Central", "Western", "Western", "Northeast", "Northeast"),
  type = c("Urban", "Rural", "Urban", "Rural", "Urban", "Rural", "Urban", "Rural"),
  pop = c(24491, 21854, 12850, 22321, 12423, 23522, 5930, 4823),
  per_income = c(13375, 4720, 8809, 2957, 8783, 2379, 8730, 3379)
)
theil_g2(data3, "region", "type", "per_income", "pop")
theil_g2(data3, "type", "region", "per_income", "pop")


zhjx19/mathmodels documentation built on June 2, 2025, 12:18 a.m.