[R] Gini coefficient in R

2007-06-11 Thread MICHELE DE MEO
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_n0

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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Gini coefficient in R

2007-06-11 Thread Dimitris Rizopoulos
try this version instead:

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

Address: Kapucijnenvoer 35, Leuven, Belgium
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 [EMAIL PROTECTED]
To: r-help@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_n0

 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@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.