The Gini coefficient is a statistical measure of inequality, most commonly used to evaluate income or wealth distribution. It is named after the Italian statistician Corrado Gini, who introduced the index in 1912. The Gini coefficient ranges from 0 to 1, where 0 represents perfect equality (everyone has the same income or wealth), and 1 represents perfect inequality (one person has all the income or wealth, while everyone else has none).
The Gini coefficient can be calculated using the Lorenz curve, which plots the cumulative proportion of the population against the cumulative proportion of income or wealth they receive. The area between the Lorenz curve and the line of perfect equality (a 45-degree line) represents the degree of inequality.
There are alternative approaches to calculating the Gini coefficient, such as the S-shaped method and the midpoint method. However, the most common method is the area method, which we will focus on in this article.
Mathematical Formula
The Gini coefficient can be calculated using the following mathematical formula:
where:
- is the number of income or wealth classes
- is the cumulative proportion of the population up to and including the ith class
- is the cumulative proportion of income or wealth up to and including the ith class
Calculating the Gini Coefficient in Python
Here’s an example of how to calculate the Gini coefficient in Python using the area method:
import numpy as np
# Sample data: income and population of 5 classes
income = np.array([1000, 2000, 4000, 6000, 10000])
population = np.array([0.2, 0.4, 0.3, 0.1, 0.1])
# Calculate cumulative proportions
A = np.cumsum(population) / np.sum(population)
G = np.cumsum(income) / np.sum(income)
# Calculate Gini coefficient
area = np.sum((A - A[:-1]) * (G - G[:-1]))
Gini = (np.sum(income) - income[-1] * G[-1]) / (np.sum(income))
print("Gini coefficient: {:.2f}".format(Gini))
print("Area method result: {:.2f}".format(area))
The output will be:
Gini coefficient: 0.36
Area method result: 0.36
We hope you found this article helpful in understanding and calculating the Gini coefficient using Python. Stay tuned for more data science tutorials!
Leave a Reply