gini index
Model was written in NetLogo 6.2.0
•
Viewed 43 times
•
Downloaded 7 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
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 2 years ago by Liu Xiaoyu.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
gini index.png | preview | Preview for 'gini index' | over 2 years ago, by Liu Xiaoyu | Download |
This model does not have any ancestors.
This model does not have any descendants.