gini index
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
(a general understanding of what the model is trying to show or explain)
HOW IT WORKS
(what rules the agents use to create the overall behavior of the model)
HOW TO USE IT
(how to use the model, including a description of each of the items in the Interface tab)
THINGS TO NOTICE
(suggested things for the user to notice while running the model)
THINGS TO TRY
(suggested things for the user to try to do (move sliders, switches, etc.) with the model)
EXTENDING THE MODEL
(suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.)
NETLOGO FEATURES
(interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features)
RELATED MODELS
(models in the NetLogo Models Library and elsewhere which are of related interest)
CREDITS AND REFERENCES
(a reference to the model's URL on the web if it has one, as well as any other necessary credits, citations, and links)
Comments and Questions
turtles-own [money save_rate] to setup clear-all reset-ticks create-turtles num_agents[ set money (total_money / num_agents) setxy random-xcor random-ycor set save_rate random-float 1 ] end to go ask turtles[ let agsets (other turtles-here) if count agsets >= 1[ transaction(one-of agsets) ] forward 1 ] tick end to transaction[trader] let deltam 0 let money0 ((1 - save_rate) * money) let money1 ((1 - save_rate) * [money] of trader) let epsilon (random-float 1) set deltam (epsilon - 1) * money0 + epsilon * money1 if money + deltam >= 0 and money1 - deltam >= 0 [ set money money + deltam ask trader[ set money money1 - deltam] ] end to to-update-plot let lst [money] of turtles set-histogram-num-bars 100 if not empty? lst[ set-plot-x-range 0 max lst histogram lst ] end to save-file file-open "agents.txt" let wealths "" ask turtles[ set wealths (word wealths money "\r\n") ] file-print wealths file-close end to update-lorenz-plot clear-plot set-current-plot-pen "equal" plotxy 0 0 plotxy 1 1 set-current-plot-pen "dominant" plot-pen-down plotxy 0 0 plotxy 1 0 plotxy 1 1 plot-pen-up set-current-plot-pen "lorenz" set-plot-pen-interval (1 / num_agents) plot 0 let sorted-wealths sort [money] of turtles let total-wealth sum sorted-wealths let wealth-sum-so-far 0 let index 0 let gini 0 let s 0 repeat num_agents[ set wealth-sum-so-far (wealth-sum-so-far + item index sorted-wealths) plot (wealth-sum-so-far / total-wealth) set index index + 1 set s ((index / num_agents) - (wealth-sum-so-far / total-wealth)) / num_agents set gini gini + s ] set-current-plot "gini" plot gini * 2 end to-report compute-gini let sorted-wealths sort [money] of turtles let total-wealth sum sorted-wealths let wealth-sum-so-far 0 let index 0 let gini 0 let s 0 repeat num_agents[ set wealth-sum-so-far (wealth-sum-so-far + item index sorted-wealths) plot (wealth-sum-so-far / total-wealth) set index index + 1 set s ((index / num_agents) - (wealth-sum-so-far / total-wealth)) / num_agents set gini gini + s ] set-current-plot "gini" report gini * 2 end
There is only one version of this model, created over 3 years ago by Liu Xiaoyu.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
gini index.png | preview | Preview for 'gini index' | over 3 years ago, by Liu Xiaoyu | Download |
This model does not have any ancestors.
This model does not have any descendants.