R/gini.r

Defines functions gini

Documented in gini

gini <- 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])
}

Try the reldist package in your browser

Any scripts or data that you put into this service are public.

reldist documentation built on March 7, 2023, 8:34 p.m.