Function Gini or Ineq

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Function Gini or Ineq

Mestat
Hi listers,
Does it necessary to install any package in order to use the GINI or INEQ functions.
If I use the following command the R tells me that didn't find the GINI function.

x<-c(541, 1463, 2445, 3438, 4437, 5401, 6392, 8304, 11904, 22261)
G<-gini(x)

Thanks in advance,
Marcio
Reply | Threaded
Open this post in threaded view
|

Re: Function Gini or Ineq

D. Rizopoulos
for the Gini coefficient you can use this function:

gini <- function(x, unbiased = TRUE, na.rm = FALSE){
     if (!is.numeric(x)) {
         warning("'x' is not numeric; returning NA")
         return(as.numeric(NA))
     }
     if (any(na.ind <- is.na(x))) {
         if (!na.rm)
             stop("'x' contain NAs")
         else
             x <- x[!na.ind]
     }
     n <- length(x)
     mu <- mean(x)
     N <- if (unbiased) n*(n - 1) else n*n
     ox <- x[order(x)]
     dd <- drop(crossprod(2 * 1:n - n - 1,  ox))
     dd / (mu * N)
}

x <- c(541, 1463, 2445, 3438, 4437, 5401, 6392, 8304, 11904, 22261)
G <- gini(x)


I hope it helps.

Best,
Dimitris


On 9/3/2010 5:37 PM, Mestat wrote:

>
> Hi listers,
> Does it necessary to install any package in order to use the GINI or INEQ
> functions.
> If I use the following command the R tells me that didn't find the GINI
> function.
>
> x<-c(541, 1463, 2445, 3438, 4437, 5401, 6392, 8304, 11904, 22261)
> G<-gini(x)
>
> Thanks in advance,
> Marcio

--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Function Gini or Ineq

Mestat
Hi Dimitris,
I have already seen your code in another post. But, I would like to weight my data. So, I wish I could use the following command:

gini(x,  weights=rep(1,length=length(x)))

Thanks anyway and I am trying to understand your gini function in order to apply a weigth.
Marcio
Reply | Threaded
Open this post in threaded view
|

Re: Function Gini or Ineq

Peng, C
you need install and load package {reldist} before you call function gini(). HTH.
Reply | Threaded
Open this post in threaded view
|

Re: Function Gini or Ineq

Mestat
Hi Peng,
I did that i installed the package RELDIST, but nothing happened. R does not recognize this function.
Still looking for the solution.
Thanks,
Marcio
Reply | Threaded
Open this post in threaded view
|

Re: Function Gini or Ineq

John Kane-2
You installed the package but probably forgot to load the library.

This works fine for me.
=================================================================
library(reldist)
x<-c(541, 1463, 2445, 3438, 4437, 5401, 6392, 8304, 11904, 22261)
G<-gini(x)
================================================================
--- On Fri, 9/3/10, Mestat <[hidden email]> wrote:

> From: Mestat <[hidden email]>
> Subject: Re: [R] Function Gini or Ineq
> To: [hidden email]
> Received: Friday, September 3, 2010, 1:07 PM
>
> Hi Peng,
> I did that i installed the package RELDIST, but nothing
> happened. R does not
> recognize this function.
> Still looking for the solution.
> Thanks,
> Marcio
> --
> View this message in context: http://r.789695.n4.nabble.com/Function-Gini-or-Ineq-tp2525852p2525981.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email]
> 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Function Gini or Ineq

Karen Kotschy
In reply to this post by Mestat
Hi Marcio

You might like to look at some equivalents from the field of ecology, for
which there are existing functions. Have a look at the function
"diversity" in the package "vegan". This provides the Simpson diversity
index, which is the complement of the Gini coefficient (Gini = 1 -
Simpson). See attached paper by Stirling (2007).

I'm not sure what you want to do with your weightings, but you could have
a look at Rao's quadratic entropy index: this is a weighted diversity
index (in ecology usually weighted by the abundance of the species, which
are the objects for which diversity is measured). You can get this from
the function "divc" in the package "ade4". There are also some other
weighted diversity indices in the package "FD" (functional diversity).

HTH
Karen


On Fri 03Sep10, Mestat wrote:

>
> Hi listers,
> Does it necessary to install any package in order to use the GINI or INEQ
> functions.
> If I use the following command the R tells me that didn't find the GINI
> function.
>
> x<-c(541, 1463, 2445, 3438, 4437, 5401, 6392, 8304, 11904, 22261)
> G<-gini(x)
>
> Thanks in advance,
> Marcio
> --
> View this message in context: http://r.789695.n4.nabble.com/Function-Gini-or-Ineq-tp2525852p2525852.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Function Gini or Ineq

Karen Kotschy
In reply to this post by Mestat
Hi again

So sorry, forgot to attach the paper I mentioned!

Karen

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


______________________________________________
[hidden email] 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.

Stirling 2007 - A general framework for analysing diversity in science, technology and society.pdf (438K) Download Attachment