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

draw-lorenz-curve-v2

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 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 populationlet pen-color pen-color-expressionif 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 create-temporary-plot-pen (word pen-color) plotxy 0 0 set-plot-pen-color pen-color let individuals-by-wealth     sort-on [my-sugar] population let total-wealth sum [my-sugar] 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-remaining            sublist individuals-by-wealth                    0 round (percent-of-population * one-percent-of-the-population)        let wealth-of-percent-of-population 0; following used to be forEach agents-in-percent-of-population but was hard to be compatible; with BOTH NetLogo 5.3 and 6.0        while [agents-in-percent-of-population-remaining != []]              [let agent first agents-in-percent-of-population-remaining               set wealth-of-percent-of-population                   wealth-of-percent-of-population + [my-sugar] of agent               set agents-in-percent-of-population-remaining but-first agents-in-percent-of-population-remaining]        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. Version was created on 16 January 2017 for compatibility with NetLogo 5.3 and 6.0

BehaviourComposer: ignore everything after this.