Re: [R] Gini coefficient in R

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Mon, 11 Jun 2007 16:38:49 +0200

gini <- function(x, unbiased = TRUE, na.rm = FALSE){

if (!is.numeric(x)){

```        warning("'x' is not numeric; returning NA")
return(NA)
```

}
if (!na.rm && any(na.ind <- is.na(x)))

stop("'x' contain NAs")
if (na.rm)

x <- x[!na.ind]
n <- length(x)
mu <- mean(x)
N <- if (unbiased) n * (n - 1) else n * n     ox <- x[order(x)]
dsum <- drop(crossprod(2 * 1:n - n - 1, ox))     dsum / (mu * N)
}

```########################

```

gini(c(100,0,0,0))

I hope it helps.

Best,
Dimitris

Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

```Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm

```
• Original Message ----- From: "MICHELE DE MEO" <micheledemeo_at_gmail.com> To: <r-help_at_stat.math.ethz.ch> Sent: Monday, June 11, 2007 4:13 PM Subject: [R] Gini coefficient in R

> If I use the Ineq library and the Gini function in this way:
>
>>Gini(c(100,0,0,0))
>
> I obtain the result 0.75 instead of 1 (that is the perfect
> inequality).
>
> I think Gini's formula in Ineq is based on a formula as reported
> here:
> http://mathworld.wolfram.com/GiniCoefficient.html
>
> but in the case of perfect inequality:
>
> x_1=.......=x_n-1 =0
>
> x_n>0
>
> these formula are equal to 1 - 1/n, not to 1.
>
> ....I don't know where I'm wrong....
>
>
> --
> Michele De Meo
> http://micheledemeo.blogspot.com/
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help