BehaviourComposer: ignore everything before this.
I draw a Lorenz curve and compute the Gini coefficient.
Draw Lorenz curve
Begin NetLogo code:
do-after-setup [do-every 1 [let population count all-individuals if population <= 2 [stop] set-current-plot "Wealth Distribution" auto-plot-off create-temporary-plot-pen "Lorenz pen" set-current-plot-pen "Lorenz pen" ; 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 round time mod 145 let individuals-by-wealth sort-on [my-sugar] all-individuals let total-wealth sum [my-sugar] of all-individuals let one-percent-of-the-population population / 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 + [my-sugar] 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
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 (sugar) 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).
This expects CREATE-EMPTY-LORENZ-CURVE has been added to create the surface this draws upon.
This was implemented by Ken Kahn. Last updated on 27 June 2012.
BehaviourComposer: ignore everything after this.