gini Coefficient Functions

Prev Next

Function Names

gini, gini ignore blanks, gini ignore zero

Description

Calculates the gini coefficient (e.g. to identify the income disparity) of a set of values. This function will also return the corresponding Lorenz curve if a 2nd parameter is provided.

The suffix ... ignore zero excludes all zero values. Note: Blank values are also considered zero and are therefore ignored
The suffix ... ignore blanks excludes blank values, but includes zeros.

Call as: function

Parameter count

1-2

Parameters

No.TypeDescription
1
input
set input values

The set shall contain numerals and/or blank strings.

Opt. 2
code
variable Lorenz curve

Specify a variable name to which the set of numbers describing the Lorenz curve will be written to. The variable will be created if it does not exist yet.

Return value

TypeDescription
numeral Gini coefficient

Exceptions

1st parameter is not a set containing positive numerals and/or blank strings.

Examples

               echo( gini( { 1,1,1,1,1 } ) ); // Everyone is equal, returns 1
               echo( gini( { 1, 1.2, 1.3, 1, 1.4, 1.2 } ) ); // ca 0.93, some dispartiy
               echo( gini( { 1, 1, 1, 1, 16 }, lorenz[] ) ); // 0.4, big disparity
               echo( "Lorenz curve: ", lorenz[] );

Output

1
0.9319248826
0.4
Lorenz curve: {0,0.05,0.1,0.15,0.2,1}
Try it yourself: Open LIB_Function_gini.b4p in B4P_Examples.zip. Decompress before use.

See also

variance
deviation