Homophily Choice
Model was written in NetLogo 6.1.1
•
Viewed 291 times
•
Downloaded 47 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
globals [ guest-count host-count choice gini-index-reserve lorenz-points ] ;extensions [ import-a ] ;extensions [ rnd ] breed [hosts host] breed [guests guest] breed [trees tree] hosts-own [ h-race ;w-b-a-ratio w-ratio b-ratio a-ratio w-cnt b-cnt a-cnt attract num-guest ] guests-own [ g-race cate ] to setup clear-all ask patches [set pcolor green - random-float 0.5] ;ask patches [set pcolor 56 ] ;import-drawing "map.jpg" set-default-shape guests "person" set-default-shape hosts "house" set host-count (white-hosts + black-hosts + asian-hosts) set guest-count (white-hosts + black-hosts + asian-hosts) ;;add number of hosts according to the input create-hosts white-hosts [ set size 2 set h-race "White" set color 105 ;; white = 105 set xcor -20 + random 40 set ycor -20 + random 50 ] create-hosts black-hosts [ set size 2 set h-race "Black" set color 3 ;; grey = 3 set xcor -20 + random 40 set ycor -20 + random 50 ] create-hosts asian-hosts [ set size 2 set h-race "Asian" set color 25 ;; yellow = 45 set xcor -20 + random 40 set ycor -20 + random 50 ] ;;set hosts apart for visual purpose ask hosts [move-to one-of patches with [not any? other hosts in-radius 2]] update-lorenz-and-gini reset-ticks end to go ;; update the ratio for all hosts based on the guest race ask hosts [ if count link-neighbors > 0 [ ;set w-b-a-ratio (list ((count (link-neighbors with [g-race = "White"])) / count link-neighbors) ;((count (link-neighbors with [g-race = "Black"])) / count link-neighbors) ;((count (link-neighbors with [g-race = "Asian"])) / count link-neighbors) ) set w-ratio count (link-neighbors with [g-race = "White"])/ count link-neighbors set b-ratio count (link-neighbors with [g-race = "Black"])/ count link-neighbors set a-ratio count (link-neighbors with [g-race = "Asian"])/ count link-neighbors set w-cnt count (link-neighbors with [g-race = "White"]) set b-cnt count (link-neighbors with [g-race = "Black"]) set a-cnt count (link-neighbors with [g-race = "Asian"]) ] set num-guest count (link-neighbors) ] ask links [ set color gray ] set guest-count (guest-count + 1) create-guest make-decision find-partner ;;decide the race of a guest by probability update-lorenz-and-gini tick end ;; used for creating a new guest to create-guest create-guests 1 [ ;set new? true let a-g-prob 1 - w-g-prob - b-g-prob let probs ( list (w-g-prob) (b-g-prob) (a-g-prob) ) ;let race-col [ "White" "Black" "Asian" ] ;set g-race first rnd:weighted-one-of-list (map list race-col probs) last set g-race (random-pick-guest-race probs) if g-race = "White" [set color 105 set cate 1] if g-race = "Black" [set color 3 set cate 2] if g-race = "Asian" [set color 25 set cate 3] ] end to make-decision [listing] ask (max-one-of guests [who]) [ if listing != nobody [ create-link-with listing [ set color grey ] ;; position the new node near its partner move-to listing fd 3 + (random 6) ] ] end to-report find-partner ;; update the attractiveness of hosts based on the guest race --> attractiveness is a list of probabilities let w-a-1 1 - w-w-1 - w-b-1 let b-a-1 1 - b-w-1 - b-b-1 let a-w-1 1 - a-a-1 - a-b-1 let w-a-2 1 - w-w-2 - w-b-2 let b-a-2 1 - b-w-2 - b-b-2 let a-w-2 1 - a-a-2 - a-b-2 ;let w-pref reduce sentence (map [[a] -> [w-ratio] of hosts with [who = a]] (range 0 (host-count))) ;let b-pref reduce sentence (map [[a] -> [b-ratio] of hosts with [who = a]] (range 0 (host-count))) ;let a-pref reduce sentence (map [[a] -> [a-ratio] of hosts with [who = a]] (range 0 (host-count))) let w-pref reduce sentence (map [[a] -> [w-cnt] of hosts with [who = a]] (range 0 (host-count))) let b-pref reduce sentence (map [[a] -> [b-cnt] of hosts with [who = a]] (range 0 (host-count))) let a-pref reduce sentence (map [[a] -> [a-cnt] of hosts with [who = a]] (range 0 (host-count))) let temp-race ([g-race] of (max-one-of guests [who])) let base-ratio (map [[a b c] -> a + b + c ] w-pref b-pref a-pref) if temp-race = "White" [ ;show temp-race ;;show base-ratio ;; guest-host preference: guest-host pref let gh-pref (sentence (n-values white-hosts [w-w-1]) (n-values black-hosts [w-b-1]) (n-values asian-hosts [w-a-1])) set gh-pref (map [[a] -> a * 1] gh-pref ) ;;guest-reviewer pref let gr-pref (sentence (n-values white-hosts [w-w-2]) (n-values black-hosts [w-b-2]) (n-values asian-hosts [w-a-2])) ;;show gh-pref ;; add up base-ratio, gh-pref and gr-pref let gr-pref2 (map [[a b] -> a * b] base-ratio gr-pref) let att (map [[a b] -> a + b ] gh-pref gr-pref) ;let att (map [[a b c] -> a + b + c ] base-ratio gh-pref gr-pref) ;let host-order (range 0 host-count) set choice (random-pick-host att) ;set choice first rnd:weighted-one-of-list (map list host-order att) last ;show choice ;show att report host choice ] if temp-race = "Black" [ ;show temp-race ;;show base-ratio ;; first preference: guest-host pref ;;let gh-pref (list a-w-pref a-w-pref a-w-pref a-b-pref a-b-pref a-b-pref a-a-pref a-a-pref a-a-pref) let gh-pref (sentence (n-values white-hosts [b-w-1]) (n-values black-hosts [b-b-1]) (n-values asian-hosts [b-a-1])) set gh-pref (map [[a] -> a * 1] gh-pref ) ;;show gh-pref ;; secondary preference: guest-reviewer pref let gr-pref (sentence (n-values white-hosts [b-w-2]) (n-values black-hosts [b-b-2]) (n-values asian-hosts [b-a-2])) ;let gr-pref (list a-w a-w a-w a-b a-b a-b a-a a-a a-a) ;; add up base-ratio, gh-pref and gr-pref let gr-pref2 (map [[a b] -> a * b] base-ratio gr-pref) let att (map [[a b] -> a + b ] gh-pref gr-pref) ;let att (map [[a b c] -> a + b + c ] base-ratio gh-pref gr-pref) ;let host-order (range 0 host-count) set choice (random-pick-host att) ;set choice first rnd:weighted-one-of-list (map list host-order att) last ;show choice ;show att report host choice ] if temp-race = "Asian" [ ;show temp-race ;;show base-ratio ;; first preference: guest-host pref ;;let gh-pref (list a-w-pref a-w-pref a-w-pref a-b-pref a-b-pref a-b-pref a-a-pref a-a-pref a-a-pref) let gh-pref (sentence (n-values white-hosts [a-w-1]) (n-values black-hosts [a-b-1]) (n-values asian-hosts [a-a-1])) set gh-pref (map [[a] -> a * 1] gh-pref ) ;;show gh-pref ;; secondary preference: guest-reviewer pref let gr-pref (sentence (n-values white-hosts [a-w-2]) (n-values black-hosts [a-b-2]) (n-values asian-hosts [a-a-2])) ;;let gr-pref (list a-w a-w a-w a-b a-b a-b a-a a-a a-a) ;; add up base-ratio, gh-pref and gr-pref let gr-pref2 (map [[a b] -> a * b] base-ratio gr-pref) let att (map [[a b] -> a + b ] gh-pref gr-pref) ;let att (map [[a b c] -> a + b + c ] base-ratio gh-pref gr-pref) ;let host-order (range 0 host-count) set choice (random-pick-host att) ;set choice first rnd:weighted-one-of-list (map list host-order att) last ;show choice ;show att report host choice ] end to-report random-pick-guest-race [tmp] let var (1 / sum tmp) let _ps map [[a] -> a * var] tmp ;[0.1 0.2 0.1 0.4 0.1 0.01] let _r random-float 1 let _lst [ "White" "Black" "Asian" ] let _i 0 while [_r >= item _i _ps] [ set _r (_r - item _i _ps) set _i (_i + 1) ] report item _i _lst end to-report random-pick-host [tmp] let var (1 / sum tmp) let _ps map [[a] -> a * var] tmp ;[0.1 0.2 0.1 0.4 0.1 0.01] let _r random-float 1 let _lst (range 0 host-count) let _i 0 while [_r >= item _i _ps] [ set _r (_r - item _i _ps) set _i (_i + 1) ] report item _i _lst end ;;;;;;Gini coefficient to update-lorenz-and-gini let sorted-wealths sort [num-guest] of hosts let total-wealth sum sorted-wealths let wealth-sum-so-far 0 let index 0 set gini-index-reserve 0 set lorenz-points [] ;; now actually plot the Lorenz curve -- along the way, we also ;; calculate the Gini index. ;; (see the Info tab for a description of the curve and measure) if total-wealth > 0 [ repeat host-count [ set wealth-sum-so-far (wealth-sum-so-far + item index sorted-wealths) set lorenz-points lput ((wealth-sum-so-far / total-wealth) * 100) lorenz-points set index (index + 1) set gini-index-reserve gini-index-reserve + (index / host-count) - (wealth-sum-so-far / total-wealth) ] ] end
There are 29 versions of this model.
This model does not have any ancestors.
This model does not have any descendants.