How to Calculate Gini Coefficient in R
In this article, we will discuss what is Gini Coefficient and How to Calculate Gini Coefficient in R Programming Language.
What is the Gini Coefficient?
The Gini coefficient is a way to measure the income distribution of a population. The value for the Gini coefficient ranges from 0 to 1 where higher values represent greater income inequality.
0 represents perfect income equality meaning everyone has the same income
1 represents perfect income inequality meaning one individual has all the income
How to Calculate Gini Coefficient in R
We can calculate the Gini coefficient using the Gini() function from the DescTools package.
Calculate Gini Coefficient Using Individual Incomes
Step 1: Package Installation
install.packages("DescTools")
library(DescTools)
Step 2: Defining vector of incomes
x <- c(50, 50, 70, 70, 70, 90, 150, 150, 150, 150)
Step 3: Calculate Gini coefficient
Gini(x, unbiased=FALSE)
#Step 1: Package Installation
install.packages("DescTools")
library(DescTools)
#Step 2: Defining vector of incomes
x <- c(50, 50, 70, 70, 70, 90, 150, 150, 150, 150)
#Step 3: Calculate Gini coefficient
Gini(x, unbiased=FALSE)
Output:
0.226
Calculate Gini Coefficient Using Frequencies
#Step 1: Package Installation
install.packages("DescTools")
library(DescTools)
#Step 2: Define vector of incomes
x <- c(10, 20, 25, 55, 70, 90, 110, 115, 130)
#Step 3: Define vector of frequencies
n <- c(6, 7, 7, 14, 22, 20, 8, 4, 1)
#Step 4: Calculate Gini coefficient
Gini(x, n, unbiased=FALSE)
Output:
0.2632289
Conclusion
In this article, we learnt about How to Calculate Gini Coefficient in R. The value for the Gini coefficient ranges from 0 to 1 where higher values represent greater income inequality.
Contact Us