Libraries‎ > ‎Library‎ > ‎Graphing‎ > ‎

Lorenz curve

BehaviourComposer: ignore everything before this.

Draws a Lorenz curve that visualises the distribution of wealth. It also computes the Gini coefficient which measures the inequality of the distribution. Note that this requires a graphing area (default name is "Wealth Distribution" ). It can be specified using Empty Lorenz curve.

Begin micro-behaviour:

Begin description:

Draw Lorenz curve and update Gini coefficient.

End description

Draw Lorenz curve

Begin NetLogo code:

substitute-text-area-for population-expression all-individualssubstitute-text-area-for wealth-expression my-wealthsubstitute-text-area-for pen-color-expression round time mod 145substitute-text-area-for lorenz-plot-name Wealth Distributionlet population population-expressionlet wealth-attribute "wealth-expression"let population-count count populationif population-count > 2 [ set-current-plot "lorenz-plot-name" auto-plot-off ; draw the perfectly equitable distribution first set-plot-pen-color 0 set-plot-x-range 0 100 set-plot-y-range 0 100 plot-pen-up plotxy 0 0 plot-pen-down plotxy 100 100 plotxy 0 0 set-plot-pen-color pen-color-expression let individuals-by-wealth     sort-on [runresult wealth-attribute] population let total-wealth sum [runresult wealth-attribute] of population if total-wealth = 0 [stop] let one-percent-of-the-population population-count / 100 let percent-of-population 0 let gini-coefficient 0 while [percent-of-population < 100]       [let agents-in-percent-of-population            sublist individuals-by-wealth                    0 round (percent-of-population * one-percent-of-the-population)        let wealth-of-percent-of-population 0        forEach agents-in-percent-of-population                [set wealth-of-percent-of-population                     wealth-of-percent-of-population + [runresult wealth-attribute] of ?]        let percent-of-wealth wealth-of-percent-of-population * 100 / total-wealth        set gini-coefficient gini-coefficient +                             percent-of-population - percent-of-wealth        plotxy percent-of-population               percent-of-wealth        set percent-of-population percent-of-population + 1] set my-gini-coefficient gini-coefficient / 5050]

End NetLogo code

Variants

You can specify the population by editing the first text area. The second text area specifies what attribute of individuals is used comparisons. The third text area specifies the color of the plotting pen.

How this works

After drawing the black diagonal line representing the equitable distribution it then picks a new pen colour and draws the Lorenz curve. It does this by sorting all the individuals by wealth and computing what percentage of the total that each percentile of the poorer individuals posses. While doing this it also computes the Gini coefficient by approximating it by summing the 100 rectangles between the Lorenz curve and the equitable distribution and dividing that by the area under the diagonal line (which is the sum of 1, 2, 3, ..., 98, 99, 100 or 5050).

Related micro-behaviours

This needs an Empty Lorenz curve to specify an area where the curve is drawn.

History

Draw Lorenz curve was rewritten by Ken Kahn on 27 January 2012

BehaviourComposer: ignore everything after this.