ff_dist_gini_random_var: Compute gini coefficient between 0 (equality) and 1 based on...

Description Usage Arguments Value Author(s) References Examples

View source: R/ff_dist_gini.R

Description

Suppose there are N outcomes from x1, to xn, each with P(x_i) of happening. What is the gini index/coefficient that summarizes the level of inequality of the population that is described by this discrete random variable?

Usage

1
ff_dist_gini_random_var(ar_x, ar_prob_of_x, bl_sort_sum = TRUE)

Arguments

ar_x

array of sclaar values x1, x2, ..., xn-1, xn, sorted.

ar_prob_of_x

array of probability mass that sums to one for sequentially each element of ar_x.

bl_sort_sum

boolean if true then finds the unique values of ar_x, sort it, and sum up the probabilities contained in ar_prob_of_x for each one of the unique values in ar_x

Value

a scalar value of the gini coefficient

Author(s)

Fan Wang, http://fanwangecon.github.io

References

https://fanwangecon.github.io/REconTools/articles/fv_dist_gini_vector_pos.html https://fanwangecon.github.io/R4Econ/math/func_ineq/htmlpdfr/fs_gini_disc.html

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# already sorted example
for (fl_binom_success_prob in seq(0.0001,0.9999,length.out=10)) {
    ar_x <- seq(0, 100, by=1)
    ar_prob_of_x <- dbinom(ar_x, 100, fl_binom_success_prob)
    fl_gini_index <- ff_dist_gini_random_var(ar_x, ar_prob_of_x, bl_sort_sum=FALSE)
    st_print <- paste0('binom p(success)=', fl_binom_success_prob ,
                       ', the fl_gini_index=', fl_gini_index)
    print(st_print)
}
# Example 2a, unsorted
set.seed(123)
ar_x <- c(1,2,3,5,2,1,3)
ar_prob_of_x <- runif(length(ar_x))
ar_prob_of_x <- ar_prob_of_x/sum(ar_prob_of_x)
ff_dist_gini_random_var(ar_x, ar_prob_of_x, bl_sort_sum=TRUE)
# Example 2b, sorted same
ar_x_sort <- c(1,2,3,5)
ar_prob_of_x_sort <- c(0,0,0,0)
ar_prob_of_x_sort[1] <- ar_prob_of_x[1] + ar_prob_of_x[6]
ar_prob_of_x_sort[2] <- ar_prob_of_x[2] + ar_prob_of_x[5]
ar_prob_of_x_sort[3] <- ar_prob_of_x[3] + ar_prob_of_x[7]
ar_prob_of_x_sort[4] <- ar_prob_of_x[4]
ff_dist_gini_random_var(ar_x_sort, ar_prob_of_x_sort, bl_sort_sum=FALSE)
ff_dist_gini_random_var(ar_x_sort, ar_prob_of_x_sort, bl_sort_sum=TRUE)

FanWangEcon/REconTools documentation built on Jan. 21, 2022, 10:28 p.m.