rformulainequalitygini

What formula does Gini() from ineq package use to get the Gini coefficient in R?


I'm writing a paper and I want to declare how I obtained some Gini coefficients using the Gini() function from the ineq package, but when looking for what formula Gini() from ineq uses, I do not find any reliable source for what formula it employs.

Does anyone know? I've read that it uses Brown's formula, but I've also found that it uses the difference between Lorenz Curves (the one with 45° and the "real" distribution). And in the ineq page, it only says that "Gini() is the Gini coefficient".

I'm not sure which formula to write in my paper and any help is welcome. :)

Thanks!


Solution

  • You can type the name of a function to see it's code. Or look at the package source. In this case we see:

    Gini <- function(x, corr = FALSE, na.rm = TRUE)
    {
        if(!na.rm && any(is.na(x))) return(NA_real_)
        x <- as.numeric(na.omit(x))
        n <- length(x)
        x <- sort(x)
        G <- sum(x * 1L:n)
        G <- 2 * G/sum(x) - (n + 1L)
        if (corr) G/(n - 1L) else G/n
    }
    

    This matches the Wikipedia page's 2nd formula under Alternative Expressions.

    screenshot of formula for "simplified version" of Gini coefficient from wikipedia