FOI/2021/2852
You asked
Please supply any information on the ONS' current methodology for measuring the GINI coefficient from a Lorenz Curve.
We said
Thank you for your request.
Our current Gini calculation is a piece of rather complex derivation code within a SAS programme. With that in mind, we are currently trying to move our derivation systems over to R.
There is a function 'gini' in the package 'reldist' which can be accessed via the following link: https://cran.r-project.org/web/packages/reldist/reldist.pdf. This produces the same results as our complex SAS system, therefore we would recommend you look at this function in R if you are interested in the calculation. Please see the basic information below:
function (x, weights = rep(1, length = length(x)))
{
ox <- order(x)
x <- x[ox]
weights <- weights[ox]/sum(weights)
p <- cumsum(weights)
nu <- cumsum(weights * x)
n <- length(nu)
nu <- nu/nu[n]
sum(nu[-1] * p[-n]) - sum(nu[-n] * p[-1])
}