R/gini.R

Defines functions gini

Documented in gini

# x: population of each region
# y: resource of each region
gini=function(x,y){
  index=order(y/x)
  x=x[index]
  y=y[index]
  X=cumsum(x)/sum(x)
  Y=cumsum(y)/sum(y)
  G=1-sum((X-c(0,X[1:(length(X)-1)]))*(Y+c(0,Y[1:(length(Y)-1)])))
  return(G)
}

Try the Gini package in your browser

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

Gini documentation built on Sept. 13, 2021, 5:06 p.m.