inequality | R Documentation |
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.
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)
x |
For |
income |
For |
pop |
For |
y |
For |
data |
For |
group |
For |
group1 |
For |
group2 |
For |
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
).
# 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.