├── ch03_schelling ├── .gitkeep └── segregation.nlogo ├── ch04_contagion ├── .gitkeep └── Contagion_SI.nlogo ├── ch05_opinions ├── .gitkeep ├── opiniondynamics_posinfluence.nlogo └── opiniondynamics_BC.nlogo ├── ch08_science ├── .gitkeep ├── berkson_sim.R ├── science_bayesianupdating.nlogo └── science_pub-bias.nlogo ├── ch09_networks ├── .gitkeep ├── RingNetwork.nlogo └── RandomNetwork.nlogo ├── ch06_cooperation ├── .gitkeep ├── PD_simple.nlogo └── PD_randomized.nlogo ├── ch07_coordination ├── .gitkeep ├── coordination_asymmetric.nlogo └── coordination_simple.nlogo ├── README.md └── ch02_particles ├── particlesflock.nlogo └── particles.nlogo /ch03_schelling/.gitkeep: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ch04_contagion/.gitkeep: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ch05_opinions/.gitkeep: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ch08_science/.gitkeep: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ch09_networks/.gitkeep: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ch06_cooperation/.gitkeep: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ch07_coordination/.gitkeep: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # modsoc 2 | 3 | This repository contains the NetLogo code for Modeling Social Behavior: Mathematical and Computational Models of Social Dynamics and Cultural Evolution by Paul E. Smaldino. 4 | 5 | Enjoy! 6 | 7 | Feel free to cite any code used from this repo using the permanent DOI found here: https://zenodo.org/records/11245354 8 | -------------------------------------------------------------------------------- /ch08_science/berkson_sim.R: -------------------------------------------------------------------------------- 1 | # Selection bottlenecks lead to the promotion of less trustworthy science 2 | # Coded by Paul Smaldino in 2021 3 | # Modeling Social Behavior 4 | 5 | # A simple model to show selection distortion. 6 | 7 | # MODEL DESCRIPTION 8 | # 1. Generate dataset of M papers, with normally distributed trustworthiness (T) and newsworthiness (W) 9 | # 2. Show no correlation in pre-selection sample 10 | # 3. Rank papers by sum of T + W. Select top 10% for publication 11 | # 4. Show correlation in post-selection sample. 12 | 13 | #import libraries 14 | library(ggplot2) 15 | library (cowplot) 16 | library(dplyr) 17 | 18 | rm(list = ls()) 19 | M <- 500 #number of papers 20 | M_top <- round(M/10) #number of selected papers 21 | 22 | df <- data.frame("news" = rnorm(M, 0, 1), 23 | "trust" = rnorm(M, 0, 1)) 24 | 25 | #select on score 26 | df$score <- df$news + df$trust 27 | df <- df[order(df$score, decreasing = TRUE),] 28 | df$selected <- rep(0, M) 29 | df$selected[1:M_top] <- 1 30 | 31 | #dataframe of just selected values 32 | df.selected <- df[which(df$selected == 1),] 33 | cor.selected <- cor(df.selected$news, df.selected$trust) #correlation coefficient 34 | cor.all <- cor(df$news, df$trust) #correlation coefficient 35 | 36 | #plot of rejected and accepted papers 37 | ggplot() + 38 | geom_point(data=df, aes(x=news, y=trust), size = 1.45, alpha = 0.65, shape = 21, color = "black", fill = "firebrick1") + 39 | geom_point(data=df.selected, aes(x=news, y=trust), size = 1.46, alpha = 1, shape = 19, color = "seagreen4") + 40 | geom_smooth(data=df.selected, aes(x=news, y=trust), method='lm', se = FALSE, fullrange = TRUE, color = "seagreen4", size = .6) + 41 | scale_x_continuous(limits=c(-3.1, 3.1), breaks = c(-2, 0, 2)) + 42 | scale_y_continuous(limits=c(-3.1, 3.1), breaks = c(-2, 0, 2)) + 43 | labs(x = "newsworthiness", y="trustworthiness") + 44 | theme_bw() + 45 | theme(panel.grid.major = element_blank(), 46 | panel.grid.minor = element_blank(), 47 | panel.background = element_rect(colour = "black", size=1)) 48 | #3.44 x 3.52 inches 49 | 50 | #plot of all papers 51 | ggplot() + 52 | geom_point(data=df, aes(x=news, y=trust), size = 1.45, alpha = 0.65, shape = 21, color = "black", fill = "gray50") + 53 | #geom_smooth(data=df, aes(x=news, y=trust), method='lm', se = FALSE, fullrange = TRUE, color = "gray40", size = .6) + 54 | scale_x_continuous(limits=c(-3.1, 3.1), breaks = c(-2, 0, 2)) + 55 | scale_y_continuous(limits=c(-3.1, 3.1), breaks = c(-2, 0, 2)) + 56 | labs(x = "newsworthiness", y="trustworthiness") + 57 | theme_bw() + 58 | theme(panel.grid.major = element_blank(), 59 | panel.grid.minor = element_blank(), 60 | panel.background = element_rect(colour = "black", size=1)) 61 | #3.44 x 3.52 inches 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /ch09_networks/RingNetwork.nlogo: -------------------------------------------------------------------------------- 1 | 2 | to setup 3 | clear-all 4 | set-default-shape turtles "circle" 5 | ask patches [set pcolor white] ;;make background white 6 | make-turtles 7 | wire 8 | end 9 | 10 | to make-turtles 11 | create-turtles num-nodes [ 12 | set color orange 13 | set size 1 14 | ] 15 | ;; arrange them in a circle in order by who number 16 | layout-circle (sort turtles) max-pxcor - 1 17 | end 18 | 19 | ;; creates a new lattice 20 | to wire 21 | ;;ensure there can't more more than N - 1 edges per node 22 | if degree >= num-nodes 23 | [set degree num-nodes - 1] 24 | 25 | ;; iterate over the turtles 26 | let n 0 27 | while [n < count turtles] 28 | [ 29 | ;; iterate over pairs of edges 30 | let k 1 31 | while [k <= degree / 2] 32 | [ 33 | make-edge turtle n turtle ((n + k) mod count turtles) 34 | set k k + 1 35 | ] 36 | set n n + 1 37 | ] 38 | end 39 | 40 | ;; connects the two turtles 41 | to make-edge [node1 node2] 42 | ask node1 [ create-link-with node2 [set color black] ] 43 | end 44 | 45 | 46 | ; Copyright 2023 Paul E. Smaldino. 47 | ; See Info tab for full copyright and license. 48 | @#$#@#$#@ 49 | GRAPHICS-WINDOW 50 | 306 51 | 37 52 | 753 53 | 485 54 | -1 55 | -1 56 | 12.543 57 | 1 58 | 10 59 | 1 60 | 1 61 | 1 62 | 0 63 | 0 64 | 0 65 | 1 66 | -17 67 | 17 68 | -17 69 | 17 70 | 1 71 | 1 72 | 0 73 | ticks 74 | 30.0 75 | 76 | SLIDER 77 | 111 78 | 53 79 | 270 80 | 86 81 | num-nodes 82 | num-nodes 83 | 6 84 | 21 85 | 11.0 86 | 1 87 | 1 88 | NIL 89 | HORIZONTAL 90 | 91 | BUTTON 92 | 37 93 | 53 94 | 103 95 | 86 96 | setup 97 | setup 98 | NIL 99 | 1 100 | T 101 | OBSERVER 102 | NIL 103 | NIL 104 | NIL 105 | NIL 106 | 1 107 | 108 | SLIDER 109 | 111 110 | 94 111 | 270 112 | 127 113 | degree 114 | degree 115 | 2 116 | 20 117 | 8.0 118 | 2 119 | 1 120 | NIL 121 | HORIZONTAL 122 | 123 | @#$#@#$#@ 124 | ## Model Information and Materials 125 | 126 | This model is original material created by Paul E. Smaldino. 127 | 128 | ## References and Citation 129 | 130 | For this model: 131 | 132 | * Smaldino PE (2023). Ring Network. Modeling Social Behavior. https://github.com/psmaldino/modsoc/ 133 | 134 | For the book: 135 | 136 | * Smaldino PE (2023). Modeling Social Behavior: Mathematical and Agent-Based Models of Social Dynamics and Cultural Evolution. Princeton University Press. 137 | 138 | For the NetLogo: 139 | 140 | * Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. 141 | 142 | 143 | ## Licence 144 | 145 | ![CC BY-NC-SA 4.0](http://ccl.northwestern.edu/images/creativecommons/byncsa.png) 146 | 147 | This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/ 148 | @#$#@#$#@ 149 | default 150 | true 151 | 0 152 | Polygon -7500403 true true 150 5 40 250 150 205 260 250 153 | 154 | airplane 155 | true 156 | 0 157 | Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 158 | 159 | arrow 160 | true 161 | 0 162 | Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 163 | 164 | box 165 | false 166 | 0 167 | Polygon -7500403 true true 150 285 285 225 285 75 150 135 168 | Polygon -7500403 true true 150 135 15 75 150 15 285 75 169 | Polygon -7500403 true true 15 75 15 225 150 285 150 135 170 | Line -16777216 false 150 285 150 135 171 | Line -16777216 false 150 135 15 75 172 | Line -16777216 false 150 135 285 75 173 | 174 | bug 175 | true 176 | 0 177 | Circle -7500403 true true 96 182 108 178 | Circle -7500403 true true 110 127 80 179 | Circle -7500403 true true 110 75 80 180 | Line -7500403 true 150 100 80 30 181 | Line -7500403 true 150 100 220 30 182 | 183 | butterfly 184 | true 185 | 0 186 | Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 187 | Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 188 | Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 189 | Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 190 | Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 191 | Circle -16777216 true false 135 90 30 192 | Line -16777216 false 150 105 195 60 193 | Line -16777216 false 150 105 105 60 194 | 195 | car 196 | false 197 | 0 198 | Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 199 | Circle -16777216 true false 180 180 90 200 | Circle -16777216 true false 30 180 90 201 | Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 202 | Circle -7500403 true true 47 195 58 203 | Circle -7500403 true true 195 195 58 204 | 205 | circle 206 | false 207 | 0 208 | Circle -7500403 true true 0 0 300 209 | 210 | circle 2 211 | false 212 | 0 213 | Circle -7500403 true true 0 0 300 214 | Circle -16777216 true false 30 30 240 215 | 216 | cow 217 | false 218 | 0 219 | Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 220 | Polygon -7500403 true true 73 210 86 251 62 249 48 208 221 | Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 222 | 223 | cylinder 224 | false 225 | 0 226 | Circle -7500403 true true 0 0 300 227 | 228 | dot 229 | false 230 | 0 231 | Circle -7500403 true true 90 90 120 232 | 233 | face happy 234 | false 235 | 0 236 | Circle -7500403 true true 8 8 285 237 | Circle -16777216 true false 60 75 60 238 | Circle -16777216 true false 180 75 60 239 | Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 240 | 241 | face neutral 242 | false 243 | 0 244 | Circle -7500403 true true 8 7 285 245 | Circle -16777216 true false 60 75 60 246 | Circle -16777216 true false 180 75 60 247 | Rectangle -16777216 true false 60 195 240 225 248 | 249 | face sad 250 | false 251 | 0 252 | Circle -7500403 true true 8 8 285 253 | Circle -16777216 true false 60 75 60 254 | Circle -16777216 true false 180 75 60 255 | Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 256 | 257 | fish 258 | false 259 | 0 260 | Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 261 | Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 262 | Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 263 | Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 264 | Circle -16777216 true false 215 106 30 265 | 266 | flag 267 | false 268 | 0 269 | Rectangle -7500403 true true 60 15 75 300 270 | Polygon -7500403 true true 90 150 270 90 90 30 271 | Line -7500403 true 75 135 90 135 272 | Line -7500403 true 75 45 90 45 273 | 274 | flower 275 | false 276 | 0 277 | Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 278 | Circle -7500403 true true 85 132 38 279 | Circle -7500403 true true 130 147 38 280 | Circle -7500403 true true 192 85 38 281 | Circle -7500403 true true 85 40 38 282 | Circle -7500403 true true 177 40 38 283 | Circle -7500403 true true 177 132 38 284 | Circle -7500403 true true 70 85 38 285 | Circle -7500403 true true 130 25 38 286 | Circle -7500403 true true 96 51 108 287 | Circle -16777216 true false 113 68 74 288 | Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 289 | Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 290 | 291 | house 292 | false 293 | 0 294 | Rectangle -7500403 true true 45 120 255 285 295 | Rectangle -16777216 true false 120 210 180 285 296 | Polygon -7500403 true true 15 120 150 15 285 120 297 | Line -16777216 false 30 120 270 120 298 | 299 | leaf 300 | false 301 | 0 302 | Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 303 | Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 304 | 305 | line 306 | true 307 | 0 308 | Line -7500403 true 150 0 150 300 309 | 310 | line half 311 | true 312 | 0 313 | Line -7500403 true 150 0 150 150 314 | 315 | pentagon 316 | false 317 | 0 318 | Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 319 | 320 | person 321 | false 322 | 0 323 | Circle -7500403 true true 110 5 80 324 | Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 325 | Rectangle -7500403 true true 127 79 172 94 326 | Polygon -7500403 true true 195 90 240 150 225 180 165 105 327 | Polygon -7500403 true true 105 90 60 150 75 180 135 105 328 | 329 | plant 330 | false 331 | 0 332 | Rectangle -7500403 true true 135 90 165 300 333 | Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 334 | Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 335 | Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 336 | Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 337 | Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 338 | Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 339 | Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 340 | 341 | square 342 | false 343 | 0 344 | Rectangle -7500403 true true 30 30 270 270 345 | 346 | square 2 347 | false 348 | 0 349 | Rectangle -7500403 true true 30 30 270 270 350 | Rectangle -16777216 true false 60 60 240 240 351 | 352 | star 353 | false 354 | 0 355 | Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 356 | 357 | target 358 | false 359 | 0 360 | Circle -7500403 true true 0 0 300 361 | Circle -16777216 true false 30 30 240 362 | Circle -7500403 true true 60 60 180 363 | Circle -16777216 true false 90 90 120 364 | Circle -7500403 true true 120 120 60 365 | 366 | tree 367 | false 368 | 0 369 | Circle -7500403 true true 118 3 94 370 | Rectangle -6459832 true false 120 195 180 300 371 | Circle -7500403 true true 65 21 108 372 | Circle -7500403 true true 116 41 127 373 | Circle -7500403 true true 45 90 120 374 | Circle -7500403 true true 104 74 152 375 | 376 | triangle 377 | false 378 | 0 379 | Polygon -7500403 true true 150 30 15 255 285 255 380 | 381 | triangle 2 382 | false 383 | 0 384 | Polygon -7500403 true true 150 30 15 255 285 255 385 | Polygon -16777216 true false 151 99 225 223 75 224 386 | 387 | truck 388 | false 389 | 0 390 | Rectangle -7500403 true true 4 45 195 187 391 | Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 392 | Rectangle -1 true false 195 60 195 105 393 | Polygon -16777216 true false 238 112 252 141 219 141 218 112 394 | Circle -16777216 true false 234 174 42 395 | Rectangle -7500403 true true 181 185 214 194 396 | Circle -16777216 true false 144 174 42 397 | Circle -16777216 true false 24 174 42 398 | Circle -7500403 false true 24 174 42 399 | Circle -7500403 false true 144 174 42 400 | Circle -7500403 false true 234 174 42 401 | 402 | turtle 403 | true 404 | 0 405 | Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 406 | Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 407 | Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 408 | Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 409 | Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 410 | Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 411 | 412 | wheel 413 | false 414 | 0 415 | Circle -7500403 true true 3 3 294 416 | Circle -16777216 true false 30 30 240 417 | Line -7500403 true 150 285 150 15 418 | Line -7500403 true 15 150 285 150 419 | Circle -7500403 true true 120 120 60 420 | Line -7500403 true 216 40 79 269 421 | Line -7500403 true 40 84 269 221 422 | Line -7500403 true 40 216 269 79 423 | Line -7500403 true 84 40 221 269 424 | 425 | x 426 | false 427 | 0 428 | Polygon -7500403 true true 270 75 225 30 30 225 75 270 429 | Polygon -7500403 true true 30 75 75 30 270 225 225 270 430 | @#$#@#$#@ 431 | NetLogo 6.2.2 432 | @#$#@#$#@ 433 | setup 434 | repeat 5 [rewire-one] 435 | @#$#@#$#@ 436 | @#$#@#$#@ 437 | 438 | 439 | rewire-all 440 | 441 | rewiring-probability > 1 442 | average-path-length 443 | clustering-coefficient 444 | 445 | 446 | 447 | @#$#@#$#@ 448 | @#$#@#$#@ 449 | default 450 | 0.0 451 | -0.2 0 0.0 1.0 452 | 0.0 1 1.0 0.0 453 | 0.2 0 0.0 1.0 454 | link direction 455 | true 456 | 0 457 | Line -7500403 true 150 150 90 180 458 | Line -7500403 true 150 150 210 180 459 | @#$#@#$#@ 460 | 0 461 | @#$#@#$#@ 462 | -------------------------------------------------------------------------------- /ch09_networks/RandomNetwork.nlogo: -------------------------------------------------------------------------------- 1 | ;; Create nodes. 2 | to setup 3 | clear-all 4 | ask patches [set pcolor white] ;;make background white 5 | create-turtles num-nodes [ 6 | set shape "circle" 7 | set color orange 8 | ] 9 | layout-circle (sort turtles) max-pxcor - 1 10 | reset-ticks 11 | end 12 | 13 | 14 | ;; Each possible pair of nodes gets a chance to 15 | ;; create a link between them with a specified probability. 16 | to wire 17 | ask links [ die ] 18 | ask turtles [ 19 | ask turtles with [ who > [ who ] of myself ] [ 20 | if random-float 1.0 < wiring-prob [ 21 | create-link-with myself 22 | ] 23 | ] 24 | ] 25 | tick 26 | end 27 | 28 | 29 | ; Copyright 2023 Paul E. Smaldino. 30 | ; See Info tab for full copyright and license. 31 | @#$#@#$#@ 32 | GRAPHICS-WINDOW 33 | 210 34 | 10 35 | 588 36 | 389 37 | -1 38 | -1 39 | 11.212121212121213 40 | 1 41 | 10 42 | 1 43 | 1 44 | 1 45 | 0 46 | 0 47 | 0 48 | 1 49 | -16 50 | 16 51 | -16 52 | 16 53 | 1 54 | 1 55 | 1 56 | ticks 57 | 30.0 58 | 59 | BUTTON 60 | 10 61 | 90 62 | 180 63 | 123 64 | NIL 65 | setup 66 | NIL 67 | 1 68 | T 69 | OBSERVER 70 | NIL 71 | NIL 72 | NIL 73 | NIL 74 | 1 75 | 76 | SLIDER 77 | 10 78 | 10 79 | 180 80 | 43 81 | num-nodes 82 | num-nodes 83 | 0 84 | 1000 85 | 1000.0 86 | 1 87 | 1 88 | NIL 89 | HORIZONTAL 90 | 91 | MONITOR 92 | 10 93 | 180 94 | 71 95 | 225 96 | max-deg 97 | max [count link-neighbors] of turtles 98 | 1 99 | 1 100 | 11 101 | 102 | BUTTON 103 | 10 104 | 130 105 | 180 106 | 163 107 | NIL 108 | wire 109 | NIL 110 | 1 111 | T 112 | OBSERVER 113 | NIL 114 | NIL 115 | NIL 116 | NIL 117 | 0 118 | 119 | SLIDER 120 | 10 121 | 50 122 | 182 123 | 83 124 | wiring-prob 125 | wiring-prob 126 | 0 127 | 1 128 | 0.1 129 | .01 130 | 1 131 | NIL 132 | HORIZONTAL 133 | 134 | MONITOR 135 | 147 136 | 180 137 | 204 138 | 225 139 | #links 140 | count links 141 | 1 142 | 1 143 | 11 144 | 145 | MONITOR 146 | 77 147 | 180 148 | 143 149 | 225 150 | min-deg 151 | min [count link-neighbors] of turtles 152 | 1 153 | 1 154 | 11 155 | 156 | PLOT 157 | 600 158 | 10 159 | 965 160 | 330 161 | degree distribution 162 | degree 163 | count 164 | 0.0 165 | 25.0 166 | 0.0 167 | 100.0 168 | false 169 | false 170 | "" "set-plot-x-range (min [count link-neighbors] of turtles) (max [count link-neighbors] of turtles + 1) " 171 | PENS 172 | "default" 1.0 1 -16777216 true "" "histogram [count link-neighbors] of turtles" 173 | 174 | @#$#@#$#@ 175 | ## Model Information and Materials 176 | 177 | This model is original material created by Paul E. Smaldino, building on code by Wilensky and Rand (2008). 178 | 179 | * Wilensky, U., Rand, W. (2008). NetLogo Random Network model. http://ccl.northwestern.edu/netlogo/models/RandomNetwork. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL. 180 | 181 | ## References and Citation 182 | 183 | For this model: 184 | 185 | * Smaldino PE (2023). Random Network. Modeling Social Behavior. https://github.com/psmaldino/modsoc/ 186 | 187 | For the book: 188 | 189 | * Smaldino PE (2023). Modeling Social Behavior: Mathematical and Agent-Based Models of Social Dynamics and Cultural Evolution. Princeton University Press. 190 | 191 | For the NetLogo: 192 | 193 | * Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. 194 | 195 | 196 | ## Licence 197 | 198 | ![CC BY-NC-SA 4.0](http://ccl.northwestern.edu/images/creativecommons/byncsa.png) 199 | 200 | This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/ 201 | 202 | @#$#@#$#@ 203 | default 204 | true 205 | 0 206 | Polygon -7500403 true true 150 5 40 250 150 205 260 250 207 | 208 | airplane 209 | true 210 | 0 211 | Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 212 | 213 | arrow 214 | true 215 | 0 216 | Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 217 | 218 | box 219 | false 220 | 0 221 | Polygon -7500403 true true 150 285 285 225 285 75 150 135 222 | Polygon -7500403 true true 150 135 15 75 150 15 285 75 223 | Polygon -7500403 true true 15 75 15 225 150 285 150 135 224 | Line -16777216 false 150 285 150 135 225 | Line -16777216 false 150 135 15 75 226 | Line -16777216 false 150 135 285 75 227 | 228 | bug 229 | true 230 | 0 231 | Circle -7500403 true true 96 182 108 232 | Circle -7500403 true true 110 127 80 233 | Circle -7500403 true true 110 75 80 234 | Line -7500403 true 150 100 80 30 235 | Line -7500403 true 150 100 220 30 236 | 237 | butterfly 238 | true 239 | 0 240 | Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 241 | Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 242 | Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 243 | Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 244 | Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 245 | Circle -16777216 true false 135 90 30 246 | Line -16777216 false 150 105 195 60 247 | Line -16777216 false 150 105 105 60 248 | 249 | car 250 | false 251 | 0 252 | Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 253 | Circle -16777216 true false 180 180 90 254 | Circle -16777216 true false 30 180 90 255 | Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 256 | Circle -7500403 true true 47 195 58 257 | Circle -7500403 true true 195 195 58 258 | 259 | circle 260 | false 261 | 0 262 | Circle -7500403 true true 0 0 300 263 | 264 | circle 2 265 | false 266 | 0 267 | Circle -7500403 true true 0 0 300 268 | Circle -16777216 true false 30 30 240 269 | 270 | cow 271 | false 272 | 0 273 | Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 274 | Polygon -7500403 true true 73 210 86 251 62 249 48 208 275 | Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 276 | 277 | cylinder 278 | false 279 | 0 280 | Circle -7500403 true true 0 0 300 281 | 282 | dot 283 | false 284 | 0 285 | Circle -7500403 true true 90 90 120 286 | 287 | face happy 288 | false 289 | 0 290 | Circle -7500403 true true 8 8 285 291 | Circle -16777216 true false 60 75 60 292 | Circle -16777216 true false 180 75 60 293 | Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 294 | 295 | face neutral 296 | false 297 | 0 298 | Circle -7500403 true true 8 7 285 299 | Circle -16777216 true false 60 75 60 300 | Circle -16777216 true false 180 75 60 301 | Rectangle -16777216 true false 60 195 240 225 302 | 303 | face sad 304 | false 305 | 0 306 | Circle -7500403 true true 8 8 285 307 | Circle -16777216 true false 60 75 60 308 | Circle -16777216 true false 180 75 60 309 | Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 310 | 311 | fish 312 | false 313 | 0 314 | Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 315 | Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 316 | Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 317 | Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 318 | Circle -16777216 true false 215 106 30 319 | 320 | flag 321 | false 322 | 0 323 | Rectangle -7500403 true true 60 15 75 300 324 | Polygon -7500403 true true 90 150 270 90 90 30 325 | Line -7500403 true 75 135 90 135 326 | Line -7500403 true 75 45 90 45 327 | 328 | flower 329 | false 330 | 0 331 | Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 332 | Circle -7500403 true true 85 132 38 333 | Circle -7500403 true true 130 147 38 334 | Circle -7500403 true true 192 85 38 335 | Circle -7500403 true true 85 40 38 336 | Circle -7500403 true true 177 40 38 337 | Circle -7500403 true true 177 132 38 338 | Circle -7500403 true true 70 85 38 339 | Circle -7500403 true true 130 25 38 340 | Circle -7500403 true true 96 51 108 341 | Circle -16777216 true false 113 68 74 342 | Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 343 | Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 344 | 345 | house 346 | false 347 | 0 348 | Rectangle -7500403 true true 45 120 255 285 349 | Rectangle -16777216 true false 120 210 180 285 350 | Polygon -7500403 true true 15 120 150 15 285 120 351 | Line -16777216 false 30 120 270 120 352 | 353 | leaf 354 | false 355 | 0 356 | Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 357 | Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 358 | 359 | line 360 | true 361 | 0 362 | Line -7500403 true 150 0 150 300 363 | 364 | line half 365 | true 366 | 0 367 | Line -7500403 true 150 0 150 150 368 | 369 | pentagon 370 | false 371 | 0 372 | Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 373 | 374 | person 375 | false 376 | 0 377 | Circle -7500403 true true 110 5 80 378 | Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 379 | Rectangle -7500403 true true 127 79 172 94 380 | Polygon -7500403 true true 195 90 240 150 225 180 165 105 381 | Polygon -7500403 true true 105 90 60 150 75 180 135 105 382 | 383 | plant 384 | false 385 | 0 386 | Rectangle -7500403 true true 135 90 165 300 387 | Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 388 | Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 389 | Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 390 | Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 391 | Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 392 | Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 393 | Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 394 | 395 | sheep 396 | false 397 | 15 398 | Circle -1 true true 203 65 88 399 | Circle -1 true true 70 65 162 400 | Circle -1 true true 150 105 120 401 | Polygon -7500403 true false 218 120 240 165 255 165 278 120 402 | Circle -7500403 true false 214 72 67 403 | Rectangle -1 true true 164 223 179 298 404 | Polygon -1 true true 45 285 30 285 30 240 15 195 45 210 405 | Circle -1 true true 3 83 150 406 | Rectangle -1 true true 65 221 80 296 407 | Polygon -1 true true 195 285 210 285 210 240 240 210 195 210 408 | Polygon -7500403 true false 276 85 285 105 302 99 294 83 409 | Polygon -7500403 true false 219 85 210 105 193 99 201 83 410 | 411 | square 412 | false 413 | 0 414 | Rectangle -7500403 true true 30 30 270 270 415 | 416 | square 2 417 | false 418 | 0 419 | Rectangle -7500403 true true 30 30 270 270 420 | Rectangle -16777216 true false 60 60 240 240 421 | 422 | star 423 | false 424 | 0 425 | Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 426 | 427 | target 428 | false 429 | 0 430 | Circle -7500403 true true 0 0 300 431 | Circle -16777216 true false 30 30 240 432 | Circle -7500403 true true 60 60 180 433 | Circle -16777216 true false 90 90 120 434 | Circle -7500403 true true 120 120 60 435 | 436 | tree 437 | false 438 | 0 439 | Circle -7500403 true true 118 3 94 440 | Rectangle -6459832 true false 120 195 180 300 441 | Circle -7500403 true true 65 21 108 442 | Circle -7500403 true true 116 41 127 443 | Circle -7500403 true true 45 90 120 444 | Circle -7500403 true true 104 74 152 445 | 446 | triangle 447 | false 448 | 0 449 | Polygon -7500403 true true 150 30 15 255 285 255 450 | 451 | triangle 2 452 | false 453 | 0 454 | Polygon -7500403 true true 150 30 15 255 285 255 455 | Polygon -16777216 true false 151 99 225 223 75 224 456 | 457 | truck 458 | false 459 | 0 460 | Rectangle -7500403 true true 4 45 195 187 461 | Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 462 | Rectangle -1 true false 195 60 195 105 463 | Polygon -16777216 true false 238 112 252 141 219 141 218 112 464 | Circle -16777216 true false 234 174 42 465 | Rectangle -7500403 true true 181 185 214 194 466 | Circle -16777216 true false 144 174 42 467 | Circle -16777216 true false 24 174 42 468 | Circle -7500403 false true 24 174 42 469 | Circle -7500403 false true 144 174 42 470 | Circle -7500403 false true 234 174 42 471 | 472 | turtle 473 | true 474 | 0 475 | Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 476 | Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 477 | Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 478 | Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 479 | Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 480 | Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 481 | 482 | wheel 483 | false 484 | 0 485 | Circle -7500403 true true 3 3 294 486 | Circle -16777216 true false 30 30 240 487 | Line -7500403 true 150 285 150 15 488 | Line -7500403 true 15 150 285 150 489 | Circle -7500403 true true 120 120 60 490 | Line -7500403 true 216 40 79 269 491 | Line -7500403 true 40 84 269 221 492 | Line -7500403 true 40 216 269 79 493 | Line -7500403 true 84 40 221 269 494 | 495 | wolf 496 | false 497 | 0 498 | Polygon -16777216 true false 253 133 245 131 245 133 499 | Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105 500 | Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113 501 | 502 | x 503 | false 504 | 0 505 | Polygon -7500403 true true 270 75 225 30 30 225 75 270 506 | Polygon -7500403 true true 30 75 75 30 270 225 225 270 507 | @#$#@#$#@ 508 | NetLogo 6.2.2 509 | @#$#@#$#@ 510 | setup wire1 511 | @#$#@#$#@ 512 | @#$#@#$#@ 513 | @#$#@#$#@ 514 | @#$#@#$#@ 515 | default 516 | 0.0 517 | -0.2 0 0.0 1.0 518 | 0.0 1 1.0 0.0 519 | 0.2 0 0.0 1.0 520 | link direction 521 | true 522 | 0 523 | Line -7500403 true 150 150 90 180 524 | Line -7500403 true 150 150 210 180 525 | @#$#@#$#@ 526 | 1 527 | @#$#@#$#@ 528 | -------------------------------------------------------------------------------- /ch05_opinions/opiniondynamics_posinfluence.nlogo: -------------------------------------------------------------------------------- 1 | turtles-own [opinion] 2 | 3 | ;;create one turle on each patch, give each a random opinion 4 | to setup 5 | clear-all 6 | ask patches[ 7 | sprout 1[ 8 | set opinion (random-float 2) - 1 ;;give each agent an opinion drawn from [-1, 1] 9 | set shape "circle" 10 | ] 11 | ] 12 | update-colors ;;color represents opinion 13 | reset-ticks 14 | end 15 | 16 | 17 | to go 18 | ;; a random agent chooses another agent for a potential interaction 19 | ask one-of turtles [ 20 | let x1 opinion ;;my opinion 21 | let other-turtle one-of other turtles ;;choose interaction partner at random 22 | let x2 [opinion] of other-turtle ;;other guy's opinion 23 | 24 | ;;Everyone becomes more similar to their partner 25 | let x1-new (x1 + learning-rate * (x2 - x1)) 26 | let x2-new (x2 + learning-rate * (x1 - x2)) 27 | set opinion x1-new 28 | ask other-turtle [ set opinion x2-new] 29 | ] 30 | update-colors 31 | tick 32 | end 33 | 34 | 35 | ;;shade each agent between black (opinion = -1) and white (opinion = 1) 36 | to update-colors 37 | ask turtles [ 38 | set color (opinion + 1) * 9.9 / 2 39 | ] 40 | end 41 | 42 | 43 | ; Copyright 2023 Paul E. Smaldino. 44 | ; See Info tab for full copyright and license. 45 | @#$#@#$#@ 46 | GRAPHICS-WINDOW 47 | 269 48 | 14 49 | 579 50 | 325 51 | -1 52 | -1 53 | 14.4 54 | 1 55 | 10 56 | 1 57 | 1 58 | 1 59 | 0 60 | 0 61 | 0 62 | 1 63 | -10 64 | 10 65 | -10 66 | 10 67 | 0 68 | 0 69 | 1 70 | ticks 71 | 30.0 72 | 73 | BUTTON 74 | 85 75 | 34 76 | 151 77 | 67 78 | NIL 79 | setup 80 | NIL 81 | 1 82 | T 83 | OBSERVER 84 | NIL 85 | NIL 86 | NIL 87 | NIL 88 | 1 89 | 90 | BUTTON 91 | 157 92 | 34 93 | 249 94 | 67 95 | NIL 96 | go 97 | T 98 | 1 99 | T 100 | OBSERVER 101 | NIL 102 | NIL 103 | NIL 104 | NIL 105 | 0 106 | 107 | SLIDER 108 | 86 109 | 77 110 | 250 111 | 110 112 | learning-rate 113 | learning-rate 114 | 0 115 | 1 116 | 0.3 117 | .01 118 | 1 119 | NIL 120 | HORIZONTAL 121 | 122 | PLOT 123 | 270 124 | 329 125 | 580 126 | 513 127 | Agent opinions 128 | opinion 129 | number of agents 130 | -1.2 131 | 1.2 132 | 0.0 133 | 10.0 134 | false 135 | false 136 | "set-plot-x-range -1.02 1.02\nset-plot-y-range 0 count turtles\nset-histogram-num-bars 40\n" "" 137 | PENS 138 | "default" 1.0 1 -16777216 true "" "histogram [opinion] of turtles" 139 | 140 | PLOT 141 | 583 142 | 14 143 | 970 144 | 512 145 | Agent opinions over time 146 | time 147 | opinions 148 | 0.0 149 | 10.0 150 | -1.0 151 | 1.0 152 | true 153 | false 154 | "" "" 155 | PENS 156 | "default" 1.0 2 -14730904 true "" "if (ticks mod 100 = 0) [\nask turtles [\nplotxy ticks opinion\n]\n]" 157 | 158 | @#$#@#$#@ 159 | ## Model Information and Materials 160 | 161 | This model is original material created by Paul E. Smaldino. The model is based on work by Deffuant et al. (2000). 162 | 163 | * Deffuant, G., Neau, D., Amblard, F., & Weisbuch, G. (2000). Mixing beliefs among interacting agents. Advances in Complex Systems, 3, 87-98. 164 | 165 | ## References and Citation 166 | 167 | For this model: 168 | 169 | * Smaldino PE (2023). Opinion Dynamics: Positive Influence. Modeling Social Behavior. https://github.com/psmaldino/modsoc/ 170 | 171 | For the book: 172 | 173 | * Smaldino PE (2023). Modeling Social Behavior: Mathematical and Agent-Based Models of Social Dynamics and Cultural Evolution. Princeton University Press. 174 | 175 | For the NetLogo: 176 | 177 | * Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. 178 | 179 | 180 | ## Licence 181 | 182 | ![CC BY-NC-SA 4.0](http://ccl.northwestern.edu/images/creativecommons/byncsa.png) 183 | 184 | This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/ 185 | @#$#@#$#@ 186 | default 187 | true 188 | 0 189 | Polygon -7500403 true true 150 5 40 250 150 205 260 250 190 | 191 | airplane 192 | true 193 | 0 194 | Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 195 | 196 | arrow 197 | true 198 | 0 199 | Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 200 | 201 | box 202 | false 203 | 0 204 | Polygon -7500403 true true 150 285 285 225 285 75 150 135 205 | Polygon -7500403 true true 150 135 15 75 150 15 285 75 206 | Polygon -7500403 true true 15 75 15 225 150 285 150 135 207 | Line -16777216 false 150 285 150 135 208 | Line -16777216 false 150 135 15 75 209 | Line -16777216 false 150 135 285 75 210 | 211 | bug 212 | true 213 | 0 214 | Circle -7500403 true true 96 182 108 215 | Circle -7500403 true true 110 127 80 216 | Circle -7500403 true true 110 75 80 217 | Line -7500403 true 150 100 80 30 218 | Line -7500403 true 150 100 220 30 219 | 220 | butterfly 221 | true 222 | 0 223 | Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 224 | Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 225 | Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 226 | Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 227 | Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 228 | Circle -16777216 true false 135 90 30 229 | Line -16777216 false 150 105 195 60 230 | Line -16777216 false 150 105 105 60 231 | 232 | car 233 | false 234 | 0 235 | Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 236 | Circle -16777216 true false 180 180 90 237 | Circle -16777216 true false 30 180 90 238 | Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 239 | Circle -7500403 true true 47 195 58 240 | Circle -7500403 true true 195 195 58 241 | 242 | circle 243 | false 244 | 0 245 | Circle -7500403 true true 0 0 300 246 | 247 | circle 2 248 | false 249 | 0 250 | Circle -7500403 true true 0 0 300 251 | Circle -16777216 true false 30 30 240 252 | 253 | cow 254 | false 255 | 0 256 | Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 257 | Polygon -7500403 true true 73 210 86 251 62 249 48 208 258 | Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 259 | 260 | cylinder 261 | false 262 | 0 263 | Circle -7500403 true true 0 0 300 264 | 265 | dot 266 | false 267 | 0 268 | Circle -7500403 true true 90 90 120 269 | 270 | face happy 271 | false 272 | 0 273 | Circle -7500403 true true 8 8 285 274 | Circle -16777216 true false 60 75 60 275 | Circle -16777216 true false 180 75 60 276 | Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 277 | 278 | face neutral 279 | false 280 | 0 281 | Circle -7500403 true true 8 7 285 282 | Circle -16777216 true false 60 75 60 283 | Circle -16777216 true false 180 75 60 284 | Rectangle -16777216 true false 60 195 240 225 285 | 286 | face sad 287 | false 288 | 0 289 | Circle -7500403 true true 8 8 285 290 | Circle -16777216 true false 60 75 60 291 | Circle -16777216 true false 180 75 60 292 | Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 293 | 294 | fish 295 | false 296 | 0 297 | Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 298 | Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 299 | Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 300 | Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 301 | Circle -16777216 true false 215 106 30 302 | 303 | flag 304 | false 305 | 0 306 | Rectangle -7500403 true true 60 15 75 300 307 | Polygon -7500403 true true 90 150 270 90 90 30 308 | Line -7500403 true 75 135 90 135 309 | Line -7500403 true 75 45 90 45 310 | 311 | flower 312 | false 313 | 0 314 | Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 315 | Circle -7500403 true true 85 132 38 316 | Circle -7500403 true true 130 147 38 317 | Circle -7500403 true true 192 85 38 318 | Circle -7500403 true true 85 40 38 319 | Circle -7500403 true true 177 40 38 320 | Circle -7500403 true true 177 132 38 321 | Circle -7500403 true true 70 85 38 322 | Circle -7500403 true true 130 25 38 323 | Circle -7500403 true true 96 51 108 324 | Circle -16777216 true false 113 68 74 325 | Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 326 | Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 327 | 328 | house 329 | false 330 | 0 331 | Rectangle -7500403 true true 45 120 255 285 332 | Rectangle -16777216 true false 120 210 180 285 333 | Polygon -7500403 true true 15 120 150 15 285 120 334 | Line -16777216 false 30 120 270 120 335 | 336 | leaf 337 | false 338 | 0 339 | Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 340 | Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 341 | 342 | line 343 | true 344 | 0 345 | Line -7500403 true 150 0 150 300 346 | 347 | line half 348 | true 349 | 0 350 | Line -7500403 true 150 0 150 150 351 | 352 | pentagon 353 | false 354 | 0 355 | Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 356 | 357 | person 358 | false 359 | 0 360 | Circle -7500403 true true 110 5 80 361 | Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 362 | Rectangle -7500403 true true 127 79 172 94 363 | Polygon -7500403 true true 195 90 240 150 225 180 165 105 364 | Polygon -7500403 true true 105 90 60 150 75 180 135 105 365 | 366 | plant 367 | false 368 | 0 369 | Rectangle -7500403 true true 135 90 165 300 370 | Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 371 | Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 372 | Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 373 | Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 374 | Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 375 | Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 376 | Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 377 | 378 | sheep 379 | false 380 | 15 381 | Circle -1 true true 203 65 88 382 | Circle -1 true true 70 65 162 383 | Circle -1 true true 150 105 120 384 | Polygon -7500403 true false 218 120 240 165 255 165 278 120 385 | Circle -7500403 true false 214 72 67 386 | Rectangle -1 true true 164 223 179 298 387 | Polygon -1 true true 45 285 30 285 30 240 15 195 45 210 388 | Circle -1 true true 3 83 150 389 | Rectangle -1 true true 65 221 80 296 390 | Polygon -1 true true 195 285 210 285 210 240 240 210 195 210 391 | Polygon -7500403 true false 276 85 285 105 302 99 294 83 392 | Polygon -7500403 true false 219 85 210 105 193 99 201 83 393 | 394 | square 395 | false 396 | 0 397 | Rectangle -7500403 true true 30 30 270 270 398 | 399 | square 2 400 | false 401 | 0 402 | Rectangle -7500403 true true 30 30 270 270 403 | Rectangle -16777216 true false 60 60 240 240 404 | 405 | star 406 | false 407 | 0 408 | Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 409 | 410 | target 411 | false 412 | 0 413 | Circle -7500403 true true 0 0 300 414 | Circle -16777216 true false 30 30 240 415 | Circle -7500403 true true 60 60 180 416 | Circle -16777216 true false 90 90 120 417 | Circle -7500403 true true 120 120 60 418 | 419 | tree 420 | false 421 | 0 422 | Circle -7500403 true true 118 3 94 423 | Rectangle -6459832 true false 120 195 180 300 424 | Circle -7500403 true true 65 21 108 425 | Circle -7500403 true true 116 41 127 426 | Circle -7500403 true true 45 90 120 427 | Circle -7500403 true true 104 74 152 428 | 429 | triangle 430 | false 431 | 0 432 | Polygon -7500403 true true 150 30 15 255 285 255 433 | 434 | triangle 2 435 | false 436 | 0 437 | Polygon -7500403 true true 150 30 15 255 285 255 438 | Polygon -16777216 true false 151 99 225 223 75 224 439 | 440 | truck 441 | false 442 | 0 443 | Rectangle -7500403 true true 4 45 195 187 444 | Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 445 | Rectangle -1 true false 195 60 195 105 446 | Polygon -16777216 true false 238 112 252 141 219 141 218 112 447 | Circle -16777216 true false 234 174 42 448 | Rectangle -7500403 true true 181 185 214 194 449 | Circle -16777216 true false 144 174 42 450 | Circle -16777216 true false 24 174 42 451 | Circle -7500403 false true 24 174 42 452 | Circle -7500403 false true 144 174 42 453 | Circle -7500403 false true 234 174 42 454 | 455 | turtle 456 | true 457 | 0 458 | Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 459 | Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 460 | Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 461 | Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 462 | Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 463 | Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 464 | 465 | wheel 466 | false 467 | 0 468 | Circle -7500403 true true 3 3 294 469 | Circle -16777216 true false 30 30 240 470 | Line -7500403 true 150 285 150 15 471 | Line -7500403 true 15 150 285 150 472 | Circle -7500403 true true 120 120 60 473 | Line -7500403 true 216 40 79 269 474 | Line -7500403 true 40 84 269 221 475 | Line -7500403 true 40 216 269 79 476 | Line -7500403 true 84 40 221 269 477 | 478 | wolf 479 | false 480 | 0 481 | Polygon -16777216 true false 253 133 245 131 245 133 482 | Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105 483 | Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113 484 | 485 | x 486 | false 487 | 0 488 | Polygon -7500403 true true 270 75 225 30 30 225 75 270 489 | Polygon -7500403 true true 30 75 75 30 270 225 225 270 490 | @#$#@#$#@ 491 | NetLogo 6.2.2 492 | @#$#@#$#@ 493 | @#$#@#$#@ 494 | @#$#@#$#@ 495 | @#$#@#$#@ 496 | @#$#@#$#@ 497 | default 498 | 0.0 499 | -0.2 0 0.0 1.0 500 | 0.0 1 1.0 0.0 501 | 0.2 0 0.0 1.0 502 | link direction 503 | true 504 | 0 505 | Line -7500403 true 150 150 90 180 506 | Line -7500403 true 150 150 210 180 507 | @#$#@#$#@ 508 | 0 509 | @#$#@#$#@ 510 | -------------------------------------------------------------------------------- /ch08_science/science_bayesianupdating.nlogo: -------------------------------------------------------------------------------- 1 | ;; A model of science as a Bayesian updating process 2 | 3 | 4 | globals [ prob-true ] 5 | 6 | to setup 7 | clear-all 8 | set prob-true initial-prior 9 | ifelse true-hypothesis? ;;Color patches with initial epistemic state 10 | [ask patches [set pcolor green]] 11 | [ask patches [set pcolor red]] 12 | reset-ticks 13 | end 14 | 15 | ;;Bayesian updating 16 | to go 17 | ;;hypothesis is actually true 18 | ifelse true-hypothesis? [ 19 | ;;true positive 20 | ifelse random-float 1 < power [ 21 | ask patches [set pcolor green] 22 | set prob-true (power * prob-true) / ((power * prob-true) + (false-positive-rate * (1 - prob-true))) 23 | ] 24 | ;;false negative 25 | [ 26 | ask patches [set pcolor red] 27 | set prob-true ((1 - power) * prob-true) / (((1 - power) * prob-true) + ((1 - false-positive-rate) * (1 - prob-true))) 28 | ] 29 | ] 30 | ;;hypothesis is actually false 31 | [ 32 | ;;false positive 33 | ifelse random-float 1 < false-positive-rate [ 34 | ask patches [set pcolor green] 35 | set prob-true (power * prob-true) / ((power * prob-true) + (false-positive-rate * (1 - prob-true))) 36 | ] 37 | ;;true negative 38 | [ 39 | ask patches [set pcolor red] 40 | set prob-true ((1 - power) * prob-true) / (((1 - power) * prob-true) + ((1 - false-positive-rate) * (1 - prob-true))) 41 | ] 42 | ] 43 | tick 44 | end 45 | 46 | ; Copyright 2023 Paul E. Smaldino. 47 | ; See Info tab for full copyright and license. 48 | @#$#@#$#@ 49 | GRAPHICS-WINDOW 50 | 205 51 | 11 52 | 515 53 | 63 54 | -1 55 | -1 56 | 14.4 57 | 1 58 | 10 59 | 1 60 | 1 61 | 1 62 | 0 63 | 1 64 | 1 65 | 1 66 | -10 67 | 10 68 | -1 69 | 1 70 | 1 71 | 1 72 | 1 73 | ticks 74 | 30.0 75 | 76 | BUTTON 77 | 20 78 | 21 79 | 94 80 | 54 81 | NIL 82 | setup 83 | NIL 84 | 1 85 | T 86 | OBSERVER 87 | NIL 88 | NIL 89 | NIL 90 | NIL 91 | 1 92 | 93 | BUTTON 94 | 99 95 | 21 96 | 180 97 | 54 98 | go once 99 | go 100 | NIL 101 | 1 102 | T 103 | OBSERVER 104 | NIL 105 | NIL 106 | NIL 107 | NIL 108 | 0 109 | 110 | SLIDER 111 | 16 112 | 90 113 | 189 114 | 123 115 | initial-prior 116 | initial-prior 117 | 0 118 | 1 119 | 0.1 120 | .001 121 | 1 122 | NIL 123 | HORIZONTAL 124 | 125 | SLIDER 126 | 16 127 | 133 128 | 188 129 | 166 130 | false-positive-rate 131 | false-positive-rate 132 | 0 133 | 1 134 | 0.05 135 | .001 136 | 1 137 | NIL 138 | HORIZONTAL 139 | 140 | SLIDER 141 | 16 142 | 177 143 | 189 144 | 210 145 | power 146 | power 147 | 0 148 | 1 149 | 0.5 150 | .001 151 | 1 152 | NIL 153 | HORIZONTAL 154 | 155 | SWITCH 156 | 17 157 | 221 158 | 189 159 | 254 160 | true-hypothesis? 161 | true-hypothesis? 162 | 0 163 | 1 164 | -1000 165 | 166 | PLOT 167 | 205 168 | 69 169 | 516 170 | 261 171 | Probability of True Hypothesis 172 | time 173 | Pr(true) 174 | 0.0 175 | 10.0 176 | 0.0 177 | 1.0 178 | true 179 | false 180 | "" "" 181 | PENS 182 | "default" 1.0 0 -16777216 true "" "plot prob-true" 183 | 184 | TEXTBOX 185 | 325 186 | 26 187 | 656 188 | 131 189 | RESULT 190 | 18 191 | 9.0 192 | 1 193 | 194 | @#$#@#$#@ 195 | ## Model Information and Materials 196 | 197 | This model is original material created by Paul E. Smaldino. 198 | 199 | ## References and Citation 200 | 201 | For this model: 202 | 203 | * Smaldino PE (2023). Science as Bayesian Updating. Modeling Social Behavior. https://github.com/psmaldino/modsoc/ 204 | 205 | For the book: 206 | 207 | * Smaldino PE (2023). Modeling Social Behavior: Mathematical and Agent-Based Models of Social Dynamics and Cultural Evolution. Princeton University Press. 208 | 209 | For the NetLogo: 210 | 211 | * Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. 212 | 213 | 214 | ## Licence 215 | 216 | ![CC BY-NC-SA 4.0](http://ccl.northwestern.edu/images/creativecommons/byncsa.png) 217 | 218 | This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/ 219 | @#$#@#$#@ 220 | default 221 | true 222 | 0 223 | Polygon -7500403 true true 150 5 40 250 150 205 260 250 224 | 225 | airplane 226 | true 227 | 0 228 | Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 229 | 230 | arrow 231 | true 232 | 0 233 | Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 234 | 235 | box 236 | false 237 | 0 238 | Polygon -7500403 true true 150 285 285 225 285 75 150 135 239 | Polygon -7500403 true true 150 135 15 75 150 15 285 75 240 | Polygon -7500403 true true 15 75 15 225 150 285 150 135 241 | Line -16777216 false 150 285 150 135 242 | Line -16777216 false 150 135 15 75 243 | Line -16777216 false 150 135 285 75 244 | 245 | bug 246 | true 247 | 0 248 | Circle -7500403 true true 96 182 108 249 | Circle -7500403 true true 110 127 80 250 | Circle -7500403 true true 110 75 80 251 | Line -7500403 true 150 100 80 30 252 | Line -7500403 true 150 100 220 30 253 | 254 | butterfly 255 | true 256 | 0 257 | Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 258 | Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 259 | Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 260 | Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 261 | Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 262 | Circle -16777216 true false 135 90 30 263 | Line -16777216 false 150 105 195 60 264 | Line -16777216 false 150 105 105 60 265 | 266 | car 267 | false 268 | 0 269 | Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 270 | Circle -16777216 true false 180 180 90 271 | Circle -16777216 true false 30 180 90 272 | Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 273 | Circle -7500403 true true 47 195 58 274 | Circle -7500403 true true 195 195 58 275 | 276 | circle 277 | false 278 | 0 279 | Circle -7500403 true true 0 0 300 280 | 281 | circle 2 282 | false 283 | 0 284 | Circle -7500403 true true 0 0 300 285 | Circle -16777216 true false 30 30 240 286 | 287 | cow 288 | false 289 | 0 290 | Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 291 | Polygon -7500403 true true 73 210 86 251 62 249 48 208 292 | Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 293 | 294 | cylinder 295 | false 296 | 0 297 | Circle -7500403 true true 0 0 300 298 | 299 | dot 300 | false 301 | 0 302 | Circle -7500403 true true 90 90 120 303 | 304 | face happy 305 | false 306 | 0 307 | Circle -7500403 true true 8 8 285 308 | Circle -16777216 true false 60 75 60 309 | Circle -16777216 true false 180 75 60 310 | Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 311 | 312 | face neutral 313 | false 314 | 0 315 | Circle -7500403 true true 8 7 285 316 | Circle -16777216 true false 60 75 60 317 | Circle -16777216 true false 180 75 60 318 | Rectangle -16777216 true false 60 195 240 225 319 | 320 | face sad 321 | false 322 | 0 323 | Circle -7500403 true true 8 8 285 324 | Circle -16777216 true false 60 75 60 325 | Circle -16777216 true false 180 75 60 326 | Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 327 | 328 | fish 329 | false 330 | 0 331 | Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 332 | Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 333 | Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 334 | Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 335 | Circle -16777216 true false 215 106 30 336 | 337 | flag 338 | false 339 | 0 340 | Rectangle -7500403 true true 60 15 75 300 341 | Polygon -7500403 true true 90 150 270 90 90 30 342 | Line -7500403 true 75 135 90 135 343 | Line -7500403 true 75 45 90 45 344 | 345 | flower 346 | false 347 | 0 348 | Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 349 | Circle -7500403 true true 85 132 38 350 | Circle -7500403 true true 130 147 38 351 | Circle -7500403 true true 192 85 38 352 | Circle -7500403 true true 85 40 38 353 | Circle -7500403 true true 177 40 38 354 | Circle -7500403 true true 177 132 38 355 | Circle -7500403 true true 70 85 38 356 | Circle -7500403 true true 130 25 38 357 | Circle -7500403 true true 96 51 108 358 | Circle -16777216 true false 113 68 74 359 | Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 360 | Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 361 | 362 | house 363 | false 364 | 0 365 | Rectangle -7500403 true true 45 120 255 285 366 | Rectangle -16777216 true false 120 210 180 285 367 | Polygon -7500403 true true 15 120 150 15 285 120 368 | Line -16777216 false 30 120 270 120 369 | 370 | leaf 371 | false 372 | 0 373 | Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 374 | Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 375 | 376 | line 377 | true 378 | 0 379 | Line -7500403 true 150 0 150 300 380 | 381 | line half 382 | true 383 | 0 384 | Line -7500403 true 150 0 150 150 385 | 386 | pentagon 387 | false 388 | 0 389 | Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 390 | 391 | person 392 | false 393 | 0 394 | Circle -7500403 true true 110 5 80 395 | Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 396 | Rectangle -7500403 true true 127 79 172 94 397 | Polygon -7500403 true true 195 90 240 150 225 180 165 105 398 | Polygon -7500403 true true 105 90 60 150 75 180 135 105 399 | 400 | plant 401 | false 402 | 0 403 | Rectangle -7500403 true true 135 90 165 300 404 | Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 405 | Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 406 | Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 407 | Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 408 | Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 409 | Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 410 | Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 411 | 412 | sheep 413 | false 414 | 15 415 | Circle -1 true true 203 65 88 416 | Circle -1 true true 70 65 162 417 | Circle -1 true true 150 105 120 418 | Polygon -7500403 true false 218 120 240 165 255 165 278 120 419 | Circle -7500403 true false 214 72 67 420 | Rectangle -1 true true 164 223 179 298 421 | Polygon -1 true true 45 285 30 285 30 240 15 195 45 210 422 | Circle -1 true true 3 83 150 423 | Rectangle -1 true true 65 221 80 296 424 | Polygon -1 true true 195 285 210 285 210 240 240 210 195 210 425 | Polygon -7500403 true false 276 85 285 105 302 99 294 83 426 | Polygon -7500403 true false 219 85 210 105 193 99 201 83 427 | 428 | square 429 | false 430 | 0 431 | Rectangle -7500403 true true 30 30 270 270 432 | 433 | square 2 434 | false 435 | 0 436 | Rectangle -7500403 true true 30 30 270 270 437 | Rectangle -16777216 true false 60 60 240 240 438 | 439 | star 440 | false 441 | 0 442 | Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 443 | 444 | target 445 | false 446 | 0 447 | Circle -7500403 true true 0 0 300 448 | Circle -16777216 true false 30 30 240 449 | Circle -7500403 true true 60 60 180 450 | Circle -16777216 true false 90 90 120 451 | Circle -7500403 true true 120 120 60 452 | 453 | tree 454 | false 455 | 0 456 | Circle -7500403 true true 118 3 94 457 | Rectangle -6459832 true false 120 195 180 300 458 | Circle -7500403 true true 65 21 108 459 | Circle -7500403 true true 116 41 127 460 | Circle -7500403 true true 45 90 120 461 | Circle -7500403 true true 104 74 152 462 | 463 | triangle 464 | false 465 | 0 466 | Polygon -7500403 true true 150 30 15 255 285 255 467 | 468 | triangle 2 469 | false 470 | 0 471 | Polygon -7500403 true true 150 30 15 255 285 255 472 | Polygon -16777216 true false 151 99 225 223 75 224 473 | 474 | truck 475 | false 476 | 0 477 | Rectangle -7500403 true true 4 45 195 187 478 | Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 479 | Rectangle -1 true false 195 60 195 105 480 | Polygon -16777216 true false 238 112 252 141 219 141 218 112 481 | Circle -16777216 true false 234 174 42 482 | Rectangle -7500403 true true 181 185 214 194 483 | Circle -16777216 true false 144 174 42 484 | Circle -16777216 true false 24 174 42 485 | Circle -7500403 false true 24 174 42 486 | Circle -7500403 false true 144 174 42 487 | Circle -7500403 false true 234 174 42 488 | 489 | turtle 490 | true 491 | 0 492 | Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 493 | Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 494 | Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 495 | Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 496 | Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 497 | Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 498 | 499 | wheel 500 | false 501 | 0 502 | Circle -7500403 true true 3 3 294 503 | Circle -16777216 true false 30 30 240 504 | Line -7500403 true 150 285 150 15 505 | Line -7500403 true 15 150 285 150 506 | Circle -7500403 true true 120 120 60 507 | Line -7500403 true 216 40 79 269 508 | Line -7500403 true 40 84 269 221 509 | Line -7500403 true 40 216 269 79 510 | Line -7500403 true 84 40 221 269 511 | 512 | wolf 513 | false 514 | 0 515 | Polygon -16777216 true false 253 133 245 131 245 133 516 | Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105 517 | Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113 518 | 519 | x 520 | false 521 | 0 522 | Polygon -7500403 true true 270 75 225 30 30 225 75 270 523 | Polygon -7500403 true true 30 75 75 30 270 225 225 270 524 | @#$#@#$#@ 525 | NetLogo 6.2.2 526 | @#$#@#$#@ 527 | @#$#@#$#@ 528 | @#$#@#$#@ 529 | @#$#@#$#@ 530 | @#$#@#$#@ 531 | default 532 | 0.0 533 | -0.2 0 0.0 1.0 534 | 0.0 1 1.0 0.0 535 | 0.2 0 0.0 1.0 536 | link direction 537 | true 538 | 0 539 | Line -7500403 true 150 150 90 180 540 | Line -7500403 true 150 150 210 180 541 | @#$#@#$#@ 542 | 0 543 | @#$#@#$#@ 544 | -------------------------------------------------------------------------------- /ch02_particles/particlesflock.nlogo: -------------------------------------------------------------------------------- 1 | globals [ 2 | collisions ;;a global variable to keep track of the total collisions 3 | ] 4 | 5 | 6 | to setup 7 | clear-all ;;clear/reset all variables 8 | ;set-default-shape turtles "circle" ;;make the turtles circles (default is arrows) 9 | set-default-shape turtles "default" 10 | ;;make a bunch of green turtles 11 | create-turtles num-particles [ 12 | set color green 13 | set size 2 14 | setxy random-xcor random-ycor 15 | set heading random 360 ;;give them a random heading 16 | ] 17 | set collisions 0 ;;initialize collisions at zero 18 | reset-ticks ;;set the clock to zero 19 | end 20 | 21 | 22 | 23 | to go 24 | ;;if ticks > 1000 [set flock? true] 25 | ask turtles [ 26 | ;;turn a random amount 27 | if flock? [flock] 28 | 29 | right random whimsy 30 | left random whimsy 31 | forward speed ;;move forward 32 | 33 | ;; if there is at least 1 other turtle near, set new heading 34 | if count turtles in-radius size > 1 [ 35 | ask turtles in-radius size [ 36 | set heading random 360 37 | fd 0.1 38 | ] 39 | set collisions (collisions + 1) 40 | ] 41 | ] 42 | tick 43 | end 44 | 45 | 46 | ;to go 47 | ; ask turtles [ 48 | ; ;;turn a random amount 49 | ; if flock? [flock] 50 | ; move 51 | ; bounce-turtle 52 | ; ] 53 | ; tick 54 | ;end 55 | 56 | 57 | to move 58 | ;;turn a random amount 59 | right random whimsy 60 | left random whimsy 61 | forward speed 62 | end 63 | 64 | 65 | to bounce-turtle 66 | ;; if there is at least 1 other turtle near, set new heading 67 | if count turtles in-radius 1 > 1 [ 68 | ask turtles in-radius 1 [ 69 | set heading random 360 70 | fd .01 71 | ] 72 | set collisions (collisions + 1) 73 | ] 74 | end 75 | 76 | to flock 77 | if any? other turtles in-radius vision-radius [ 78 | let mean-heading (mean [heading] of other turtles in-radius vision-radius) 79 | set heading mean-heading 80 | ] 81 | end 82 | 83 | 84 | ; Copyright 2023 Paul E. Smaldino. 85 | ; See Info tab for full copyright and license. 86 | @#$#@#$#@ 87 | GRAPHICS-WINDOW 88 | 234 89 | 33 90 | 729 91 | 529 92 | -1 93 | -1 94 | 4.822 95 | 1 96 | 10 97 | 1 98 | 1 99 | 1 100 | 0 101 | 1 102 | 1 103 | 1 104 | -50 105 | 50 106 | -50 107 | 50 108 | 0 109 | 0 110 | 1 111 | ticks 112 | 30.0 113 | 114 | BUTTON 115 | 104 116 | 33 117 | 220 118 | 68 119 | NIL 120 | go 121 | T 122 | 1 123 | T 124 | OBSERVER 125 | NIL 126 | NIL 127 | NIL 128 | NIL 129 | 0 130 | 131 | BUTTON 132 | 21 133 | 33 134 | 97 135 | 67 136 | NIL 137 | setup 138 | NIL 139 | 1 140 | T 141 | OBSERVER 142 | NIL 143 | NIL 144 | NIL 145 | NIL 146 | 1 147 | 148 | SLIDER 149 | 21 150 | 80 151 | 220 152 | 113 153 | num-particles 154 | num-particles 155 | 1 156 | 500 157 | 300.0 158 | 1 159 | 1 160 | NIL 161 | HORIZONTAL 162 | 163 | SLIDER 164 | 21 165 | 122 166 | 221 167 | 155 168 | whimsy 169 | whimsy 170 | 0 171 | 180 172 | 10.0 173 | 1 174 | 1 175 | NIL 176 | HORIZONTAL 177 | 178 | SLIDER 179 | 21 180 | 164 181 | 220 182 | 197 183 | speed 184 | speed 185 | .001 186 | .05 187 | 0.03 188 | .001 189 | 1 190 | NIL 191 | HORIZONTAL 192 | 193 | PLOT 194 | 20 195 | 210 196 | 220 197 | 360 198 | collisions 199 | time 200 | # collisions 201 | 0.0 202 | 10.0 203 | 0.0 204 | 10.0 205 | true 206 | false 207 | "" "" 208 | PENS 209 | "default" 1.0 0 -16777216 true "" "plot collisions" 210 | 211 | MONITOR 212 | 20 213 | 368 214 | 220 215 | 413 216 | NIL 217 | collisions 218 | 17 219 | 1 220 | 11 221 | 222 | SLIDER 223 | 26 224 | 419 225 | 198 226 | 452 227 | vision-radius 228 | vision-radius 229 | 0 230 | 10 231 | 5.0 232 | .1 233 | 1 234 | NIL 235 | HORIZONTAL 236 | 237 | SWITCH 238 | 51 239 | 462 240 | 154 241 | 495 242 | flock? 243 | flock? 244 | 0 245 | 1 246 | -1000 247 | 248 | @#$#@#$#@ 249 | ## Model Information and Materials 250 | 251 | This model is original material created by Paul E. Smaldino. 252 | 253 | ## References and Citation 254 | 255 | For this model: 256 | 257 | * Smaldino PE (2023). Particles Flock. Modeling Social Behavior. https://github.com/psmaldino/modsoc/ 258 | 259 | For the book: 260 | 261 | * Smaldino PE (2023). Modeling Social Behavior: Mathematical and Agent-Based Models of Social Dynamics and Cultural Evolution. Princeton University Press. 262 | 263 | For the NetLogo: 264 | 265 | * Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. 266 | 267 | 268 | ## Licence 269 | 270 | ![CC BY-NC-SA 4.0](http://ccl.northwestern.edu/images/creativecommons/byncsa.png) 271 | 272 | This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/ 273 | @#$#@#$#@ 274 | default 275 | true 276 | 0 277 | Polygon -7500403 true true 150 5 40 250 150 205 260 250 278 | 279 | airplane 280 | true 281 | 0 282 | Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 283 | 284 | arrow 285 | true 286 | 0 287 | Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 288 | 289 | box 290 | false 291 | 0 292 | Polygon -7500403 true true 150 285 285 225 285 75 150 135 293 | Polygon -7500403 true true 150 135 15 75 150 15 285 75 294 | Polygon -7500403 true true 15 75 15 225 150 285 150 135 295 | Line -16777216 false 150 285 150 135 296 | Line -16777216 false 150 135 15 75 297 | Line -16777216 false 150 135 285 75 298 | 299 | bug 300 | true 301 | 0 302 | Circle -7500403 true true 96 182 108 303 | Circle -7500403 true true 110 127 80 304 | Circle -7500403 true true 110 75 80 305 | Line -7500403 true 150 100 80 30 306 | Line -7500403 true 150 100 220 30 307 | 308 | butterfly 309 | true 310 | 0 311 | Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 312 | Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 313 | Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 314 | Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 315 | Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 316 | Circle -16777216 true false 135 90 30 317 | Line -16777216 false 150 105 195 60 318 | Line -16777216 false 150 105 105 60 319 | 320 | car 321 | false 322 | 0 323 | Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 324 | Circle -16777216 true false 180 180 90 325 | Circle -16777216 true false 30 180 90 326 | Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 327 | Circle -7500403 true true 47 195 58 328 | Circle -7500403 true true 195 195 58 329 | 330 | circle 331 | false 332 | 0 333 | Circle -7500403 true true 0 0 300 334 | 335 | circle 2 336 | false 337 | 0 338 | Circle -7500403 true true 0 0 300 339 | Circle -16777216 true false 30 30 240 340 | 341 | cow 342 | false 343 | 0 344 | Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 345 | Polygon -7500403 true true 73 210 86 251 62 249 48 208 346 | Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 347 | 348 | cylinder 349 | false 350 | 0 351 | Circle -7500403 true true 0 0 300 352 | 353 | dot 354 | false 355 | 0 356 | Circle -7500403 true true 90 90 120 357 | 358 | face happy 359 | false 360 | 0 361 | Circle -7500403 true true 8 8 285 362 | Circle -16777216 true false 60 75 60 363 | Circle -16777216 true false 180 75 60 364 | Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 365 | 366 | face neutral 367 | false 368 | 0 369 | Circle -7500403 true true 8 7 285 370 | Circle -16777216 true false 60 75 60 371 | Circle -16777216 true false 180 75 60 372 | Rectangle -16777216 true false 60 195 240 225 373 | 374 | face sad 375 | false 376 | 0 377 | Circle -7500403 true true 8 8 285 378 | Circle -16777216 true false 60 75 60 379 | Circle -16777216 true false 180 75 60 380 | Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 381 | 382 | fish 383 | false 384 | 0 385 | Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 386 | Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 387 | Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 388 | Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 389 | Circle -16777216 true false 215 106 30 390 | 391 | flag 392 | false 393 | 0 394 | Rectangle -7500403 true true 60 15 75 300 395 | Polygon -7500403 true true 90 150 270 90 90 30 396 | Line -7500403 true 75 135 90 135 397 | Line -7500403 true 75 45 90 45 398 | 399 | flower 400 | false 401 | 0 402 | Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 403 | Circle -7500403 true true 85 132 38 404 | Circle -7500403 true true 130 147 38 405 | Circle -7500403 true true 192 85 38 406 | Circle -7500403 true true 85 40 38 407 | Circle -7500403 true true 177 40 38 408 | Circle -7500403 true true 177 132 38 409 | Circle -7500403 true true 70 85 38 410 | Circle -7500403 true true 130 25 38 411 | Circle -7500403 true true 96 51 108 412 | Circle -16777216 true false 113 68 74 413 | Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 414 | Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 415 | 416 | house 417 | false 418 | 0 419 | Rectangle -7500403 true true 45 120 255 285 420 | Rectangle -16777216 true false 120 210 180 285 421 | Polygon -7500403 true true 15 120 150 15 285 120 422 | Line -16777216 false 30 120 270 120 423 | 424 | leaf 425 | false 426 | 0 427 | Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 428 | Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 429 | 430 | line 431 | true 432 | 0 433 | Line -7500403 true 150 0 150 300 434 | 435 | line half 436 | true 437 | 0 438 | Line -7500403 true 150 0 150 150 439 | 440 | pentagon 441 | false 442 | 0 443 | Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 444 | 445 | person 446 | false 447 | 0 448 | Circle -7500403 true true 110 5 80 449 | Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 450 | Rectangle -7500403 true true 127 79 172 94 451 | Polygon -7500403 true true 195 90 240 150 225 180 165 105 452 | Polygon -7500403 true true 105 90 60 150 75 180 135 105 453 | 454 | plant 455 | false 456 | 0 457 | Rectangle -7500403 true true 135 90 165 300 458 | Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 459 | Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 460 | Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 461 | Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 462 | Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 463 | Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 464 | Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 465 | 466 | sheep 467 | false 468 | 15 469 | Circle -1 true true 203 65 88 470 | Circle -1 true true 70 65 162 471 | Circle -1 true true 150 105 120 472 | Polygon -7500403 true false 218 120 240 165 255 165 278 120 473 | Circle -7500403 true false 214 72 67 474 | Rectangle -1 true true 164 223 179 298 475 | Polygon -1 true true 45 285 30 285 30 240 15 195 45 210 476 | Circle -1 true true 3 83 150 477 | Rectangle -1 true true 65 221 80 296 478 | Polygon -1 true true 195 285 210 285 210 240 240 210 195 210 479 | Polygon -7500403 true false 276 85 285 105 302 99 294 83 480 | Polygon -7500403 true false 219 85 210 105 193 99 201 83 481 | 482 | square 483 | false 484 | 0 485 | Rectangle -7500403 true true 30 30 270 270 486 | 487 | square 2 488 | false 489 | 0 490 | Rectangle -7500403 true true 30 30 270 270 491 | Rectangle -16777216 true false 60 60 240 240 492 | 493 | star 494 | false 495 | 0 496 | Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 497 | 498 | target 499 | false 500 | 0 501 | Circle -7500403 true true 0 0 300 502 | Circle -16777216 true false 30 30 240 503 | Circle -7500403 true true 60 60 180 504 | Circle -16777216 true false 90 90 120 505 | Circle -7500403 true true 120 120 60 506 | 507 | tree 508 | false 509 | 0 510 | Circle -7500403 true true 118 3 94 511 | Rectangle -6459832 true false 120 195 180 300 512 | Circle -7500403 true true 65 21 108 513 | Circle -7500403 true true 116 41 127 514 | Circle -7500403 true true 45 90 120 515 | Circle -7500403 true true 104 74 152 516 | 517 | triangle 518 | false 519 | 0 520 | Polygon -7500403 true true 150 30 15 255 285 255 521 | 522 | triangle 2 523 | false 524 | 0 525 | Polygon -7500403 true true 150 30 15 255 285 255 526 | Polygon -16777216 true false 151 99 225 223 75 224 527 | 528 | truck 529 | false 530 | 0 531 | Rectangle -7500403 true true 4 45 195 187 532 | Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 533 | Rectangle -1 true false 195 60 195 105 534 | Polygon -16777216 true false 238 112 252 141 219 141 218 112 535 | Circle -16777216 true false 234 174 42 536 | Rectangle -7500403 true true 181 185 214 194 537 | Circle -16777216 true false 144 174 42 538 | Circle -16777216 true false 24 174 42 539 | Circle -7500403 false true 24 174 42 540 | Circle -7500403 false true 144 174 42 541 | Circle -7500403 false true 234 174 42 542 | 543 | turtle 544 | true 545 | 0 546 | Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 547 | Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 548 | Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 549 | Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 550 | Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 551 | Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 552 | 553 | wheel 554 | false 555 | 0 556 | Circle -7500403 true true 3 3 294 557 | Circle -16777216 true false 30 30 240 558 | Line -7500403 true 150 285 150 15 559 | Line -7500403 true 15 150 285 150 560 | Circle -7500403 true true 120 120 60 561 | Line -7500403 true 216 40 79 269 562 | Line -7500403 true 40 84 269 221 563 | Line -7500403 true 40 216 269 79 564 | Line -7500403 true 84 40 221 269 565 | 566 | wolf 567 | false 568 | 0 569 | Polygon -16777216 true false 253 133 245 131 245 133 570 | Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105 571 | Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113 572 | 573 | x 574 | false 575 | 0 576 | Polygon -7500403 true true 270 75 225 30 30 225 75 270 577 | Polygon -7500403 true true 30 75 75 30 270 225 225 270 578 | @#$#@#$#@ 579 | NetLogo 6.2.2 580 | @#$#@#$#@ 581 | @#$#@#$#@ 582 | @#$#@#$#@ 583 | @#$#@#$#@ 584 | @#$#@#$#@ 585 | default 586 | 0.0 587 | -0.2 0 0.0 1.0 588 | 0.0 1 1.0 0.0 589 | 0.2 0 0.0 1.0 590 | link direction 591 | true 592 | 0 593 | Line -7500403 true 150 150 90 180 594 | Line -7500403 true 150 150 210 180 595 | @#$#@#$#@ 596 | 0 597 | @#$#@#$#@ 598 | -------------------------------------------------------------------------------- /ch04_contagion/Contagion_SI.nlogo: -------------------------------------------------------------------------------- 1 | ;;A simple model of adoption/contagion. Agents move around at random. 2 | ;;They adopt a behavior either with a fixed probability or by social influence 3 | 4 | turtles-own [ 5 | infected? 6 | ] 7 | 8 | 9 | ;;--SETUP PROCEDURES------------------ 10 | 11 | to setup 12 | clear-all 13 | setup-turtles 14 | setup-infected 15 | recolor 16 | reset-ticks 17 | end 18 | 19 | ;;create the agents 20 | to setup-turtles 21 | create-turtles num-turtles [ 22 | set shape "circle" 23 | set infected? false ;;default to uninfected 24 | setxy random-xcor random-ycor ;;give random location 25 | ] 26 | end 27 | 28 | ;;infect a small number of randomly-selected agents 29 | to setup-infected 30 | if init-infected > num-turtles ;;can't infect more agents than exist 31 | [set init-infected 1] 32 | ask n-of init-infected turtles [ 33 | set infected? true 34 | ] 35 | end 36 | 37 | ;;update agents' color based on infection status. 38 | ;;red = infected, white = uninfected 39 | to recolor 40 | ask turtles [ 41 | ifelse infected? 42 | [set color red] 43 | [set color white] 44 | ] 45 | end 46 | 47 | 48 | 49 | ;;--DYNAMICS PROCEDURES------------------ 50 | 51 | to go 52 | ;;stop the simulation if everyone is infected 53 | if (count turtles with [infected?]) = num-turtles [ stop ] 54 | infect-susceptibles ;; S -> I 55 | recolor 56 | move 57 | tick 58 | end 59 | 60 | ;;infected agents with probability dependent on transmissibility, number of infected neighbors, and 61 | ;;the probability of spontaneous adoption. 62 | to infect-susceptibles ;; S -> I 63 | ask turtles with [not infected?] [ 64 | let infected-neighbors (count other turtles with [color = red] in-radius 1) 65 | if random-float 1 < 1 - (((1 - transmissibility) ^ infected-neighbors) * (1 - spontaneous-infect)) 66 | [set infected? true] 67 | ] 68 | end 69 | 70 | ;;execute a random walk 71 | to move 72 | ask turtles [ ;;move 73 | left random turning-angle 74 | right random turning-angle 75 | fd speed 76 | ] 77 | end 78 | 79 | ; Copyright 2023 Paul E. Smaldino. 80 | ; See Info tab for full copyright and license. 81 | @#$#@#$#@ 82 | GRAPHICS-WINDOW 83 | 221 84 | 18 85 | 526 86 | 324 87 | -1 88 | -1 89 | 9.0 90 | 1 91 | 10 92 | 1 93 | 1 94 | 1 95 | 0 96 | 1 97 | 1 98 | 1 99 | -16 100 | 16 101 | -16 102 | 16 103 | 0 104 | 0 105 | 1 106 | ticks 107 | 30.0 108 | 109 | BUTTON 110 | 33 111 | 44 112 | 118 113 | 77 114 | NIL 115 | setup 116 | NIL 117 | 1 118 | T 119 | OBSERVER 120 | NIL 121 | NIL 122 | NIL 123 | NIL 124 | 1 125 | 126 | BUTTON 127 | 123 128 | 44 129 | 206 130 | 77 131 | NIL 132 | go 133 | T 134 | 1 135 | T 136 | OBSERVER 137 | NIL 138 | NIL 139 | NIL 140 | NIL 141 | 1 142 | 143 | SLIDER 144 | 34 145 | 86 146 | 206 147 | 119 148 | num-turtles 149 | num-turtles 150 | 1 151 | 1000 152 | 300.0 153 | 1 154 | 1 155 | NIL 156 | HORIZONTAL 157 | 158 | SLIDER 159 | 35 160 | 170 161 | 207 162 | 203 163 | speed 164 | speed 165 | 0.1 166 | 2 167 | 0.5 168 | .1 169 | 1 170 | NIL 171 | HORIZONTAL 172 | 173 | SLIDER 174 | 36 175 | 129 176 | 208 177 | 162 178 | init-infected 179 | init-infected 180 | 1 181 | 10 182 | 3.0 183 | 1 184 | 1 185 | NIL 186 | HORIZONTAL 187 | 188 | SLIDER 189 | 36 190 | 290 191 | 208 192 | 323 193 | transmissibility 194 | transmissibility 195 | 0 196 | 1 197 | 0.01 198 | .01 199 | 1 200 | NIL 201 | HORIZONTAL 202 | 203 | PLOT 204 | 534 205 | 19 206 | 871 207 | 321 208 | Infection rate 209 | time 210 | Proportion infected 211 | 0.0 212 | 10.0 213 | 0.0 214 | 1.0 215 | true 216 | false 217 | "" "" 218 | PENS 219 | "infected" 1.0 0 -2674135 true "" "plot (count turtles with [infected?]) / num-turtles" 220 | 221 | SLIDER 222 | 35 223 | 211 224 | 207 225 | 244 226 | turning-angle 227 | turning-angle 228 | 0 229 | 360 230 | 60.0 231 | 1 232 | 1 233 | NIL 234 | HORIZONTAL 235 | 236 | SLIDER 237 | 35 238 | 251 239 | 208 240 | 284 241 | spontaneous-infect 242 | spontaneous-infect 243 | 0 244 | 1 245 | 0.0 246 | .01 247 | 1 248 | NIL 249 | HORIZONTAL 250 | 251 | @#$#@#$#@ 252 | ## Model Information and Materials 253 | 254 | This model is original material created by Paul E. Smaldino. 255 | 256 | ## References and Citation 257 | 258 | For this model: 259 | 260 | * Smaldino PE (2023). Contagion: SI. Modeling Social Behavior. https://github.com/psmaldino/modsoc/ 261 | 262 | For the book: 263 | 264 | * Smaldino PE (2023). Modeling Social Behavior: Mathematical and Agent-Based Models of Social Dynamics and Cultural Evolution. Princeton University Press. 265 | 266 | For the NetLogo: 267 | 268 | * Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. 269 | 270 | 271 | ## Licence 272 | 273 | ![CC BY-NC-SA 4.0](http://ccl.northwestern.edu/images/creativecommons/byncsa.png) 274 | 275 | This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/ 276 | @#$#@#$#@ 277 | default 278 | true 279 | 0 280 | Polygon -7500403 true true 150 5 40 250 150 205 260 250 281 | 282 | airplane 283 | true 284 | 0 285 | Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 286 | 287 | arrow 288 | true 289 | 0 290 | Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 291 | 292 | box 293 | false 294 | 0 295 | Polygon -7500403 true true 150 285 285 225 285 75 150 135 296 | Polygon -7500403 true true 150 135 15 75 150 15 285 75 297 | Polygon -7500403 true true 15 75 15 225 150 285 150 135 298 | Line -16777216 false 150 285 150 135 299 | Line -16777216 false 150 135 15 75 300 | Line -16777216 false 150 135 285 75 301 | 302 | bug 303 | true 304 | 0 305 | Circle -7500403 true true 96 182 108 306 | Circle -7500403 true true 110 127 80 307 | Circle -7500403 true true 110 75 80 308 | Line -7500403 true 150 100 80 30 309 | Line -7500403 true 150 100 220 30 310 | 311 | butterfly 312 | true 313 | 0 314 | Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 315 | Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 316 | Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 317 | Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 318 | Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 319 | Circle -16777216 true false 135 90 30 320 | Line -16777216 false 150 105 195 60 321 | Line -16777216 false 150 105 105 60 322 | 323 | car 324 | false 325 | 0 326 | Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 327 | Circle -16777216 true false 180 180 90 328 | Circle -16777216 true false 30 180 90 329 | Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 330 | Circle -7500403 true true 47 195 58 331 | Circle -7500403 true true 195 195 58 332 | 333 | circle 334 | false 335 | 0 336 | Circle -7500403 true true 0 0 300 337 | 338 | circle 2 339 | false 340 | 0 341 | Circle -7500403 true true 0 0 300 342 | Circle -16777216 true false 30 30 240 343 | 344 | cow 345 | false 346 | 0 347 | Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 348 | Polygon -7500403 true true 73 210 86 251 62 249 48 208 349 | Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 350 | 351 | cylinder 352 | false 353 | 0 354 | Circle -7500403 true true 0 0 300 355 | 356 | dot 357 | false 358 | 0 359 | Circle -7500403 true true 90 90 120 360 | 361 | face happy 362 | false 363 | 0 364 | Circle -7500403 true true 8 8 285 365 | Circle -16777216 true false 60 75 60 366 | Circle -16777216 true false 180 75 60 367 | Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 368 | 369 | face neutral 370 | false 371 | 0 372 | Circle -7500403 true true 8 7 285 373 | Circle -16777216 true false 60 75 60 374 | Circle -16777216 true false 180 75 60 375 | Rectangle -16777216 true false 60 195 240 225 376 | 377 | face sad 378 | false 379 | 0 380 | Circle -7500403 true true 8 8 285 381 | Circle -16777216 true false 60 75 60 382 | Circle -16777216 true false 180 75 60 383 | Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 384 | 385 | fish 386 | false 387 | 0 388 | Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 389 | Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 390 | Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 391 | Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 392 | Circle -16777216 true false 215 106 30 393 | 394 | flag 395 | false 396 | 0 397 | Rectangle -7500403 true true 60 15 75 300 398 | Polygon -7500403 true true 90 150 270 90 90 30 399 | Line -7500403 true 75 135 90 135 400 | Line -7500403 true 75 45 90 45 401 | 402 | flower 403 | false 404 | 0 405 | Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 406 | Circle -7500403 true true 85 132 38 407 | Circle -7500403 true true 130 147 38 408 | Circle -7500403 true true 192 85 38 409 | Circle -7500403 true true 85 40 38 410 | Circle -7500403 true true 177 40 38 411 | Circle -7500403 true true 177 132 38 412 | Circle -7500403 true true 70 85 38 413 | Circle -7500403 true true 130 25 38 414 | Circle -7500403 true true 96 51 108 415 | Circle -16777216 true false 113 68 74 416 | Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 417 | Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 418 | 419 | house 420 | false 421 | 0 422 | Rectangle -7500403 true true 45 120 255 285 423 | Rectangle -16777216 true false 120 210 180 285 424 | Polygon -7500403 true true 15 120 150 15 285 120 425 | Line -16777216 false 30 120 270 120 426 | 427 | leaf 428 | false 429 | 0 430 | Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 431 | Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 432 | 433 | line 434 | true 435 | 0 436 | Line -7500403 true 150 0 150 300 437 | 438 | line half 439 | true 440 | 0 441 | Line -7500403 true 150 0 150 150 442 | 443 | pentagon 444 | false 445 | 0 446 | Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 447 | 448 | person 449 | false 450 | 0 451 | Circle -7500403 true true 110 5 80 452 | Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 453 | Rectangle -7500403 true true 127 79 172 94 454 | Polygon -7500403 true true 195 90 240 150 225 180 165 105 455 | Polygon -7500403 true true 105 90 60 150 75 180 135 105 456 | 457 | plant 458 | false 459 | 0 460 | Rectangle -7500403 true true 135 90 165 300 461 | Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 462 | Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 463 | Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 464 | Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 465 | Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 466 | Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 467 | Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 468 | 469 | sheep 470 | false 471 | 15 472 | Circle -1 true true 203 65 88 473 | Circle -1 true true 70 65 162 474 | Circle -1 true true 150 105 120 475 | Polygon -7500403 true false 218 120 240 165 255 165 278 120 476 | Circle -7500403 true false 214 72 67 477 | Rectangle -1 true true 164 223 179 298 478 | Polygon -1 true true 45 285 30 285 30 240 15 195 45 210 479 | Circle -1 true true 3 83 150 480 | Rectangle -1 true true 65 221 80 296 481 | Polygon -1 true true 195 285 210 285 210 240 240 210 195 210 482 | Polygon -7500403 true false 276 85 285 105 302 99 294 83 483 | Polygon -7500403 true false 219 85 210 105 193 99 201 83 484 | 485 | square 486 | false 487 | 0 488 | Rectangle -7500403 true true 30 30 270 270 489 | 490 | square 2 491 | false 492 | 0 493 | Rectangle -7500403 true true 30 30 270 270 494 | Rectangle -16777216 true false 60 60 240 240 495 | 496 | star 497 | false 498 | 0 499 | Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 500 | 501 | target 502 | false 503 | 0 504 | Circle -7500403 true true 0 0 300 505 | Circle -16777216 true false 30 30 240 506 | Circle -7500403 true true 60 60 180 507 | Circle -16777216 true false 90 90 120 508 | Circle -7500403 true true 120 120 60 509 | 510 | tree 511 | false 512 | 0 513 | Circle -7500403 true true 118 3 94 514 | Rectangle -6459832 true false 120 195 180 300 515 | Circle -7500403 true true 65 21 108 516 | Circle -7500403 true true 116 41 127 517 | Circle -7500403 true true 45 90 120 518 | Circle -7500403 true true 104 74 152 519 | 520 | triangle 521 | false 522 | 0 523 | Polygon -7500403 true true 150 30 15 255 285 255 524 | 525 | triangle 2 526 | false 527 | 0 528 | Polygon -7500403 true true 150 30 15 255 285 255 529 | Polygon -16777216 true false 151 99 225 223 75 224 530 | 531 | truck 532 | false 533 | 0 534 | Rectangle -7500403 true true 4 45 195 187 535 | Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 536 | Rectangle -1 true false 195 60 195 105 537 | Polygon -16777216 true false 238 112 252 141 219 141 218 112 538 | Circle -16777216 true false 234 174 42 539 | Rectangle -7500403 true true 181 185 214 194 540 | Circle -16777216 true false 144 174 42 541 | Circle -16777216 true false 24 174 42 542 | Circle -7500403 false true 24 174 42 543 | Circle -7500403 false true 144 174 42 544 | Circle -7500403 false true 234 174 42 545 | 546 | turtle 547 | true 548 | 0 549 | Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 550 | Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 551 | Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 552 | Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 553 | Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 554 | Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 555 | 556 | wheel 557 | false 558 | 0 559 | Circle -7500403 true true 3 3 294 560 | Circle -16777216 true false 30 30 240 561 | Line -7500403 true 150 285 150 15 562 | Line -7500403 true 15 150 285 150 563 | Circle -7500403 true true 120 120 60 564 | Line -7500403 true 216 40 79 269 565 | Line -7500403 true 40 84 269 221 566 | Line -7500403 true 40 216 269 79 567 | Line -7500403 true 84 40 221 269 568 | 569 | wolf 570 | false 571 | 0 572 | Polygon -16777216 true false 253 133 245 131 245 133 573 | Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105 574 | Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113 575 | 576 | x 577 | false 578 | 0 579 | Polygon -7500403 true true 270 75 225 30 30 225 75 270 580 | Polygon -7500403 true true 30 75 75 30 270 225 225 270 581 | @#$#@#$#@ 582 | NetLogo 6.2.2 583 | @#$#@#$#@ 584 | @#$#@#$#@ 585 | @#$#@#$#@ 586 | @#$#@#$#@ 587 | @#$#@#$#@ 588 | default 589 | 0.0 590 | -0.2 0 0.0 1.0 591 | 0.0 1 1.0 0.0 592 | 0.2 0 0.0 1.0 593 | link direction 594 | true 595 | 0 596 | Line -7500403 true 150 150 90 180 597 | Line -7500403 true 150 150 210 180 598 | @#$#@#$#@ 599 | 0 600 | @#$#@#$#@ 601 | -------------------------------------------------------------------------------- /ch02_particles/particles.nlogo: -------------------------------------------------------------------------------- 1 | globals [ 2 | collisions ;;a global variable to keep track of the total collisions 3 | ] 4 | 5 | 6 | to setup 7 | clear-all ;;clear/reset all variables 8 | set-default-shape turtles "default" ;;make the turtles arrows (not strictly necessary as this is default) 9 | ;set-default-shape turtles "circle" ;;make the turtles circles (default is arrows) 10 | ;;make a bunch of green turtles 11 | create-turtles num-particles [ 12 | set color green 13 | set size 2 ;;if default shape, make them easier to see 14 | setxy random-xcor random-ycor 15 | set heading random 360 ;;give them a random heading (not strictly necessary as this is default) 16 | ] 17 | set collisions 0 ;;initialize collisions at zero 18 | reset-ticks ;;set the clock to zero 19 | end 20 | 21 | 22 | to go 23 | ask turtles [ 24 | ;;turn a random amount 25 | right random whimsy 26 | left random whimsy 27 | forward speed ;;move forward 28 | 29 | ;; if there is at least 1 other turtle near, set new heading 30 | if count turtles in-radius 1 > 1 [ 31 | ask turtles in-radius 1 [ 32 | set heading random 360 33 | fd 0.1 34 | ] 35 | set collisions (collisions + 1) 36 | ] 37 | ] 38 | tick 39 | end 40 | 41 | 42 | ;to go 43 | ; ask turtles [ 44 | ; ;;turn a random amount 45 | ; move 46 | ; bounce-turtle 47 | ; ] 48 | ; tick 49 | ;end 50 | 51 | 52 | to move 53 | ;;turn a random amount 54 | right random whimsy 55 | left random whimsy 56 | forward speed 57 | end 58 | 59 | 60 | to bounce-turtle 61 | ;; if there is at least 1 other turtle near, set new heading 62 | if count turtles in-radius size > 1 [ 63 | ask turtles in-radius size [ 64 | set heading random 360 65 | fd 0.1 66 | ] 67 | set collisions (collisions + 1) 68 | ] 69 | end 70 | 71 | ; Copyright 2023 Paul E. Smaldino. 72 | ; See Info tab for full copyright and license. 73 | @#$#@#$#@ 74 | GRAPHICS-WINDOW 75 | 229 76 | 10 77 | 724 78 | 506 79 | -1 80 | -1 81 | 4.822 82 | 1 83 | 10 84 | 1 85 | 1 86 | 1 87 | 0 88 | 1 89 | 1 90 | 1 91 | -50 92 | 50 93 | -50 94 | 50 95 | 0 96 | 0 97 | 1 98 | ticks 99 | 30.0 100 | 101 | BUTTON 102 | 99 103 | 10 104 | 215 105 | 45 106 | NIL 107 | go 108 | T 109 | 1 110 | T 111 | OBSERVER 112 | NIL 113 | NIL 114 | NIL 115 | NIL 116 | 0 117 | 118 | BUTTON 119 | 16 120 | 10 121 | 92 122 | 44 123 | NIL 124 | setup 125 | NIL 126 | 1 127 | T 128 | OBSERVER 129 | NIL 130 | NIL 131 | NIL 132 | NIL 133 | 1 134 | 135 | SLIDER 136 | 16 137 | 57 138 | 215 139 | 90 140 | num-particles 141 | num-particles 142 | 1 143 | 500 144 | 50.0 145 | 1 146 | 1 147 | NIL 148 | HORIZONTAL 149 | 150 | SLIDER 151 | 16 152 | 96 153 | 215 154 | 129 155 | whimsy 156 | whimsy 157 | 0 158 | 180 159 | 0.0 160 | 1 161 | 1 162 | NIL 163 | HORIZONTAL 164 | 165 | SLIDER 166 | 16 167 | 136 168 | 215 169 | 169 170 | speed 171 | speed 172 | .001 173 | .05 174 | 0.02 175 | .001 176 | 1 177 | NIL 178 | HORIZONTAL 179 | 180 | PLOT 181 | 15 182 | 187 183 | 215 184 | 337 185 | collisions 186 | time 187 | # collisions 188 | 0.0 189 | 10.0 190 | 0.0 191 | 10.0 192 | true 193 | false 194 | "" "" 195 | PENS 196 | "default" 1.0 0 -16777216 true "" "plot collisions" 197 | 198 | MONITOR 199 | 15 200 | 345 201 | 215 202 | 390 203 | NIL 204 | collisions 205 | 17 206 | 1 207 | 11 208 | 209 | @#$#@#$#@ 210 | ## Model Information and Materials 211 | 212 | This model is original material created by Paul E. Smaldino. 213 | 214 | ## References and Citation 215 | 216 | For this model: 217 | 218 | * Smaldino PE (2023). Particles. Modeling Social Behavior. https://github.com/psmaldino/modsoc/ 219 | 220 | For the book: 221 | 222 | * Smaldino PE (2023). Modeling Social Behavior: Mathematical and Agent-Based Models of Social Dynamics and Cultural Evolution. Princeton University Press. 223 | 224 | For the NetLogo: 225 | 226 | * Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. 227 | 228 | 229 | ## Licence 230 | 231 | ![CC BY-NC-SA 4.0](http://ccl.northwestern.edu/images/creativecommons/byncsa.png) 232 | 233 | This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/ 234 | @#$#@#$#@ 235 | default 236 | true 237 | 0 238 | Polygon -7500403 true true 150 5 40 250 150 205 260 250 239 | 240 | airplane 241 | true 242 | 0 243 | Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 244 | 245 | arrow 246 | true 247 | 0 248 | Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 249 | 250 | box 251 | false 252 | 0 253 | Polygon -7500403 true true 150 285 285 225 285 75 150 135 254 | Polygon -7500403 true true 150 135 15 75 150 15 285 75 255 | Polygon -7500403 true true 15 75 15 225 150 285 150 135 256 | Line -16777216 false 150 285 150 135 257 | Line -16777216 false 150 135 15 75 258 | Line -16777216 false 150 135 285 75 259 | 260 | bug 261 | true 262 | 0 263 | Circle -7500403 true true 96 182 108 264 | Circle -7500403 true true 110 127 80 265 | Circle -7500403 true true 110 75 80 266 | Line -7500403 true 150 100 80 30 267 | Line -7500403 true 150 100 220 30 268 | 269 | butterfly 270 | true 271 | 0 272 | Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 273 | Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 274 | Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 275 | Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 276 | Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 277 | Circle -16777216 true false 135 90 30 278 | Line -16777216 false 150 105 195 60 279 | Line -16777216 false 150 105 105 60 280 | 281 | car 282 | false 283 | 0 284 | Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 285 | Circle -16777216 true false 180 180 90 286 | Circle -16777216 true false 30 180 90 287 | Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 288 | Circle -7500403 true true 47 195 58 289 | Circle -7500403 true true 195 195 58 290 | 291 | circle 292 | false 293 | 0 294 | Circle -7500403 true true 0 0 300 295 | 296 | circle 2 297 | false 298 | 0 299 | Circle -7500403 true true 0 0 300 300 | Circle -16777216 true false 30 30 240 301 | 302 | cow 303 | false 304 | 0 305 | Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 306 | Polygon -7500403 true true 73 210 86 251 62 249 48 208 307 | Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 308 | 309 | cylinder 310 | false 311 | 0 312 | Circle -7500403 true true 0 0 300 313 | 314 | dot 315 | false 316 | 0 317 | Circle -7500403 true true 90 90 120 318 | 319 | face happy 320 | false 321 | 0 322 | Circle -7500403 true true 8 8 285 323 | Circle -16777216 true false 60 75 60 324 | Circle -16777216 true false 180 75 60 325 | Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 326 | 327 | face neutral 328 | false 329 | 0 330 | Circle -7500403 true true 8 7 285 331 | Circle -16777216 true false 60 75 60 332 | Circle -16777216 true false 180 75 60 333 | Rectangle -16777216 true false 60 195 240 225 334 | 335 | face sad 336 | false 337 | 0 338 | Circle -7500403 true true 8 8 285 339 | Circle -16777216 true false 60 75 60 340 | Circle -16777216 true false 180 75 60 341 | Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 342 | 343 | fish 344 | false 345 | 0 346 | Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 347 | Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 348 | Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 349 | Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 350 | Circle -16777216 true false 215 106 30 351 | 352 | flag 353 | false 354 | 0 355 | Rectangle -7500403 true true 60 15 75 300 356 | Polygon -7500403 true true 90 150 270 90 90 30 357 | Line -7500403 true 75 135 90 135 358 | Line -7500403 true 75 45 90 45 359 | 360 | flower 361 | false 362 | 0 363 | Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 364 | Circle -7500403 true true 85 132 38 365 | Circle -7500403 true true 130 147 38 366 | Circle -7500403 true true 192 85 38 367 | Circle -7500403 true true 85 40 38 368 | Circle -7500403 true true 177 40 38 369 | Circle -7500403 true true 177 132 38 370 | Circle -7500403 true true 70 85 38 371 | Circle -7500403 true true 130 25 38 372 | Circle -7500403 true true 96 51 108 373 | Circle -16777216 true false 113 68 74 374 | Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 375 | Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 376 | 377 | house 378 | false 379 | 0 380 | Rectangle -7500403 true true 45 120 255 285 381 | Rectangle -16777216 true false 120 210 180 285 382 | Polygon -7500403 true true 15 120 150 15 285 120 383 | Line -16777216 false 30 120 270 120 384 | 385 | leaf 386 | false 387 | 0 388 | Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 389 | Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 390 | 391 | line 392 | true 393 | 0 394 | Line -7500403 true 150 0 150 300 395 | 396 | line half 397 | true 398 | 0 399 | Line -7500403 true 150 0 150 150 400 | 401 | pentagon 402 | false 403 | 0 404 | Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 405 | 406 | person 407 | false 408 | 0 409 | Circle -7500403 true true 110 5 80 410 | Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 411 | Rectangle -7500403 true true 127 79 172 94 412 | Polygon -7500403 true true 195 90 240 150 225 180 165 105 413 | Polygon -7500403 true true 105 90 60 150 75 180 135 105 414 | 415 | plant 416 | false 417 | 0 418 | Rectangle -7500403 true true 135 90 165 300 419 | Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 420 | Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 421 | Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 422 | Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 423 | Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 424 | Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 425 | Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 426 | 427 | sheep 428 | false 429 | 15 430 | Circle -1 true true 203 65 88 431 | Circle -1 true true 70 65 162 432 | Circle -1 true true 150 105 120 433 | Polygon -7500403 true false 218 120 240 165 255 165 278 120 434 | Circle -7500403 true false 214 72 67 435 | Rectangle -1 true true 164 223 179 298 436 | Polygon -1 true true 45 285 30 285 30 240 15 195 45 210 437 | Circle -1 true true 3 83 150 438 | Rectangle -1 true true 65 221 80 296 439 | Polygon -1 true true 195 285 210 285 210 240 240 210 195 210 440 | Polygon -7500403 true false 276 85 285 105 302 99 294 83 441 | Polygon -7500403 true false 219 85 210 105 193 99 201 83 442 | 443 | square 444 | false 445 | 0 446 | Rectangle -7500403 true true 30 30 270 270 447 | 448 | square 2 449 | false 450 | 0 451 | Rectangle -7500403 true true 30 30 270 270 452 | Rectangle -16777216 true false 60 60 240 240 453 | 454 | star 455 | false 456 | 0 457 | Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 458 | 459 | target 460 | false 461 | 0 462 | Circle -7500403 true true 0 0 300 463 | Circle -16777216 true false 30 30 240 464 | Circle -7500403 true true 60 60 180 465 | Circle -16777216 true false 90 90 120 466 | Circle -7500403 true true 120 120 60 467 | 468 | tree 469 | false 470 | 0 471 | Circle -7500403 true true 118 3 94 472 | Rectangle -6459832 true false 120 195 180 300 473 | Circle -7500403 true true 65 21 108 474 | Circle -7500403 true true 116 41 127 475 | Circle -7500403 true true 45 90 120 476 | Circle -7500403 true true 104 74 152 477 | 478 | triangle 479 | false 480 | 0 481 | Polygon -7500403 true true 150 30 15 255 285 255 482 | 483 | triangle 2 484 | false 485 | 0 486 | Polygon -7500403 true true 150 30 15 255 285 255 487 | Polygon -16777216 true false 151 99 225 223 75 224 488 | 489 | truck 490 | false 491 | 0 492 | Rectangle -7500403 true true 4 45 195 187 493 | Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 494 | Rectangle -1 true false 195 60 195 105 495 | Polygon -16777216 true false 238 112 252 141 219 141 218 112 496 | Circle -16777216 true false 234 174 42 497 | Rectangle -7500403 true true 181 185 214 194 498 | Circle -16777216 true false 144 174 42 499 | Circle -16777216 true false 24 174 42 500 | Circle -7500403 false true 24 174 42 501 | Circle -7500403 false true 144 174 42 502 | Circle -7500403 false true 234 174 42 503 | 504 | turtle 505 | true 506 | 0 507 | Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 508 | Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 509 | Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 510 | Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 511 | Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 512 | Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 513 | 514 | wheel 515 | false 516 | 0 517 | Circle -7500403 true true 3 3 294 518 | Circle -16777216 true false 30 30 240 519 | Line -7500403 true 150 285 150 15 520 | Line -7500403 true 15 150 285 150 521 | Circle -7500403 true true 120 120 60 522 | Line -7500403 true 216 40 79 269 523 | Line -7500403 true 40 84 269 221 524 | Line -7500403 true 40 216 269 79 525 | Line -7500403 true 84 40 221 269 526 | 527 | wolf 528 | false 529 | 0 530 | Polygon -16777216 true false 253 133 245 131 245 133 531 | Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105 532 | Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113 533 | 534 | x 535 | false 536 | 0 537 | Polygon -7500403 true true 270 75 225 30 30 225 75 270 538 | Polygon -7500403 true true 30 75 75 30 270 225 225 270 539 | @#$#@#$#@ 540 | NetLogo 6.2.2 541 | @#$#@#$#@ 542 | @#$#@#$#@ 543 | @#$#@#$#@ 544 | 545 | 546 | setup 547 | go 548 | 549 | count turtles 550 | collisions 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | @#$#@#$#@ 565 | @#$#@#$#@ 566 | default 567 | 0.0 568 | -0.2 0 0.0 1.0 569 | 0.0 1 1.0 0.0 570 | 0.2 0 0.0 1.0 571 | link direction 572 | true 573 | 0 574 | Line -7500403 true 150 150 90 180 575 | Line -7500403 true 150 150 210 180 576 | @#$#@#$#@ 577 | 0 578 | @#$#@#$#@ 579 | -------------------------------------------------------------------------------- /ch05_opinions/opiniondynamics_BC.nlogo: -------------------------------------------------------------------------------- 1 | 2 | turtles-own [opinion] 3 | 4 | ;;create one turle on each patch, give each a random opinion 5 | to setup 6 | clear-all 7 | ask patches[ 8 | sprout 1[ 9 | set opinion (random-float 2) - 1 ;;give each agent an opinion drawn from [-1, 1] 10 | set shape "circle" 11 | ] 12 | ] 13 | update-colors ;;color represents opinion 14 | reset-ticks 15 | end 16 | 17 | 18 | to go 19 | ;; a random agent chooses another agent for a potential interaction 20 | ask one-of turtles [ 21 | let x1 opinion ;;my opinion 22 | let other-turtle one-of other turtles ;;choose interaction partner at random 23 | 24 | if spatial-interactions? ;;restrict interactions to spatial neighbors 25 | [set other-turtle one-of other turtles-on neighbors4] 26 | let x2 [opinion] of other-turtle ;;other guy's opinion 27 | 28 | ;;do they have an interaction and become more similar? 29 | if (abs (x1 - x2) < confidence-threshold) [ 30 | let x1-new (x1 + learning-rate * (x2 - x1)) 31 | let x2-new (x2 + learning-rate * (x1 - x2)) 32 | set opinion x1-new 33 | ask other-turtle [ set opinion x2-new] 34 | ] 35 | ] 36 | update-colors 37 | tick 38 | end 39 | 40 | 41 | ;;shade each agent between black (opinion = -1) and white (opinion = 1) 42 | to update-colors 43 | ask turtles [ 44 | set color (opinion + 1) * 9.9 / 2 45 | ] 46 | end 47 | 48 | 49 | ;;calculate number of cliques at end of run 50 | to-report num-cliques 51 | let cliques 1 52 | let d confidence-threshold ;;shorten name to make it easier to work with. 53 | let min-value min [opinion] of (turtles with [opinion > (-1 + .5 * d)]) 54 | 55 | while [any? turtles with [opinion > (min-value + d) and opinion < (1 - (.5 * d))]] [ 56 | set min-value min [opinion] of (turtles with [opinion > (min-value + (.5 * d))]) 57 | set cliques (cliques + 1) 58 | ] 59 | report cliques 60 | end 61 | 62 | 63 | ; Copyright 2023 Paul E. Smaldino. 64 | ; See Info tab for full copyright and license. 65 | @#$#@#$#@ 66 | GRAPHICS-WINDOW 67 | 269 68 | 14 69 | 579 70 | 325 71 | -1 72 | -1 73 | 14.4 74 | 1 75 | 10 76 | 1 77 | 1 78 | 1 79 | 0 80 | 0 81 | 0 82 | 1 83 | -10 84 | 10 85 | -10 86 | 10 87 | 0 88 | 0 89 | 1 90 | ticks 91 | 30.0 92 | 93 | BUTTON 94 | 85 95 | 34 96 | 151 97 | 67 98 | NIL 99 | setup 100 | NIL 101 | 1 102 | T 103 | OBSERVER 104 | NIL 105 | NIL 106 | NIL 107 | NIL 108 | 1 109 | 110 | BUTTON 111 | 157 112 | 34 113 | 220 114 | 67 115 | NIL 116 | go 117 | T 118 | 1 119 | T 120 | OBSERVER 121 | NIL 122 | NIL 123 | NIL 124 | NIL 125 | 0 126 | 127 | SLIDER 128 | 62 129 | 77 130 | 250 131 | 110 132 | learning-rate 133 | learning-rate 134 | 0 135 | 1 136 | 0.3 137 | .01 138 | 1 139 | NIL 140 | HORIZONTAL 141 | 142 | SLIDER 143 | 62 144 | 116 145 | 250 146 | 149 147 | confidence-threshold 148 | confidence-threshold 149 | 0 150 | 2 151 | 0.3 152 | .01 153 | 1 154 | NIL 155 | HORIZONTAL 156 | 157 | PLOT 158 | 270 159 | 329 160 | 580 161 | 513 162 | Agent opinions 163 | opinion 164 | number of agents 165 | -1.02 166 | 1.2 167 | 0.0 168 | 10.0 169 | false 170 | false 171 | "set-plot-x-range -1.02 1.02\nset-plot-y-range 0 count turtles\nset-histogram-num-bars 40\n" "" 172 | PENS 173 | "default" 1.0 1 -16777216 true "" "histogram [opinion] of turtles" 174 | 175 | SWITCH 176 | 62 177 | 154 178 | 250 179 | 187 180 | spatial-interactions? 181 | spatial-interactions? 182 | 0 183 | 1 184 | -1000 185 | 186 | PLOT 187 | 583 188 | 14 189 | 970 190 | 512 191 | Agent opinions over time 192 | time 193 | opinions 194 | 0.0 195 | 10.0 196 | -1.0 197 | 1.0 198 | true 199 | false 200 | "" "" 201 | PENS 202 | "default" 1.0 2 -14730904 true "" "if (ticks mod 100 = 0) [\nask turtles [\nplotxy ticks opinion\n]\n]" 203 | 204 | @#$#@#$#@ 205 | ## Model Information and Materials 206 | 207 | This model is original material created by Paul E. Smaldino. The model is based on work by Deffuant et al. (2000). 208 | 209 | * Deffuant, G., Neau, D., Amblard, F., & Weisbuch, G. (2000). Mixing beliefs among interacting agents. Advances in Complex Systems, 3, 87-98. 210 | 211 | ## References and Citation 212 | 213 | For this model: 214 | 215 | * Smaldino PE (2023). Opinion Dynamics: Bounded Confidence. Modeling Social Behavior. https://github.com/psmaldino/modsoc/ 216 | 217 | For the book: 218 | 219 | * Smaldino PE (2023). Modeling Social Behavior: Mathematical and Agent-Based Models of Social Dynamics and Cultural Evolution. Princeton University Press. 220 | 221 | For the NetLogo: 222 | 223 | * Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. 224 | 225 | 226 | ## Licence 227 | 228 | ![CC BY-NC-SA 4.0](http://ccl.northwestern.edu/images/creativecommons/byncsa.png) 229 | 230 | This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/ 231 | @#$#@#$#@ 232 | default 233 | true 234 | 0 235 | Polygon -7500403 true true 150 5 40 250 150 205 260 250 236 | 237 | airplane 238 | true 239 | 0 240 | Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 241 | 242 | arrow 243 | true 244 | 0 245 | Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 246 | 247 | box 248 | false 249 | 0 250 | Polygon -7500403 true true 150 285 285 225 285 75 150 135 251 | Polygon -7500403 true true 150 135 15 75 150 15 285 75 252 | Polygon -7500403 true true 15 75 15 225 150 285 150 135 253 | Line -16777216 false 150 285 150 135 254 | Line -16777216 false 150 135 15 75 255 | Line -16777216 false 150 135 285 75 256 | 257 | bug 258 | true 259 | 0 260 | Circle -7500403 true true 96 182 108 261 | Circle -7500403 true true 110 127 80 262 | Circle -7500403 true true 110 75 80 263 | Line -7500403 true 150 100 80 30 264 | Line -7500403 true 150 100 220 30 265 | 266 | butterfly 267 | true 268 | 0 269 | Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 270 | Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 271 | Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 272 | Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 273 | Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 274 | Circle -16777216 true false 135 90 30 275 | Line -16777216 false 150 105 195 60 276 | Line -16777216 false 150 105 105 60 277 | 278 | car 279 | false 280 | 0 281 | Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 282 | Circle -16777216 true false 180 180 90 283 | Circle -16777216 true false 30 180 90 284 | Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 285 | Circle -7500403 true true 47 195 58 286 | Circle -7500403 true true 195 195 58 287 | 288 | circle 289 | false 290 | 0 291 | Circle -7500403 true true 0 0 300 292 | 293 | circle 2 294 | false 295 | 0 296 | Circle -7500403 true true 0 0 300 297 | Circle -16777216 true false 30 30 240 298 | 299 | cow 300 | false 301 | 0 302 | Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 303 | Polygon -7500403 true true 73 210 86 251 62 249 48 208 304 | Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 305 | 306 | cylinder 307 | false 308 | 0 309 | Circle -7500403 true true 0 0 300 310 | 311 | dot 312 | false 313 | 0 314 | Circle -7500403 true true 90 90 120 315 | 316 | face happy 317 | false 318 | 0 319 | Circle -7500403 true true 8 8 285 320 | Circle -16777216 true false 60 75 60 321 | Circle -16777216 true false 180 75 60 322 | Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 323 | 324 | face neutral 325 | false 326 | 0 327 | Circle -7500403 true true 8 7 285 328 | Circle -16777216 true false 60 75 60 329 | Circle -16777216 true false 180 75 60 330 | Rectangle -16777216 true false 60 195 240 225 331 | 332 | face sad 333 | false 334 | 0 335 | Circle -7500403 true true 8 8 285 336 | Circle -16777216 true false 60 75 60 337 | Circle -16777216 true false 180 75 60 338 | Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 339 | 340 | fish 341 | false 342 | 0 343 | Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 344 | Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 345 | Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 346 | Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 347 | Circle -16777216 true false 215 106 30 348 | 349 | flag 350 | false 351 | 0 352 | Rectangle -7500403 true true 60 15 75 300 353 | Polygon -7500403 true true 90 150 270 90 90 30 354 | Line -7500403 true 75 135 90 135 355 | Line -7500403 true 75 45 90 45 356 | 357 | flower 358 | false 359 | 0 360 | Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 361 | Circle -7500403 true true 85 132 38 362 | Circle -7500403 true true 130 147 38 363 | Circle -7500403 true true 192 85 38 364 | Circle -7500403 true true 85 40 38 365 | Circle -7500403 true true 177 40 38 366 | Circle -7500403 true true 177 132 38 367 | Circle -7500403 true true 70 85 38 368 | Circle -7500403 true true 130 25 38 369 | Circle -7500403 true true 96 51 108 370 | Circle -16777216 true false 113 68 74 371 | Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 372 | Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 373 | 374 | house 375 | false 376 | 0 377 | Rectangle -7500403 true true 45 120 255 285 378 | Rectangle -16777216 true false 120 210 180 285 379 | Polygon -7500403 true true 15 120 150 15 285 120 380 | Line -16777216 false 30 120 270 120 381 | 382 | leaf 383 | false 384 | 0 385 | Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 386 | Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 387 | 388 | line 389 | true 390 | 0 391 | Line -7500403 true 150 0 150 300 392 | 393 | line half 394 | true 395 | 0 396 | Line -7500403 true 150 0 150 150 397 | 398 | pentagon 399 | false 400 | 0 401 | Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 402 | 403 | person 404 | false 405 | 0 406 | Circle -7500403 true true 110 5 80 407 | Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 408 | Rectangle -7500403 true true 127 79 172 94 409 | Polygon -7500403 true true 195 90 240 150 225 180 165 105 410 | Polygon -7500403 true true 105 90 60 150 75 180 135 105 411 | 412 | plant 413 | false 414 | 0 415 | Rectangle -7500403 true true 135 90 165 300 416 | Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 417 | Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 418 | Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 419 | Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 420 | Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 421 | Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 422 | Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 423 | 424 | sheep 425 | false 426 | 15 427 | Circle -1 true true 203 65 88 428 | Circle -1 true true 70 65 162 429 | Circle -1 true true 150 105 120 430 | Polygon -7500403 true false 218 120 240 165 255 165 278 120 431 | Circle -7500403 true false 214 72 67 432 | Rectangle -1 true true 164 223 179 298 433 | Polygon -1 true true 45 285 30 285 30 240 15 195 45 210 434 | Circle -1 true true 3 83 150 435 | Rectangle -1 true true 65 221 80 296 436 | Polygon -1 true true 195 285 210 285 210 240 240 210 195 210 437 | Polygon -7500403 true false 276 85 285 105 302 99 294 83 438 | Polygon -7500403 true false 219 85 210 105 193 99 201 83 439 | 440 | square 441 | false 442 | 0 443 | Rectangle -7500403 true true 30 30 270 270 444 | 445 | square 2 446 | false 447 | 0 448 | Rectangle -7500403 true true 30 30 270 270 449 | Rectangle -16777216 true false 60 60 240 240 450 | 451 | star 452 | false 453 | 0 454 | Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 455 | 456 | target 457 | false 458 | 0 459 | Circle -7500403 true true 0 0 300 460 | Circle -16777216 true false 30 30 240 461 | Circle -7500403 true true 60 60 180 462 | Circle -16777216 true false 90 90 120 463 | Circle -7500403 true true 120 120 60 464 | 465 | tree 466 | false 467 | 0 468 | Circle -7500403 true true 118 3 94 469 | Rectangle -6459832 true false 120 195 180 300 470 | Circle -7500403 true true 65 21 108 471 | Circle -7500403 true true 116 41 127 472 | Circle -7500403 true true 45 90 120 473 | Circle -7500403 true true 104 74 152 474 | 475 | triangle 476 | false 477 | 0 478 | Polygon -7500403 true true 150 30 15 255 285 255 479 | 480 | triangle 2 481 | false 482 | 0 483 | Polygon -7500403 true true 150 30 15 255 285 255 484 | Polygon -16777216 true false 151 99 225 223 75 224 485 | 486 | truck 487 | false 488 | 0 489 | Rectangle -7500403 true true 4 45 195 187 490 | Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 491 | Rectangle -1 true false 195 60 195 105 492 | Polygon -16777216 true false 238 112 252 141 219 141 218 112 493 | Circle -16777216 true false 234 174 42 494 | Rectangle -7500403 true true 181 185 214 194 495 | Circle -16777216 true false 144 174 42 496 | Circle -16777216 true false 24 174 42 497 | Circle -7500403 false true 24 174 42 498 | Circle -7500403 false true 144 174 42 499 | Circle -7500403 false true 234 174 42 500 | 501 | turtle 502 | true 503 | 0 504 | Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 505 | Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 506 | Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 507 | Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 508 | Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 509 | Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 510 | 511 | wheel 512 | false 513 | 0 514 | Circle -7500403 true true 3 3 294 515 | Circle -16777216 true false 30 30 240 516 | Line -7500403 true 150 285 150 15 517 | Line -7500403 true 15 150 285 150 518 | Circle -7500403 true true 120 120 60 519 | Line -7500403 true 216 40 79 269 520 | Line -7500403 true 40 84 269 221 521 | Line -7500403 true 40 216 269 79 522 | Line -7500403 true 84 40 221 269 523 | 524 | wolf 525 | false 526 | 0 527 | Polygon -16777216 true false 253 133 245 131 245 133 528 | Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105 529 | Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113 530 | 531 | x 532 | false 533 | 0 534 | Polygon -7500403 true true 270 75 225 30 30 225 75 270 535 | Polygon -7500403 true true 30 75 75 30 270 225 225 270 536 | @#$#@#$#@ 537 | NetLogo 6.2.2 538 | @#$#@#$#@ 539 | @#$#@#$#@ 540 | @#$#@#$#@ 541 | 542 | 543 | setup 544 | go 545 | 546 | num-cliques 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | @#$#@#$#@ 557 | @#$#@#$#@ 558 | default 559 | 0.0 560 | -0.2 0 0.0 1.0 561 | 0.0 1 1.0 0.0 562 | 0.2 0 0.0 1.0 563 | link direction 564 | true 565 | 0 566 | Line -7500403 true 150 150 90 180 567 | Line -7500403 true 150 150 210 180 568 | @#$#@#$#@ 569 | 0 570 | @#$#@#$#@ 571 | -------------------------------------------------------------------------------- /ch06_cooperation/PD_simple.nlogo: -------------------------------------------------------------------------------- 1 | 2 | turtles-own [ 3 | strategy ;0=defector, 1=cooperator 4 | payoff ;;payoff 5 | ] 6 | 7 | ;;----SETUP PROCEDURES--------------------- 8 | 9 | to setup 10 | clear-all 11 | make-agents 12 | recolor 13 | reset-ticks 14 | end 15 | 16 | ;;create agents, one on each patch. Make some of them cooperators. 17 | to make-agents 18 | ask patches [ 19 | sprout 1 [ 20 | ifelse random-float 1 < init-coop-freq 21 | [ set strategy 1 ] 22 | [ set strategy 0 ] 23 | set shape "circle" 24 | set payoff 0 25 | ] 26 | ] 27 | end 28 | 29 | ;;recolor agents based on strategy 30 | ;;red = defector, blue = cooperator 31 | to recolor 32 | ask turtles[ 33 | if strategy = 0 34 | [ set color red] 35 | if strategy = 1 36 | [ set color blue] 37 | ] 38 | end 39 | 40 | 41 | 42 | ;;----DYNAMICS PROCEDURES--------------------- 43 | 44 | to go 45 | if (all? turtles [strategy = 0] or all? turtles [strategy = 1]) [stop] ;;stop if one strategy has "won" 46 | play-game ;;agents play the game with neighbors and receive payoffs 47 | evolve ;;agents copy the strategy of their most successful neighbor 48 | recolor ;;recolor agents to match their strategy 49 | tick 50 | end 51 | 52 | 53 | ;;each agent plays the PD game with each of its 4 closest neighbors and accumulates payoff 54 | to play-game 55 | 56 | ask turtles [ 57 | set payoff 0;;reset payoff for this time step 58 | 59 | ;count neighbors with each strategy 60 | let neighbors-C count (turtles-on neighbors4) with [strategy = 1] 61 | let neighbors-D count (turtles-on neighbors4) with [strategy = 0] 62 | 63 | ;if I'm a cooperator 64 | if (strategy = 1) 65 | [ set payoff (neighbors-C * (payoff-benefit - payoff-cost) - neighbors-D * payoff-cost) ] 66 | 67 | ;if I'm a defector 68 | if (strategy = 0) 69 | [ set payoff (neighbors-C * payoff-benefit) ] 70 | ] 71 | end 72 | 73 | ;;each agent imitates their most successful neighbor 74 | to evolve 75 | ask turtles[ 76 | let best-neighbor max-one-of (turtles-on neighbors4) [payoff] ;;who's my neighbor with the highest payoff 77 | if ([payoff] of best-neighbor) > payoff ;;if their payoff is better than mine, imitate them 78 | [set strategy [strategy] of best-neighbor] 79 | ] 80 | end 81 | 82 | ; Copyright 2023 Paul E. Smaldino. 83 | ; See Info tab for full copyright and license. 84 | @#$#@#$#@ 85 | GRAPHICS-WINDOW 86 | 235 87 | 18 88 | 562 89 | 346 90 | -1 91 | -1 92 | 10.3 93 | 1 94 | 10 95 | 1 96 | 1 97 | 1 98 | 0 99 | 1 100 | 1 101 | 1 102 | -15 103 | 15 104 | -15 105 | 15 106 | 0 107 | 0 108 | 1 109 | ticks 110 | 30.0 111 | 112 | SLIDER 113 | 46 114 | 104 115 | 225 116 | 137 117 | init-coop-freq 118 | init-coop-freq 119 | 0 120 | 1 121 | 0.5 122 | .01 123 | 1 124 | NIL 125 | HORIZONTAL 126 | 127 | SLIDER 128 | 46 129 | 148 130 | 225 131 | 181 132 | payoff-benefit 133 | payoff-benefit 134 | 0 135 | 1 136 | 1.0 137 | .01 138 | 1 139 | NIL 140 | HORIZONTAL 141 | 142 | SLIDER 143 | 46 144 | 190 145 | 226 146 | 223 147 | payoff-cost 148 | payoff-cost 149 | 0 150 | 1 151 | 0.1 152 | .01 153 | 1 154 | NIL 155 | HORIZONTAL 156 | 157 | BUTTON 158 | 47 159 | 18 160 | 136 161 | 51 162 | NIL 163 | setup 164 | NIL 165 | 1 166 | T 167 | OBSERVER 168 | NIL 169 | NIL 170 | NIL 171 | NIL 172 | 1 173 | 174 | BUTTON 175 | 144 176 | 18 177 | 218 178 | 51 179 | NIL 180 | go 181 | T 182 | 1 183 | T 184 | OBSERVER 185 | NIL 186 | NIL 187 | NIL 188 | NIL 189 | 0 190 | 191 | PLOT 192 | 568 193 | 19 194 | 883 195 | 346 196 | Frequency of Cooperation 197 | Time 198 | Cooperator frequency 199 | 0.0 200 | 10.0 201 | 0.0 202 | 1.0 203 | true 204 | false 205 | "" "" 206 | PENS 207 | "default" 1.0 0 -13345367 true "" "plot (count turtles with [strategy = 1]) / (count turtles)" 208 | 209 | BUTTON 210 | 91 211 | 58 212 | 172 213 | 91 214 | go once 215 | go 216 | NIL 217 | 1 218 | T 219 | OBSERVER 220 | NIL 221 | NIL 222 | NIL 223 | NIL 224 | 1 225 | 226 | @#$#@#$#@ 227 | ## Model Information and Materials 228 | 229 | This model is original material created by Paul E. Smaldino. 230 | 231 | ## References and Citation 232 | 233 | For this model: 234 | 235 | * Smaldino PE (2023). Prisoner's Dilemma Game: Simple. Modeling Social Behavior. https://github.com/psmaldino/modsoc/ 236 | 237 | For the book: 238 | 239 | * Smaldino PE (2023). Modeling Social Behavior: Mathematical and Agent-Based Models of Social Dynamics and Cultural Evolution. Princeton University Press. 240 | 241 | For the NetLogo: 242 | 243 | * Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. 244 | 245 | 246 | ## Licence 247 | 248 | ![CC BY-NC-SA 4.0](http://ccl.northwestern.edu/images/creativecommons/byncsa.png) 249 | 250 | This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/ 251 | @#$#@#$#@ 252 | default 253 | true 254 | 0 255 | Polygon -7500403 true true 150 5 40 250 150 205 260 250 256 | 257 | airplane 258 | true 259 | 0 260 | Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 261 | 262 | arrow 263 | true 264 | 0 265 | Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 266 | 267 | box 268 | false 269 | 0 270 | Polygon -7500403 true true 150 285 285 225 285 75 150 135 271 | Polygon -7500403 true true 150 135 15 75 150 15 285 75 272 | Polygon -7500403 true true 15 75 15 225 150 285 150 135 273 | Line -16777216 false 150 285 150 135 274 | Line -16777216 false 150 135 15 75 275 | Line -16777216 false 150 135 285 75 276 | 277 | bug 278 | true 279 | 0 280 | Circle -7500403 true true 96 182 108 281 | Circle -7500403 true true 110 127 80 282 | Circle -7500403 true true 110 75 80 283 | Line -7500403 true 150 100 80 30 284 | Line -7500403 true 150 100 220 30 285 | 286 | butterfly 287 | true 288 | 0 289 | Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 290 | Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 291 | Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 292 | Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 293 | Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 294 | Circle -16777216 true false 135 90 30 295 | Line -16777216 false 150 105 195 60 296 | Line -16777216 false 150 105 105 60 297 | 298 | car 299 | false 300 | 0 301 | Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 302 | Circle -16777216 true false 180 180 90 303 | Circle -16777216 true false 30 180 90 304 | Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 305 | Circle -7500403 true true 47 195 58 306 | Circle -7500403 true true 195 195 58 307 | 308 | circle 309 | false 310 | 0 311 | Circle -7500403 true true 0 0 300 312 | 313 | circle 2 314 | false 315 | 0 316 | Circle -7500403 true true 0 0 300 317 | Circle -16777216 true false 30 30 240 318 | 319 | cow 320 | false 321 | 0 322 | Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 323 | Polygon -7500403 true true 73 210 86 251 62 249 48 208 324 | Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 325 | 326 | cylinder 327 | false 328 | 0 329 | Circle -7500403 true true 0 0 300 330 | 331 | dot 332 | false 333 | 0 334 | Circle -7500403 true true 90 90 120 335 | 336 | face happy 337 | false 338 | 0 339 | Circle -7500403 true true 8 8 285 340 | Circle -16777216 true false 60 75 60 341 | Circle -16777216 true false 180 75 60 342 | Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 343 | 344 | face neutral 345 | false 346 | 0 347 | Circle -7500403 true true 8 7 285 348 | Circle -16777216 true false 60 75 60 349 | Circle -16777216 true false 180 75 60 350 | Rectangle -16777216 true false 60 195 240 225 351 | 352 | face sad 353 | false 354 | 0 355 | Circle -7500403 true true 8 8 285 356 | Circle -16777216 true false 60 75 60 357 | Circle -16777216 true false 180 75 60 358 | Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 359 | 360 | fish 361 | false 362 | 0 363 | Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 364 | Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 365 | Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 366 | Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 367 | Circle -16777216 true false 215 106 30 368 | 369 | flag 370 | false 371 | 0 372 | Rectangle -7500403 true true 60 15 75 300 373 | Polygon -7500403 true true 90 150 270 90 90 30 374 | Line -7500403 true 75 135 90 135 375 | Line -7500403 true 75 45 90 45 376 | 377 | flower 378 | false 379 | 0 380 | Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 381 | Circle -7500403 true true 85 132 38 382 | Circle -7500403 true true 130 147 38 383 | Circle -7500403 true true 192 85 38 384 | Circle -7500403 true true 85 40 38 385 | Circle -7500403 true true 177 40 38 386 | Circle -7500403 true true 177 132 38 387 | Circle -7500403 true true 70 85 38 388 | Circle -7500403 true true 130 25 38 389 | Circle -7500403 true true 96 51 108 390 | Circle -16777216 true false 113 68 74 391 | Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 392 | Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 393 | 394 | house 395 | false 396 | 0 397 | Rectangle -7500403 true true 45 120 255 285 398 | Rectangle -16777216 true false 120 210 180 285 399 | Polygon -7500403 true true 15 120 150 15 285 120 400 | Line -16777216 false 30 120 270 120 401 | 402 | leaf 403 | false 404 | 0 405 | Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 406 | Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 407 | 408 | line 409 | true 410 | 0 411 | Line -7500403 true 150 0 150 300 412 | 413 | line half 414 | true 415 | 0 416 | Line -7500403 true 150 0 150 150 417 | 418 | pentagon 419 | false 420 | 0 421 | Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 422 | 423 | person 424 | false 425 | 0 426 | Circle -7500403 true true 110 5 80 427 | Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 428 | Rectangle -7500403 true true 127 79 172 94 429 | Polygon -7500403 true true 195 90 240 150 225 180 165 105 430 | Polygon -7500403 true true 105 90 60 150 75 180 135 105 431 | 432 | plant 433 | false 434 | 0 435 | Rectangle -7500403 true true 135 90 165 300 436 | Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 437 | Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 438 | Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 439 | Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 440 | Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 441 | Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 442 | Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 443 | 444 | sheep 445 | false 446 | 15 447 | Circle -1 true true 203 65 88 448 | Circle -1 true true 70 65 162 449 | Circle -1 true true 150 105 120 450 | Polygon -7500403 true false 218 120 240 165 255 165 278 120 451 | Circle -7500403 true false 214 72 67 452 | Rectangle -1 true true 164 223 179 298 453 | Polygon -1 true true 45 285 30 285 30 240 15 195 45 210 454 | Circle -1 true true 3 83 150 455 | Rectangle -1 true true 65 221 80 296 456 | Polygon -1 true true 195 285 210 285 210 240 240 210 195 210 457 | Polygon -7500403 true false 276 85 285 105 302 99 294 83 458 | Polygon -7500403 true false 219 85 210 105 193 99 201 83 459 | 460 | square 461 | false 462 | 0 463 | Rectangle -7500403 true true 30 30 270 270 464 | 465 | square 2 466 | false 467 | 0 468 | Rectangle -7500403 true true 30 30 270 270 469 | Rectangle -16777216 true false 60 60 240 240 470 | 471 | star 472 | false 473 | 0 474 | Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 475 | 476 | target 477 | false 478 | 0 479 | Circle -7500403 true true 0 0 300 480 | Circle -16777216 true false 30 30 240 481 | Circle -7500403 true true 60 60 180 482 | Circle -16777216 true false 90 90 120 483 | Circle -7500403 true true 120 120 60 484 | 485 | tree 486 | false 487 | 0 488 | Circle -7500403 true true 118 3 94 489 | Rectangle -6459832 true false 120 195 180 300 490 | Circle -7500403 true true 65 21 108 491 | Circle -7500403 true true 116 41 127 492 | Circle -7500403 true true 45 90 120 493 | Circle -7500403 true true 104 74 152 494 | 495 | triangle 496 | false 497 | 0 498 | Polygon -7500403 true true 150 30 15 255 285 255 499 | 500 | triangle 2 501 | false 502 | 0 503 | Polygon -7500403 true true 150 30 15 255 285 255 504 | Polygon -16777216 true false 151 99 225 223 75 224 505 | 506 | truck 507 | false 508 | 0 509 | Rectangle -7500403 true true 4 45 195 187 510 | Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 511 | Rectangle -1 true false 195 60 195 105 512 | Polygon -16777216 true false 238 112 252 141 219 141 218 112 513 | Circle -16777216 true false 234 174 42 514 | Rectangle -7500403 true true 181 185 214 194 515 | Circle -16777216 true false 144 174 42 516 | Circle -16777216 true false 24 174 42 517 | Circle -7500403 false true 24 174 42 518 | Circle -7500403 false true 144 174 42 519 | Circle -7500403 false true 234 174 42 520 | 521 | turtle 522 | true 523 | 0 524 | Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 525 | Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 526 | Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 527 | Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 528 | Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 529 | Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 530 | 531 | wheel 532 | false 533 | 0 534 | Circle -7500403 true true 3 3 294 535 | Circle -16777216 true false 30 30 240 536 | Line -7500403 true 150 285 150 15 537 | Line -7500403 true 15 150 285 150 538 | Circle -7500403 true true 120 120 60 539 | Line -7500403 true 216 40 79 269 540 | Line -7500403 true 40 84 269 221 541 | Line -7500403 true 40 216 269 79 542 | Line -7500403 true 84 40 221 269 543 | 544 | wolf 545 | false 546 | 0 547 | Polygon -16777216 true false 253 133 245 131 245 133 548 | Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105 549 | Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113 550 | 551 | x 552 | false 553 | 0 554 | Polygon -7500403 true true 270 75 225 30 30 225 75 270 555 | Polygon -7500403 true true 30 75 75 30 270 225 225 270 556 | @#$#@#$#@ 557 | NetLogo 6.2.2 558 | @#$#@#$#@ 559 | @#$#@#$#@ 560 | @#$#@#$#@ 561 | 562 | 563 | setup 564 | go 565 | 566 | (count turtles with [strategy = 1]) / (count turtles) 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | @#$#@#$#@ 577 | @#$#@#$#@ 578 | default 579 | 0.0 580 | -0.2 0 0.0 1.0 581 | 0.0 1 1.0 0.0 582 | 0.2 0 0.0 1.0 583 | link direction 584 | true 585 | 0 586 | Line -7500403 true 150 150 90 180 587 | Line -7500403 true 150 150 210 180 588 | @#$#@#$#@ 589 | 0 590 | @#$#@#$#@ 591 | -------------------------------------------------------------------------------- /ch07_coordination/coordination_asymmetric.nlogo: -------------------------------------------------------------------------------- 1 | ;; An asymmetric coordination model in one population. Everyone starts with one of two norms. 2 | ;; Agents calculate their expected payoff and then preferentially (probabilistically) copy those with higher payoffs. 3 | ;; Here, Norm 1 is better for the group but costlier when rare compared to Norm 2. 4 | 5 | 6 | 7 | turtles-own [ 8 | norm1? ;;do I have norm 1? If false, norm 2. 9 | payoff 10 | ] 11 | 12 | ;; Create agents, one on each patch. Assign them one of two norms. 13 | to setup 14 | clear-all 15 | ask patches [ 16 | sprout 1 [ 17 | set shape "circle" 18 | ifelse random-float 1 < init-norm1 19 | [set norm1? true] 20 | [set norm1? false] 21 | ] 22 | ] 23 | ;set norm1-payoff 0 24 | ;set norm2-payoff 0 25 | recolor 26 | reset-ticks 27 | end 28 | 29 | 30 | to go 31 | ;;stop simulation if all agents are using the same norm 32 | if (count turtles with [norm1?]) = (count patches) or 33 | (count turtles with [norm1?]) = 0 34 | [ stop ] 35 | 36 | calculate-payoffs ;;interactions and payoffs 37 | evolve ;;success-biased imitation 38 | recolor 39 | tick 40 | end 41 | 42 | 43 | ;;calculate expected payoff for all possible interactions 44 | to calculate-payoffs 45 | 46 | let p1 (count turtles with [norm1?]) / (count turtles) 47 | 48 | let norm1-payoff ((p1 * (1 + norm1-prosocial-benefit + norm1-coord-benefit)) + ((1 - p1) * (1 - norm1-rarity-cost))) 49 | let norm2-payoff (p1 * (1 + norm1-prosocial-benefit) + (1 - p1) * 1) 50 | 51 | ask turtles with [norm1?][ ;;calculate payoffs for the norm 1 agents 52 | set payoff norm1-payoff 53 | ] 54 | ask turtles with [not norm1?][ ;;calculate payoffs for the norm 1 agents 55 | set payoff norm2-payoff 56 | ] 57 | end 58 | 59 | ;; observe another agent at random, and probabilistically copy their strategy to the extent their payoff 60 | ;; is higher than my own 61 | to evolve 62 | ask turtles[ 63 | let model one-of other turtles 64 | let other-payoff [payoff] of model 65 | let prob-copy (1 / (1 + exp (-1 * (other-payoff - payoff)))) 66 | if random-float 1 < prob-copy 67 | [set norm1? [norm1?] of model] 68 | ] 69 | end 70 | 71 | ;; recolor agents based on norm. 72 | ;; yellow = norm 1, blue = norm 2 73 | to recolor 74 | ask turtles[ 75 | ifelse norm1? 76 | [set color yellow] 77 | [set color blue] 78 | ] 79 | end 80 | 81 | 82 | ; Copyright 2023 Paul E. Smaldino. 83 | ; See Info tab for full copyright and license. 84 | @#$#@#$#@ 85 | GRAPHICS-WINDOW 86 | 230 87 | 16 88 | 494 89 | 281 90 | -1 91 | -1 92 | 8.26 93 | 1 94 | 10 95 | 1 96 | 1 97 | 1 98 | 0 99 | 1 100 | 1 101 | 1 102 | -15 103 | 15 104 | -15 105 | 15 106 | 0 107 | 0 108 | 1 109 | ticks 110 | 30.0 111 | 112 | BUTTON 113 | 41 114 | 24 115 | 126 116 | 57 117 | NIL 118 | setup 119 | NIL 120 | 1 121 | T 122 | OBSERVER 123 | NIL 124 | NIL 125 | NIL 126 | NIL 127 | 1 128 | 129 | BUTTON 130 | 131 131 | 24 132 | 214 133 | 57 134 | NIL 135 | go 136 | T 137 | 1 138 | T 139 | OBSERVER 140 | NIL 141 | NIL 142 | NIL 143 | NIL 144 | 1 145 | 146 | SLIDER 147 | 30 148 | 65 149 | 226 150 | 98 151 | init-norm1 152 | init-norm1 153 | 0 154 | 1 155 | 0.6 156 | .01 157 | 1 158 | NIL 159 | HORIZONTAL 160 | 161 | PLOT 162 | 504 163 | 17 164 | 769 165 | 223 166 | Norms 167 | time 168 | Proportion w/ norm 1 169 | 0.0 170 | 10.0 171 | 0.0 172 | 1.0 173 | true 174 | false 175 | "" "" 176 | PENS 177 | "Freq Norm 1" 1.0 0 -16777216 true "" "plot (count turtles with [norm1?]) / (count turtles)" 178 | 179 | SLIDER 180 | 30 181 | 102 182 | 226 183 | 135 184 | norm1-prosocial-benefit 185 | norm1-prosocial-benefit 186 | 0 187 | 10 188 | 1.0 189 | .1 190 | 1 191 | NIL 192 | HORIZONTAL 193 | 194 | SLIDER 195 | 30 196 | 138 197 | 226 198 | 171 199 | norm1-coord-benefit 200 | norm1-coord-benefit 201 | 0 202 | 10 203 | 1.0 204 | .1 205 | 1 206 | NIL 207 | HORIZONTAL 208 | 209 | SLIDER 210 | 30 211 | 175 212 | 226 213 | 208 214 | norm1-rarity-cost 215 | norm1-rarity-cost 216 | 0 217 | 10 218 | 0.5 219 | .1 220 | 1 221 | NIL 222 | HORIZONTAL 223 | 224 | MONITOR 225 | 505 226 | 235 227 | 594 228 | 280 229 | freq(norm1) 230 | (count turtles with [norm1?]) / (count turtles) 231 | 4 232 | 1 233 | 11 234 | 235 | MONITOR 236 | 599 237 | 235 238 | 685 239 | 280 240 | p* 241 | norm1-rarity-cost / (norm1-rarity-cost + norm1-coord-benefit) 242 | 6 243 | 1 244 | 11 245 | 246 | @#$#@#$#@ 247 | ## Model Information and Materials 248 | 249 | This model is original material created by Paul E. Smaldino. The payoff matrix is based on work by Boyd and Richerson (2002). 250 | 251 | * Boyd R. Richerson PJ (2002) Group beneficial norms can spread rapidly in a structured population. Journal of Theoretical Biology 215: 287-296. 252 | 253 | ## References and Citation 254 | 255 | For this model: 256 | 257 | * Smaldino PE (2023). Coordination: Asymmetric. Modeling Social Behavior. https://github.com/psmaldino/modsoc/ 258 | 259 | For the book: 260 | 261 | * Smaldino PE (2023). Modeling Social Behavior: Mathematical and Agent-Based Models of Social Dynamics and Cultural Evolution. Princeton University Press. 262 | 263 | For the NetLogo: 264 | 265 | * Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. 266 | 267 | 268 | ## Licence 269 | 270 | ![CC BY-NC-SA 4.0](http://ccl.northwestern.edu/images/creativecommons/byncsa.png) 271 | 272 | This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/ 273 | @#$#@#$#@ 274 | default 275 | true 276 | 0 277 | Polygon -7500403 true true 150 5 40 250 150 205 260 250 278 | 279 | airplane 280 | true 281 | 0 282 | Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 283 | 284 | arrow 285 | true 286 | 0 287 | Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 288 | 289 | box 290 | false 291 | 0 292 | Polygon -7500403 true true 150 285 285 225 285 75 150 135 293 | Polygon -7500403 true true 150 135 15 75 150 15 285 75 294 | Polygon -7500403 true true 15 75 15 225 150 285 150 135 295 | Line -16777216 false 150 285 150 135 296 | Line -16777216 false 150 135 15 75 297 | Line -16777216 false 150 135 285 75 298 | 299 | bug 300 | true 301 | 0 302 | Circle -7500403 true true 96 182 108 303 | Circle -7500403 true true 110 127 80 304 | Circle -7500403 true true 110 75 80 305 | Line -7500403 true 150 100 80 30 306 | Line -7500403 true 150 100 220 30 307 | 308 | butterfly 309 | true 310 | 0 311 | Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 312 | Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 313 | Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 314 | Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 315 | Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 316 | Circle -16777216 true false 135 90 30 317 | Line -16777216 false 150 105 195 60 318 | Line -16777216 false 150 105 105 60 319 | 320 | car 321 | false 322 | 0 323 | Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 324 | Circle -16777216 true false 180 180 90 325 | Circle -16777216 true false 30 180 90 326 | Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 327 | Circle -7500403 true true 47 195 58 328 | Circle -7500403 true true 195 195 58 329 | 330 | circle 331 | false 332 | 0 333 | Circle -7500403 true true 0 0 300 334 | 335 | circle 2 336 | false 337 | 0 338 | Circle -7500403 true true 0 0 300 339 | Circle -16777216 true false 30 30 240 340 | 341 | cow 342 | false 343 | 0 344 | Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 345 | Polygon -7500403 true true 73 210 86 251 62 249 48 208 346 | Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 347 | 348 | cylinder 349 | false 350 | 0 351 | Circle -7500403 true true 0 0 300 352 | 353 | dot 354 | false 355 | 0 356 | Circle -7500403 true true 90 90 120 357 | 358 | face happy 359 | false 360 | 0 361 | Circle -7500403 true true 8 8 285 362 | Circle -16777216 true false 60 75 60 363 | Circle -16777216 true false 180 75 60 364 | Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 365 | 366 | face neutral 367 | false 368 | 0 369 | Circle -7500403 true true 8 7 285 370 | Circle -16777216 true false 60 75 60 371 | Circle -16777216 true false 180 75 60 372 | Rectangle -16777216 true false 60 195 240 225 373 | 374 | face sad 375 | false 376 | 0 377 | Circle -7500403 true true 8 8 285 378 | Circle -16777216 true false 60 75 60 379 | Circle -16777216 true false 180 75 60 380 | Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 381 | 382 | fish 383 | false 384 | 0 385 | Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 386 | Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 387 | Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 388 | Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 389 | Circle -16777216 true false 215 106 30 390 | 391 | flag 392 | false 393 | 0 394 | Rectangle -7500403 true true 60 15 75 300 395 | Polygon -7500403 true true 90 150 270 90 90 30 396 | Line -7500403 true 75 135 90 135 397 | Line -7500403 true 75 45 90 45 398 | 399 | flower 400 | false 401 | 0 402 | Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 403 | Circle -7500403 true true 85 132 38 404 | Circle -7500403 true true 130 147 38 405 | Circle -7500403 true true 192 85 38 406 | Circle -7500403 true true 85 40 38 407 | Circle -7500403 true true 177 40 38 408 | Circle -7500403 true true 177 132 38 409 | Circle -7500403 true true 70 85 38 410 | Circle -7500403 true true 130 25 38 411 | Circle -7500403 true true 96 51 108 412 | Circle -16777216 true false 113 68 74 413 | Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 414 | Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 415 | 416 | house 417 | false 418 | 0 419 | Rectangle -7500403 true true 45 120 255 285 420 | Rectangle -16777216 true false 120 210 180 285 421 | Polygon -7500403 true true 15 120 150 15 285 120 422 | Line -16777216 false 30 120 270 120 423 | 424 | leaf 425 | false 426 | 0 427 | Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 428 | Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 429 | 430 | line 431 | true 432 | 0 433 | Line -7500403 true 150 0 150 300 434 | 435 | line half 436 | true 437 | 0 438 | Line -7500403 true 150 0 150 150 439 | 440 | pentagon 441 | false 442 | 0 443 | Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 444 | 445 | person 446 | false 447 | 0 448 | Circle -7500403 true true 110 5 80 449 | Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 450 | Rectangle -7500403 true true 127 79 172 94 451 | Polygon -7500403 true true 195 90 240 150 225 180 165 105 452 | Polygon -7500403 true true 105 90 60 150 75 180 135 105 453 | 454 | plant 455 | false 456 | 0 457 | Rectangle -7500403 true true 135 90 165 300 458 | Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 459 | Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 460 | Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 461 | Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 462 | Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 463 | Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 464 | Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 465 | 466 | sheep 467 | false 468 | 15 469 | Circle -1 true true 203 65 88 470 | Circle -1 true true 70 65 162 471 | Circle -1 true true 150 105 120 472 | Polygon -7500403 true false 218 120 240 165 255 165 278 120 473 | Circle -7500403 true false 214 72 67 474 | Rectangle -1 true true 164 223 179 298 475 | Polygon -1 true true 45 285 30 285 30 240 15 195 45 210 476 | Circle -1 true true 3 83 150 477 | Rectangle -1 true true 65 221 80 296 478 | Polygon -1 true true 195 285 210 285 210 240 240 210 195 210 479 | Polygon -7500403 true false 276 85 285 105 302 99 294 83 480 | Polygon -7500403 true false 219 85 210 105 193 99 201 83 481 | 482 | square 483 | false 484 | 0 485 | Rectangle -7500403 true true 30 30 270 270 486 | 487 | square 2 488 | false 489 | 0 490 | Rectangle -7500403 true true 30 30 270 270 491 | Rectangle -16777216 true false 60 60 240 240 492 | 493 | star 494 | false 495 | 0 496 | Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 497 | 498 | target 499 | false 500 | 0 501 | Circle -7500403 true true 0 0 300 502 | Circle -16777216 true false 30 30 240 503 | Circle -7500403 true true 60 60 180 504 | Circle -16777216 true false 90 90 120 505 | Circle -7500403 true true 120 120 60 506 | 507 | tree 508 | false 509 | 0 510 | Circle -7500403 true true 118 3 94 511 | Rectangle -6459832 true false 120 195 180 300 512 | Circle -7500403 true true 65 21 108 513 | Circle -7500403 true true 116 41 127 514 | Circle -7500403 true true 45 90 120 515 | Circle -7500403 true true 104 74 152 516 | 517 | triangle 518 | false 519 | 0 520 | Polygon -7500403 true true 150 30 15 255 285 255 521 | 522 | triangle 2 523 | false 524 | 0 525 | Polygon -7500403 true true 150 30 15 255 285 255 526 | Polygon -16777216 true false 151 99 225 223 75 224 527 | 528 | truck 529 | false 530 | 0 531 | Rectangle -7500403 true true 4 45 195 187 532 | Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 533 | Rectangle -1 true false 195 60 195 105 534 | Polygon -16777216 true false 238 112 252 141 219 141 218 112 535 | Circle -16777216 true false 234 174 42 536 | Rectangle -7500403 true true 181 185 214 194 537 | Circle -16777216 true false 144 174 42 538 | Circle -16777216 true false 24 174 42 539 | Circle -7500403 false true 24 174 42 540 | Circle -7500403 false true 144 174 42 541 | Circle -7500403 false true 234 174 42 542 | 543 | turtle 544 | true 545 | 0 546 | Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 547 | Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 548 | Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 549 | Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 550 | Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 551 | Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 552 | 553 | wheel 554 | false 555 | 0 556 | Circle -7500403 true true 3 3 294 557 | Circle -16777216 true false 30 30 240 558 | Line -7500403 true 150 285 150 15 559 | Line -7500403 true 15 150 285 150 560 | Circle -7500403 true true 120 120 60 561 | Line -7500403 true 216 40 79 269 562 | Line -7500403 true 40 84 269 221 563 | Line -7500403 true 40 216 269 79 564 | Line -7500403 true 84 40 221 269 565 | 566 | wolf 567 | false 568 | 0 569 | Polygon -16777216 true false 253 133 245 131 245 133 570 | Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105 571 | Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113 572 | 573 | x 574 | false 575 | 0 576 | Polygon -7500403 true true 270 75 225 30 30 225 75 270 577 | Polygon -7500403 true true 30 75 75 30 270 225 225 270 578 | @#$#@#$#@ 579 | NetLogo 6.2.2 580 | @#$#@#$#@ 581 | @#$#@#$#@ 582 | @#$#@#$#@ 583 | @#$#@#$#@ 584 | @#$#@#$#@ 585 | default 586 | 0.0 587 | -0.2 0 0.0 1.0 588 | 0.0 1 1.0 0.0 589 | 0.2 0 0.0 1.0 590 | link direction 591 | true 592 | 0 593 | Line -7500403 true 150 150 90 180 594 | Line -7500403 true 150 150 210 180 595 | @#$#@#$#@ 596 | 0 597 | @#$#@#$#@ 598 | -------------------------------------------------------------------------------- /ch06_cooperation/PD_randomized.nlogo: -------------------------------------------------------------------------------- 1 | ;; Simple prisoner's dilemma game with pure strategies played with neighbors. 2 | ;; This model introduces randomization to spatial location, which disrupts assortment 3 | 4 | turtles-own [ 5 | strategy ;0=defector, 1=cooperator 6 | payoff ;;payoff 7 | ] 8 | 9 | ;;----SETUP PROCEDURES--------------------- 10 | 11 | to setup 12 | clear-all 13 | make-agents 14 | reset-ticks 15 | end 16 | 17 | ;;create agents, one on each patch. Make some of them cooperators 18 | to make-agents 19 | ask patches [ 20 | sprout 1 [ 21 | ifelse random-float 1 < init-coop-freq 22 | [ set strategy 1 ] 23 | [ set strategy 0 ] 24 | set shape "circle" 25 | set payoff 0 26 | ] 27 | ] 28 | recolor 29 | end 30 | 31 | ;;recolor agents based on strategy 32 | ;;red = defector, blue = cooperator 33 | to recolor 34 | ask turtles[ 35 | if strategy = 0 36 | [ set color red] 37 | if strategy = 1 38 | [ set color blue] 39 | ] 40 | end 41 | 42 | 43 | 44 | ;;----DYNAMICS PROCEDURES--------------------- 45 | 46 | to go 47 | if (all? turtles [strategy = 0] or all? turtles [strategy = 1]) [stop] ;;stop if one strategy has "won" 48 | randomize-locations ;;agents move around to prevent assortment of similar strategies 49 | play-game ;;agents play the game with neighbors and receive payoffs 50 | evolve ;;agents copy the strategy of their most successful neighbor 51 | recolor ;;recolor agents to match their strategy 52 | tick 53 | end 54 | 55 | 56 | ;;have each turtle switch locations with a random other turtle with some probability 57 | to randomize-locations 58 | ask turtles [ 59 | if random-float 1 < randomization-prob [ 60 | let my-x xcor 61 | let my-y ycor 62 | let partner one-of other turtles 63 | let their-x [xcor] of partner 64 | let their-y [ycor] of partner 65 | set xcor their-x 66 | set ycor their-y 67 | ask partner [ 68 | set xcor my-x 69 | set ycor my-y 70 | ] 71 | ] 72 | ] 73 | end 74 | 75 | 76 | ;;each agent plays the PD game with each of its 4 closest neighbors and accumulates payoff 77 | to play-game 78 | ask turtles [ 79 | set payoff 0;;reset payoff for this time step 80 | 81 | ;count neighbors with each strategy 82 | let neighbors-C count (turtles-on neighbors4) with [strategy = 1] 83 | let neighbors-D count (turtles-on neighbors4) with [strategy = 0] 84 | 85 | ;if I'm a cooperator 86 | if (strategy = 1) 87 | [ set payoff (neighbors-C * (payoff-benefit - payoff-cost) - neighbors-D * payoff-cost) ] 88 | 89 | ;if I'm a defector 90 | if (strategy = 0) 91 | [ set payoff (neighbors-C * payoff-benefit) ] 92 | ] 93 | end 94 | 95 | ;;each agent imitates their most successful neighbor 96 | to evolve 97 | ask turtles[ 98 | let best-neighbor max-one-of (turtles-on neighbors4) [payoff] ;;who's my neighbor with the highest payoff 99 | if ([payoff] of best-neighbor) > payoff ;;if their payoff is better than mine, imitate them 100 | [set strategy [strategy] of best-neighbor] 101 | ] 102 | end 103 | 104 | 105 | ; Copyright 2023 Paul E. Smaldino. 106 | ; See Info tab for full copyright and license. 107 | @#$#@#$#@ 108 | GRAPHICS-WINDOW 109 | 235 110 | 18 111 | 562 112 | 346 113 | -1 114 | -1 115 | 10.3 116 | 1 117 | 10 118 | 1 119 | 1 120 | 1 121 | 0 122 | 1 123 | 1 124 | 1 125 | -15 126 | 15 127 | -15 128 | 15 129 | 0 130 | 0 131 | 1 132 | ticks 133 | 30.0 134 | 135 | SLIDER 136 | 46 137 | 104 138 | 225 139 | 137 140 | init-coop-freq 141 | init-coop-freq 142 | 0 143 | 1 144 | 0.5 145 | .01 146 | 1 147 | NIL 148 | HORIZONTAL 149 | 150 | SLIDER 151 | 46 152 | 146 153 | 225 154 | 179 155 | payoff-benefit 156 | payoff-benefit 157 | 0 158 | 1 159 | 1.0 160 | .01 161 | 1 162 | NIL 163 | HORIZONTAL 164 | 165 | SLIDER 166 | 46 167 | 188 168 | 226 169 | 221 170 | payoff-cost 171 | payoff-cost 172 | 0 173 | 1 174 | 0.2 175 | .01 176 | 1 177 | NIL 178 | HORIZONTAL 179 | 180 | BUTTON 181 | 47 182 | 18 183 | 136 184 | 51 185 | NIL 186 | setup 187 | NIL 188 | 1 189 | T 190 | OBSERVER 191 | NIL 192 | NIL 193 | NIL 194 | NIL 195 | 1 196 | 197 | BUTTON 198 | 144 199 | 18 200 | 218 201 | 51 202 | NIL 203 | go 204 | T 205 | 1 206 | T 207 | OBSERVER 208 | NIL 209 | NIL 210 | NIL 211 | NIL 212 | 0 213 | 214 | PLOT 215 | 568 216 | 19 217 | 883 218 | 346 219 | Frequency of Cooperation 220 | Time 221 | Cooperator frequency 222 | 0.0 223 | 10.0 224 | 0.0 225 | 1.0 226 | true 227 | false 228 | "" "" 229 | PENS 230 | "default" 1.0 0 -13345367 true "" "plot (count turtles with [strategy = 1]) / (count turtles)" 231 | 232 | BUTTON 233 | 91 234 | 58 235 | 172 236 | 91 237 | go once 238 | go 239 | NIL 240 | 1 241 | T 242 | OBSERVER 243 | NIL 244 | NIL 245 | NIL 246 | NIL 247 | 1 248 | 249 | SLIDER 250 | 47 251 | 231 252 | 226 253 | 264 254 | randomization-prob 255 | randomization-prob 256 | 0 257 | 1 258 | 0.08 259 | .01 260 | 1 261 | NIL 262 | HORIZONTAL 263 | 264 | @#$#@#$#@ 265 | ## Model Information and Materials 266 | 267 | This model is original material created by Paul E. Smaldino. 268 | 269 | ## References and Citation 270 | 271 | For this model: 272 | 273 | * Smaldino PE (2023). Prisoner's Dilemma Game: Randomized. Modeling Social Behavior. https://github.com/psmaldino/modsoc/ 274 | 275 | For the book: 276 | 277 | * Smaldino PE (2023). Modeling Social Behavior: Mathematical and Agent-Based Models of Social Dynamics and Cultural Evolution. Princeton University Press. 278 | 279 | For the NetLogo: 280 | 281 | * Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. 282 | 283 | 284 | ## Licence 285 | 286 | ![CC BY-NC-SA 4.0](http://ccl.northwestern.edu/images/creativecommons/byncsa.png) 287 | 288 | This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/ 289 | @#$#@#$#@ 290 | default 291 | true 292 | 0 293 | Polygon -7500403 true true 150 5 40 250 150 205 260 250 294 | 295 | airplane 296 | true 297 | 0 298 | Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 299 | 300 | arrow 301 | true 302 | 0 303 | Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 304 | 305 | box 306 | false 307 | 0 308 | Polygon -7500403 true true 150 285 285 225 285 75 150 135 309 | Polygon -7500403 true true 150 135 15 75 150 15 285 75 310 | Polygon -7500403 true true 15 75 15 225 150 285 150 135 311 | Line -16777216 false 150 285 150 135 312 | Line -16777216 false 150 135 15 75 313 | Line -16777216 false 150 135 285 75 314 | 315 | bug 316 | true 317 | 0 318 | Circle -7500403 true true 96 182 108 319 | Circle -7500403 true true 110 127 80 320 | Circle -7500403 true true 110 75 80 321 | Line -7500403 true 150 100 80 30 322 | Line -7500403 true 150 100 220 30 323 | 324 | butterfly 325 | true 326 | 0 327 | Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 328 | Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 329 | Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 330 | Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 331 | Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 332 | Circle -16777216 true false 135 90 30 333 | Line -16777216 false 150 105 195 60 334 | Line -16777216 false 150 105 105 60 335 | 336 | car 337 | false 338 | 0 339 | Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 340 | Circle -16777216 true false 180 180 90 341 | Circle -16777216 true false 30 180 90 342 | Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 343 | Circle -7500403 true true 47 195 58 344 | Circle -7500403 true true 195 195 58 345 | 346 | circle 347 | false 348 | 0 349 | Circle -7500403 true true 0 0 300 350 | 351 | circle 2 352 | false 353 | 0 354 | Circle -7500403 true true 0 0 300 355 | Circle -16777216 true false 30 30 240 356 | 357 | cow 358 | false 359 | 0 360 | Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 361 | Polygon -7500403 true true 73 210 86 251 62 249 48 208 362 | Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 363 | 364 | cylinder 365 | false 366 | 0 367 | Circle -7500403 true true 0 0 300 368 | 369 | dot 370 | false 371 | 0 372 | Circle -7500403 true true 90 90 120 373 | 374 | face happy 375 | false 376 | 0 377 | Circle -7500403 true true 8 8 285 378 | Circle -16777216 true false 60 75 60 379 | Circle -16777216 true false 180 75 60 380 | Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 381 | 382 | face neutral 383 | false 384 | 0 385 | Circle -7500403 true true 8 7 285 386 | Circle -16777216 true false 60 75 60 387 | Circle -16777216 true false 180 75 60 388 | Rectangle -16777216 true false 60 195 240 225 389 | 390 | face sad 391 | false 392 | 0 393 | Circle -7500403 true true 8 8 285 394 | Circle -16777216 true false 60 75 60 395 | Circle -16777216 true false 180 75 60 396 | Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 397 | 398 | fish 399 | false 400 | 0 401 | Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 402 | Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 403 | Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 404 | Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 405 | Circle -16777216 true false 215 106 30 406 | 407 | flag 408 | false 409 | 0 410 | Rectangle -7500403 true true 60 15 75 300 411 | Polygon -7500403 true true 90 150 270 90 90 30 412 | Line -7500403 true 75 135 90 135 413 | Line -7500403 true 75 45 90 45 414 | 415 | flower 416 | false 417 | 0 418 | Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 419 | Circle -7500403 true true 85 132 38 420 | Circle -7500403 true true 130 147 38 421 | Circle -7500403 true true 192 85 38 422 | Circle -7500403 true true 85 40 38 423 | Circle -7500403 true true 177 40 38 424 | Circle -7500403 true true 177 132 38 425 | Circle -7500403 true true 70 85 38 426 | Circle -7500403 true true 130 25 38 427 | Circle -7500403 true true 96 51 108 428 | Circle -16777216 true false 113 68 74 429 | Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 430 | Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 431 | 432 | house 433 | false 434 | 0 435 | Rectangle -7500403 true true 45 120 255 285 436 | Rectangle -16777216 true false 120 210 180 285 437 | Polygon -7500403 true true 15 120 150 15 285 120 438 | Line -16777216 false 30 120 270 120 439 | 440 | leaf 441 | false 442 | 0 443 | Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 444 | Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 445 | 446 | line 447 | true 448 | 0 449 | Line -7500403 true 150 0 150 300 450 | 451 | line half 452 | true 453 | 0 454 | Line -7500403 true 150 0 150 150 455 | 456 | pentagon 457 | false 458 | 0 459 | Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 460 | 461 | person 462 | false 463 | 0 464 | Circle -7500403 true true 110 5 80 465 | Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 466 | Rectangle -7500403 true true 127 79 172 94 467 | Polygon -7500403 true true 195 90 240 150 225 180 165 105 468 | Polygon -7500403 true true 105 90 60 150 75 180 135 105 469 | 470 | plant 471 | false 472 | 0 473 | Rectangle -7500403 true true 135 90 165 300 474 | Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 475 | Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 476 | Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 477 | Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 478 | Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 479 | Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 480 | Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 481 | 482 | sheep 483 | false 484 | 15 485 | Circle -1 true true 203 65 88 486 | Circle -1 true true 70 65 162 487 | Circle -1 true true 150 105 120 488 | Polygon -7500403 true false 218 120 240 165 255 165 278 120 489 | Circle -7500403 true false 214 72 67 490 | Rectangle -1 true true 164 223 179 298 491 | Polygon -1 true true 45 285 30 285 30 240 15 195 45 210 492 | Circle -1 true true 3 83 150 493 | Rectangle -1 true true 65 221 80 296 494 | Polygon -1 true true 195 285 210 285 210 240 240 210 195 210 495 | Polygon -7500403 true false 276 85 285 105 302 99 294 83 496 | Polygon -7500403 true false 219 85 210 105 193 99 201 83 497 | 498 | square 499 | false 500 | 0 501 | Rectangle -7500403 true true 30 30 270 270 502 | 503 | square 2 504 | false 505 | 0 506 | Rectangle -7500403 true true 30 30 270 270 507 | Rectangle -16777216 true false 60 60 240 240 508 | 509 | star 510 | false 511 | 0 512 | Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 513 | 514 | target 515 | false 516 | 0 517 | Circle -7500403 true true 0 0 300 518 | Circle -16777216 true false 30 30 240 519 | Circle -7500403 true true 60 60 180 520 | Circle -16777216 true false 90 90 120 521 | Circle -7500403 true true 120 120 60 522 | 523 | tree 524 | false 525 | 0 526 | Circle -7500403 true true 118 3 94 527 | Rectangle -6459832 true false 120 195 180 300 528 | Circle -7500403 true true 65 21 108 529 | Circle -7500403 true true 116 41 127 530 | Circle -7500403 true true 45 90 120 531 | Circle -7500403 true true 104 74 152 532 | 533 | triangle 534 | false 535 | 0 536 | Polygon -7500403 true true 150 30 15 255 285 255 537 | 538 | triangle 2 539 | false 540 | 0 541 | Polygon -7500403 true true 150 30 15 255 285 255 542 | Polygon -16777216 true false 151 99 225 223 75 224 543 | 544 | truck 545 | false 546 | 0 547 | Rectangle -7500403 true true 4 45 195 187 548 | Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 549 | Rectangle -1 true false 195 60 195 105 550 | Polygon -16777216 true false 238 112 252 141 219 141 218 112 551 | Circle -16777216 true false 234 174 42 552 | Rectangle -7500403 true true 181 185 214 194 553 | Circle -16777216 true false 144 174 42 554 | Circle -16777216 true false 24 174 42 555 | Circle -7500403 false true 24 174 42 556 | Circle -7500403 false true 144 174 42 557 | Circle -7500403 false true 234 174 42 558 | 559 | turtle 560 | true 561 | 0 562 | Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 563 | Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 564 | Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 565 | Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 566 | Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 567 | Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 568 | 569 | wheel 570 | false 571 | 0 572 | Circle -7500403 true true 3 3 294 573 | Circle -16777216 true false 30 30 240 574 | Line -7500403 true 150 285 150 15 575 | Line -7500403 true 15 150 285 150 576 | Circle -7500403 true true 120 120 60 577 | Line -7500403 true 216 40 79 269 578 | Line -7500403 true 40 84 269 221 579 | Line -7500403 true 40 216 269 79 580 | Line -7500403 true 84 40 221 269 581 | 582 | wolf 583 | false 584 | 0 585 | Polygon -16777216 true false 253 133 245 131 245 133 586 | Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105 587 | Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113 588 | 589 | x 590 | false 591 | 0 592 | Polygon -7500403 true true 270 75 225 30 30 225 75 270 593 | Polygon -7500403 true true 30 75 75 30 270 225 225 270 594 | @#$#@#$#@ 595 | NetLogo 6.2.2 596 | @#$#@#$#@ 597 | @#$#@#$#@ 598 | @#$#@#$#@ 599 | @#$#@#$#@ 600 | @#$#@#$#@ 601 | default 602 | 0.0 603 | -0.2 0 0.0 1.0 604 | 0.0 1 1.0 0.0 605 | 0.2 0 0.0 1.0 606 | link direction 607 | true 608 | 0 609 | Line -7500403 true 150 150 90 180 610 | Line -7500403 true 150 150 210 180 611 | @#$#@#$#@ 612 | 0 613 | @#$#@#$#@ 614 | -------------------------------------------------------------------------------- /ch07_coordination/coordination_simple.nlogo: -------------------------------------------------------------------------------- 1 | ;; A very simple coordination model. Everyone starts with one of two norms. 2 | ;; Agents calculate their expected payoff and then preferentially (probabilistically) copy those with higher payoffs. 3 | 4 | 5 | turtles-own [ 6 | norm1? ;;do I have norm 1? If false, norm 2. 7 | payoff 8 | ] 9 | 10 | ;; Create agents, one on each patch. Assign them one of two norms. 11 | to setup 12 | clear-all 13 | ask patches [ 14 | sprout 1 [ 15 | set shape "circle" 16 | ifelse random-float 1 < init-norm1 17 | [set norm1? true] 18 | [set norm1? false] 19 | ] 20 | ] 21 | recolor 22 | reset-ticks 23 | end 24 | 25 | 26 | to go 27 | ;;stop simulation if all agents are using the same norm 28 | if (count turtles with [norm1?]) = (count turtles) or 29 | (count turtles with [norm1?]) = 0 30 | [ stop ] 31 | 32 | calculate-payoffs ;;interactions and payoffs 33 | evolve ;;success-biased imitation 34 | recolor 35 | tick 36 | end 37 | 38 | ;;calculate expected payoff for all possible interactions 39 | to calculate-payoffs 40 | let p1 (count turtles with [norm1?]) / (count turtles) 41 | 42 | let norm1-payoff 1 + (p1 * coordination-benefit) 43 | let norm2-payoff 1 + ((1 - p1) * coordination-benefit) 44 | 45 | ask turtles with [norm1?][ ;;calculate payoffs for the norm 1 agents 46 | set payoff norm1-payoff 47 | ] 48 | ask turtles with [not norm1?][ ;;calculate payoffs for the norm 1 agents 49 | set payoff norm2-payoff 50 | ] 51 | end 52 | 53 | ;; observe another agent at random, and probabilistically copy their strategy to the extent their payoff 54 | ;; is higher than my own 55 | to evolve 56 | ask turtles[ 57 | let model one-of other turtles 58 | if [norm1?] of model != [norm1?] of self[ 59 | let other-payoff [payoff] of model 60 | let prob-copy (1 / (1 + exp (-1 * (other-payoff - payoff)))) 61 | if random-float 1 < prob-copy 62 | [set norm1? [norm1?] of model] 63 | ] 64 | ] 65 | end 66 | 67 | ;; recolor agents based on norm. 68 | ;; yellow = norm 1, blue = norm 2 69 | to recolor 70 | ask turtles[ 71 | ifelse norm1? 72 | [set color yellow] 73 | [set color blue] 74 | ] 75 | end 76 | 77 | 78 | to-report freq-norm1 79 | report (count turtles with [norm1?]) / (count turtles) 80 | end 81 | 82 | ; Copyright 2023 Paul E. Smaldino. 83 | ; See Info tab for full copyright and license. 84 | @#$#@#$#@ 85 | GRAPHICS-WINDOW 86 | 230 87 | 16 88 | 492 89 | 279 90 | -1 91 | -1 92 | 8.2 93 | 1 94 | 10 95 | 1 96 | 1 97 | 1 98 | 0 99 | 1 100 | 1 101 | 1 102 | -15 103 | 15 104 | -15 105 | 15 106 | 0 107 | 0 108 | 1 109 | ticks 110 | 30.0 111 | 112 | BUTTON 113 | 42 114 | 19 115 | 127 116 | 52 117 | NIL 118 | setup 119 | NIL 120 | 1 121 | T 122 | OBSERVER 123 | NIL 124 | NIL 125 | NIL 126 | NIL 127 | 1 128 | 129 | BUTTON 130 | 132 131 | 19 132 | 215 133 | 52 134 | NIL 135 | go 136 | T 137 | 1 138 | T 139 | OBSERVER 140 | NIL 141 | NIL 142 | NIL 143 | NIL 144 | 1 145 | 146 | SLIDER 147 | 44 148 | 74 149 | 216 150 | 107 151 | init-norm1 152 | init-norm1 153 | 0 154 | 1 155 | 0.5 156 | .01 157 | 1 158 | NIL 159 | HORIZONTAL 160 | 161 | PLOT 162 | 509 163 | 27 164 | 799 165 | 272 166 | Norms 167 | time 168 | Frequency of norm 1 169 | 0.0 170 | 10.0 171 | 0.0 172 | 1.0 173 | true 174 | false 175 | "" "" 176 | PENS 177 | "Freq Norm 1" 1.0 0 -7171555 true "" "plot (count turtles with [norm1?]) / (count turtles)" 178 | 179 | SLIDER 180 | 44 181 | 114 182 | 216 183 | 147 184 | coordination-benefit 185 | coordination-benefit 186 | 0 187 | 5 188 | 1.0 189 | .1 190 | 1 191 | NIL 192 | HORIZONTAL 193 | 194 | @#$#@#$#@ 195 | ## Model Information and Materials 196 | 197 | This model is original material created by Paul E. Smaldino. 198 | 199 | ## References and Citation 200 | 201 | For this model: 202 | 203 | * Smaldino PE (2023). Coordination: Simple. Modeling Social Behavior. https://github.com/psmaldino/modsoc/ 204 | 205 | For the book: 206 | 207 | * Smaldino PE (2023). Modeling Social Behavior: Mathematical and Agent-Based Models of Social Dynamics and Cultural Evolution. Princeton University Press. 208 | 209 | For the NetLogo: 210 | 211 | * Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. 212 | 213 | 214 | ## Licence 215 | 216 | ![CC BY-NC-SA 4.0](http://ccl.northwestern.edu/images/creativecommons/byncsa.png) 217 | 218 | This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/ 219 | @#$#@#$#@ 220 | default 221 | true 222 | 0 223 | Polygon -7500403 true true 150 5 40 250 150 205 260 250 224 | 225 | airplane 226 | true 227 | 0 228 | Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 229 | 230 | arrow 231 | true 232 | 0 233 | Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 234 | 235 | box 236 | false 237 | 0 238 | Polygon -7500403 true true 150 285 285 225 285 75 150 135 239 | Polygon -7500403 true true 150 135 15 75 150 15 285 75 240 | Polygon -7500403 true true 15 75 15 225 150 285 150 135 241 | Line -16777216 false 150 285 150 135 242 | Line -16777216 false 150 135 15 75 243 | Line -16777216 false 150 135 285 75 244 | 245 | bug 246 | true 247 | 0 248 | Circle -7500403 true true 96 182 108 249 | Circle -7500403 true true 110 127 80 250 | Circle -7500403 true true 110 75 80 251 | Line -7500403 true 150 100 80 30 252 | Line -7500403 true 150 100 220 30 253 | 254 | butterfly 255 | true 256 | 0 257 | Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 258 | Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 259 | Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 260 | Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 261 | Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 262 | Circle -16777216 true false 135 90 30 263 | Line -16777216 false 150 105 195 60 264 | Line -16777216 false 150 105 105 60 265 | 266 | car 267 | false 268 | 0 269 | Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 270 | Circle -16777216 true false 180 180 90 271 | Circle -16777216 true false 30 180 90 272 | Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 273 | Circle -7500403 true true 47 195 58 274 | Circle -7500403 true true 195 195 58 275 | 276 | circle 277 | false 278 | 0 279 | Circle -7500403 true true 0 0 300 280 | 281 | circle 2 282 | false 283 | 0 284 | Circle -7500403 true true 0 0 300 285 | Circle -16777216 true false 30 30 240 286 | 287 | cow 288 | false 289 | 0 290 | Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 291 | Polygon -7500403 true true 73 210 86 251 62 249 48 208 292 | Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 293 | 294 | cylinder 295 | false 296 | 0 297 | Circle -7500403 true true 0 0 300 298 | 299 | dot 300 | false 301 | 0 302 | Circle -7500403 true true 90 90 120 303 | 304 | face happy 305 | false 306 | 0 307 | Circle -7500403 true true 8 8 285 308 | Circle -16777216 true false 60 75 60 309 | Circle -16777216 true false 180 75 60 310 | Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 311 | 312 | face neutral 313 | false 314 | 0 315 | Circle -7500403 true true 8 7 285 316 | Circle -16777216 true false 60 75 60 317 | Circle -16777216 true false 180 75 60 318 | Rectangle -16777216 true false 60 195 240 225 319 | 320 | face sad 321 | false 322 | 0 323 | Circle -7500403 true true 8 8 285 324 | Circle -16777216 true false 60 75 60 325 | Circle -16777216 true false 180 75 60 326 | Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 327 | 328 | fish 329 | false 330 | 0 331 | Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 332 | Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 333 | Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 334 | Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 335 | Circle -16777216 true false 215 106 30 336 | 337 | flag 338 | false 339 | 0 340 | Rectangle -7500403 true true 60 15 75 300 341 | Polygon -7500403 true true 90 150 270 90 90 30 342 | Line -7500403 true 75 135 90 135 343 | Line -7500403 true 75 45 90 45 344 | 345 | flower 346 | false 347 | 0 348 | Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 349 | Circle -7500403 true true 85 132 38 350 | Circle -7500403 true true 130 147 38 351 | Circle -7500403 true true 192 85 38 352 | Circle -7500403 true true 85 40 38 353 | Circle -7500403 true true 177 40 38 354 | Circle -7500403 true true 177 132 38 355 | Circle -7500403 true true 70 85 38 356 | Circle -7500403 true true 130 25 38 357 | Circle -7500403 true true 96 51 108 358 | Circle -16777216 true false 113 68 74 359 | Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 360 | Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 361 | 362 | house 363 | false 364 | 0 365 | Rectangle -7500403 true true 45 120 255 285 366 | Rectangle -16777216 true false 120 210 180 285 367 | Polygon -7500403 true true 15 120 150 15 285 120 368 | Line -16777216 false 30 120 270 120 369 | 370 | leaf 371 | false 372 | 0 373 | Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 374 | Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 375 | 376 | line 377 | true 378 | 0 379 | Line -7500403 true 150 0 150 300 380 | 381 | line half 382 | true 383 | 0 384 | Line -7500403 true 150 0 150 150 385 | 386 | pentagon 387 | false 388 | 0 389 | Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 390 | 391 | person 392 | false 393 | 0 394 | Circle -7500403 true true 110 5 80 395 | Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 396 | Rectangle -7500403 true true 127 79 172 94 397 | Polygon -7500403 true true 195 90 240 150 225 180 165 105 398 | Polygon -7500403 true true 105 90 60 150 75 180 135 105 399 | 400 | plant 401 | false 402 | 0 403 | Rectangle -7500403 true true 135 90 165 300 404 | Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 405 | Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 406 | Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 407 | Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 408 | Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 409 | Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 410 | Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 411 | 412 | sheep 413 | false 414 | 15 415 | Circle -1 true true 203 65 88 416 | Circle -1 true true 70 65 162 417 | Circle -1 true true 150 105 120 418 | Polygon -7500403 true false 218 120 240 165 255 165 278 120 419 | Circle -7500403 true false 214 72 67 420 | Rectangle -1 true true 164 223 179 298 421 | Polygon -1 true true 45 285 30 285 30 240 15 195 45 210 422 | Circle -1 true true 3 83 150 423 | Rectangle -1 true true 65 221 80 296 424 | Polygon -1 true true 195 285 210 285 210 240 240 210 195 210 425 | Polygon -7500403 true false 276 85 285 105 302 99 294 83 426 | Polygon -7500403 true false 219 85 210 105 193 99 201 83 427 | 428 | square 429 | false 430 | 0 431 | Rectangle -7500403 true true 30 30 270 270 432 | 433 | square 2 434 | false 435 | 0 436 | Rectangle -7500403 true true 30 30 270 270 437 | Rectangle -16777216 true false 60 60 240 240 438 | 439 | star 440 | false 441 | 0 442 | Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 443 | 444 | target 445 | false 446 | 0 447 | Circle -7500403 true true 0 0 300 448 | Circle -16777216 true false 30 30 240 449 | Circle -7500403 true true 60 60 180 450 | Circle -16777216 true false 90 90 120 451 | Circle -7500403 true true 120 120 60 452 | 453 | tree 454 | false 455 | 0 456 | Circle -7500403 true true 118 3 94 457 | Rectangle -6459832 true false 120 195 180 300 458 | Circle -7500403 true true 65 21 108 459 | Circle -7500403 true true 116 41 127 460 | Circle -7500403 true true 45 90 120 461 | Circle -7500403 true true 104 74 152 462 | 463 | triangle 464 | false 465 | 0 466 | Polygon -7500403 true true 150 30 15 255 285 255 467 | 468 | triangle 2 469 | false 470 | 0 471 | Polygon -7500403 true true 150 30 15 255 285 255 472 | Polygon -16777216 true false 151 99 225 223 75 224 473 | 474 | truck 475 | false 476 | 0 477 | Rectangle -7500403 true true 4 45 195 187 478 | Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 479 | Rectangle -1 true false 195 60 195 105 480 | Polygon -16777216 true false 238 112 252 141 219 141 218 112 481 | Circle -16777216 true false 234 174 42 482 | Rectangle -7500403 true true 181 185 214 194 483 | Circle -16777216 true false 144 174 42 484 | Circle -16777216 true false 24 174 42 485 | Circle -7500403 false true 24 174 42 486 | Circle -7500403 false true 144 174 42 487 | Circle -7500403 false true 234 174 42 488 | 489 | turtle 490 | true 491 | 0 492 | Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 493 | Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 494 | Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 495 | Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 496 | Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 497 | Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 498 | 499 | wheel 500 | false 501 | 0 502 | Circle -7500403 true true 3 3 294 503 | Circle -16777216 true false 30 30 240 504 | Line -7500403 true 150 285 150 15 505 | Line -7500403 true 15 150 285 150 506 | Circle -7500403 true true 120 120 60 507 | Line -7500403 true 216 40 79 269 508 | Line -7500403 true 40 84 269 221 509 | Line -7500403 true 40 216 269 79 510 | Line -7500403 true 84 40 221 269 511 | 512 | wolf 513 | false 514 | 0 515 | Polygon -16777216 true false 253 133 245 131 245 133 516 | Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105 517 | Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113 518 | 519 | x 520 | false 521 | 0 522 | Polygon -7500403 true true 270 75 225 30 30 225 75 270 523 | Polygon -7500403 true true 30 75 75 30 270 225 225 270 524 | @#$#@#$#@ 525 | NetLogo 6.2.2 526 | @#$#@#$#@ 527 | @#$#@#$#@ 528 | @#$#@#$#@ 529 | 530 | 531 | setup 532 | go 533 | 534 | count turtles with [norm1?] 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | setup 556 | go 557 | freq-norm1 558 | 559 | 560 | 561 | 562 | 563 | 564 | @#$#@#$#@ 565 | @#$#@#$#@ 566 | default 567 | 0.0 568 | -0.2 0 0.0 1.0 569 | 0.0 1 1.0 0.0 570 | 0.2 0 0.0 1.0 571 | link direction 572 | true 573 | 0 574 | Line -7500403 true 150 150 90 180 575 | Line -7500403 true 150 150 210 180 576 | @#$#@#$#@ 577 | 0 578 | @#$#@#$#@ 579 | -------------------------------------------------------------------------------- /ch08_science/science_pub-bias.nlogo: -------------------------------------------------------------------------------- 1 | globals [ 2 | prob-true 3 | canonized-true 4 | ] 5 | 6 | to setup 7 | clear-all 8 | set prob-true initial-prior 9 | ifelse true-hypothesis? ;;Color patches with initial epistemic state 10 | [ask patches [set pcolor green]] 11 | [ask patches [set pcolor red]] 12 | reset-ticks 13 | end 14 | 15 | 16 | to go 17 | ;;Check if fact is ready for canonization 18 | if prob-true >= canonization-threshold [ ;;canonized TRUE! 19 | set canonized-true 1 20 | stop 21 | ] 22 | if prob-true <= (1 - canonization-threshold) [ ;;canonized FALSE! 23 | set canonized-true 0 24 | stop 25 | ] 26 | 27 | ;;otherwise, gather evidence and update the hypothesis 28 | update-hypothesis 29 | tick 30 | end 31 | 32 | 33 | to update-hypothesis 34 | ;;hypothesis is actually true 35 | ifelse true-hypothesis? [ 36 | ;;true positive -- ALWAYS PUBLISH 37 | ifelse random-float 1 < power [ 38 | ask patches [set pcolor green] 39 | set prob-true (power * prob-true) / ((power * prob-true) + (false-positive-rate * (1 - prob-true))) 40 | ] 41 | ;;false negative -- PUB BIAS 42 | [ 43 | ask patches [set pcolor red] 44 | if (random-float 1 < (1 - pub-bias))[ 45 | set prob-true ((1 - power) * prob-true) / (((1 - power) * prob-true) + ((1 - false-positive-rate) * (1 - prob-true))) 46 | ] 47 | ] 48 | ] 49 | ;;hypothesis is actually false 50 | [ 51 | ;;false positive -- ALWAYS PUBLISH 52 | ifelse random-float 1 < false-positive-rate [ 53 | ask patches [set pcolor green] 54 | set prob-true (power * prob-true) / ((power * prob-true) + (false-positive-rate * (1 - prob-true))) 55 | ] 56 | ;;false negative -- PUB BIAS 57 | [ 58 | ask patches [set pcolor red] 59 | if (random-float 1 < (1 - pub-bias))[ 60 | set prob-true ((1 - power) * prob-true) / (((1 - power) * prob-true) + ((1 - false-positive-rate) * (1 - prob-true))) 61 | ] 62 | ] 63 | ] 64 | end 65 | 66 | 67 | ; Copyright 2023 Paul E. Smaldino. 68 | ; See Info tab for full copyright and license. 69 | @#$#@#$#@ 70 | GRAPHICS-WINDOW 71 | 205 72 | 11 73 | 515 74 | 63 75 | -1 76 | -1 77 | 14.4 78 | 1 79 | 10 80 | 1 81 | 1 82 | 1 83 | 0 84 | 1 85 | 1 86 | 1 87 | -10 88 | 10 89 | -1 90 | 1 91 | 1 92 | 1 93 | 1 94 | ticks 95 | 30.0 96 | 97 | BUTTON 98 | 20 99 | 21 100 | 94 101 | 54 102 | NIL 103 | setup 104 | NIL 105 | 1 106 | T 107 | OBSERVER 108 | NIL 109 | NIL 110 | NIL 111 | NIL 112 | 1 113 | 114 | BUTTON 115 | 99 116 | 21 117 | 180 118 | 54 119 | go once 120 | go 121 | NIL 122 | 1 123 | T 124 | OBSERVER 125 | NIL 126 | NIL 127 | NIL 128 | NIL 129 | 0 130 | 131 | SLIDER 132 | 16 133 | 94 134 | 189 135 | 127 136 | initial-prior 137 | initial-prior 138 | 0 139 | 1 140 | 0.5 141 | .001 142 | 1 143 | NIL 144 | HORIZONTAL 145 | 146 | SLIDER 147 | 16 148 | 137 149 | 188 150 | 170 151 | false-positive-rate 152 | false-positive-rate 153 | 0 154 | 1 155 | 0.25 156 | .001 157 | 1 158 | NIL 159 | HORIZONTAL 160 | 161 | SLIDER 162 | 16 163 | 181 164 | 189 165 | 214 166 | power 167 | power 168 | 0 169 | 1 170 | 0.8 171 | .001 172 | 1 173 | NIL 174 | HORIZONTAL 175 | 176 | SWITCH 177 | 17 178 | 225 179 | 189 180 | 258 181 | true-hypothesis? 182 | true-hypothesis? 183 | 1 184 | 1 185 | -1000 186 | 187 | PLOT 188 | 205 189 | 69 190 | 516 191 | 261 192 | Probability of True Hypothesis 193 | time 194 | Pr(true) 195 | 0.0 196 | 10.0 197 | 0.0 198 | 1.0 199 | true 200 | false 201 | "" "" 202 | PENS 203 | "default" 1.0 0 -16777216 true "" "plot prob-true" 204 | 205 | TEXTBOX 206 | 325 207 | 26 208 | 656 209 | 131 210 | RESULT 211 | 18 212 | 9.0 213 | 1 214 | 215 | SLIDER 216 | 16 217 | 266 218 | 188 219 | 299 220 | pub-bias 221 | pub-bias 222 | 0 223 | 1 224 | 1.0 225 | .001 226 | 1 227 | NIL 228 | HORIZONTAL 229 | 230 | SLIDER 231 | 16 232 | 310 233 | 216 234 | 343 235 | canonization-threshold 236 | canonization-threshold 237 | 0 238 | 1 239 | 0.999 240 | .001 241 | 1 242 | NIL 243 | HORIZONTAL 244 | 245 | BUTTON 246 | 22 247 | 57 248 | 176 249 | 90 250 | NIL 251 | go 252 | T 253 | 1 254 | T 255 | OBSERVER 256 | NIL 257 | NIL 258 | NIL 259 | NIL 260 | 0 261 | 262 | @#$#@#$#@ 263 | ## Model Information and Materials 264 | 265 | This model is original material created by Paul E. Smaldino. The model is based on work by Nissen et al. (2016). 266 | 267 | * Nissen SB, Magidson T, Gross K, Bergstrom CT. (2016). Publication bias and the canonization of false facts. eLife 5, e21451. 268 | 269 | ## References and Citation 270 | 271 | For this model: 272 | 273 | * Smaldino PE (2023). Science with Publication Bias. Modeling Social Behavior. https://github.com/psmaldino/modsoc/ 274 | 275 | For the book: 276 | 277 | * Smaldino PE (2023). Modeling Social Behavior: Mathematical and Agent-Based Models of Social Dynamics and Cultural Evolution. Princeton University Press. 278 | 279 | For the NetLogo: 280 | 281 | * Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. 282 | 283 | 284 | ## Licence 285 | 286 | ![CC BY-NC-SA 4.0](http://ccl.northwestern.edu/images/creativecommons/byncsa.png) 287 | 288 | This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/ 289 | @#$#@#$#@ 290 | default 291 | true 292 | 0 293 | Polygon -7500403 true true 150 5 40 250 150 205 260 250 294 | 295 | airplane 296 | true 297 | 0 298 | Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 299 | 300 | arrow 301 | true 302 | 0 303 | Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 304 | 305 | box 306 | false 307 | 0 308 | Polygon -7500403 true true 150 285 285 225 285 75 150 135 309 | Polygon -7500403 true true 150 135 15 75 150 15 285 75 310 | Polygon -7500403 true true 15 75 15 225 150 285 150 135 311 | Line -16777216 false 150 285 150 135 312 | Line -16777216 false 150 135 15 75 313 | Line -16777216 false 150 135 285 75 314 | 315 | bug 316 | true 317 | 0 318 | Circle -7500403 true true 96 182 108 319 | Circle -7500403 true true 110 127 80 320 | Circle -7500403 true true 110 75 80 321 | Line -7500403 true 150 100 80 30 322 | Line -7500403 true 150 100 220 30 323 | 324 | butterfly 325 | true 326 | 0 327 | Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 328 | Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 329 | Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 330 | Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 331 | Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 332 | Circle -16777216 true false 135 90 30 333 | Line -16777216 false 150 105 195 60 334 | Line -16777216 false 150 105 105 60 335 | 336 | car 337 | false 338 | 0 339 | Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 340 | Circle -16777216 true false 180 180 90 341 | Circle -16777216 true false 30 180 90 342 | Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 343 | Circle -7500403 true true 47 195 58 344 | Circle -7500403 true true 195 195 58 345 | 346 | circle 347 | false 348 | 0 349 | Circle -7500403 true true 0 0 300 350 | 351 | circle 2 352 | false 353 | 0 354 | Circle -7500403 true true 0 0 300 355 | Circle -16777216 true false 30 30 240 356 | 357 | cow 358 | false 359 | 0 360 | Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 361 | Polygon -7500403 true true 73 210 86 251 62 249 48 208 362 | Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 363 | 364 | cylinder 365 | false 366 | 0 367 | Circle -7500403 true true 0 0 300 368 | 369 | dot 370 | false 371 | 0 372 | Circle -7500403 true true 90 90 120 373 | 374 | face happy 375 | false 376 | 0 377 | Circle -7500403 true true 8 8 285 378 | Circle -16777216 true false 60 75 60 379 | Circle -16777216 true false 180 75 60 380 | Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 381 | 382 | face neutral 383 | false 384 | 0 385 | Circle -7500403 true true 8 7 285 386 | Circle -16777216 true false 60 75 60 387 | Circle -16777216 true false 180 75 60 388 | Rectangle -16777216 true false 60 195 240 225 389 | 390 | face sad 391 | false 392 | 0 393 | Circle -7500403 true true 8 8 285 394 | Circle -16777216 true false 60 75 60 395 | Circle -16777216 true false 180 75 60 396 | Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 397 | 398 | fish 399 | false 400 | 0 401 | Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 402 | Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 403 | Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 404 | Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 405 | Circle -16777216 true false 215 106 30 406 | 407 | flag 408 | false 409 | 0 410 | Rectangle -7500403 true true 60 15 75 300 411 | Polygon -7500403 true true 90 150 270 90 90 30 412 | Line -7500403 true 75 135 90 135 413 | Line -7500403 true 75 45 90 45 414 | 415 | flower 416 | false 417 | 0 418 | Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 419 | Circle -7500403 true true 85 132 38 420 | Circle -7500403 true true 130 147 38 421 | Circle -7500403 true true 192 85 38 422 | Circle -7500403 true true 85 40 38 423 | Circle -7500403 true true 177 40 38 424 | Circle -7500403 true true 177 132 38 425 | Circle -7500403 true true 70 85 38 426 | Circle -7500403 true true 130 25 38 427 | Circle -7500403 true true 96 51 108 428 | Circle -16777216 true false 113 68 74 429 | Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 430 | Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 431 | 432 | house 433 | false 434 | 0 435 | Rectangle -7500403 true true 45 120 255 285 436 | Rectangle -16777216 true false 120 210 180 285 437 | Polygon -7500403 true true 15 120 150 15 285 120 438 | Line -16777216 false 30 120 270 120 439 | 440 | leaf 441 | false 442 | 0 443 | Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 444 | Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 445 | 446 | line 447 | true 448 | 0 449 | Line -7500403 true 150 0 150 300 450 | 451 | line half 452 | true 453 | 0 454 | Line -7500403 true 150 0 150 150 455 | 456 | pentagon 457 | false 458 | 0 459 | Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 460 | 461 | person 462 | false 463 | 0 464 | Circle -7500403 true true 110 5 80 465 | Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 466 | Rectangle -7500403 true true 127 79 172 94 467 | Polygon -7500403 true true 195 90 240 150 225 180 165 105 468 | Polygon -7500403 true true 105 90 60 150 75 180 135 105 469 | 470 | plant 471 | false 472 | 0 473 | Rectangle -7500403 true true 135 90 165 300 474 | Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 475 | Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 476 | Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 477 | Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 478 | Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 479 | Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 480 | Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 481 | 482 | sheep 483 | false 484 | 15 485 | Circle -1 true true 203 65 88 486 | Circle -1 true true 70 65 162 487 | Circle -1 true true 150 105 120 488 | Polygon -7500403 true false 218 120 240 165 255 165 278 120 489 | Circle -7500403 true false 214 72 67 490 | Rectangle -1 true true 164 223 179 298 491 | Polygon -1 true true 45 285 30 285 30 240 15 195 45 210 492 | Circle -1 true true 3 83 150 493 | Rectangle -1 true true 65 221 80 296 494 | Polygon -1 true true 195 285 210 285 210 240 240 210 195 210 495 | Polygon -7500403 true false 276 85 285 105 302 99 294 83 496 | Polygon -7500403 true false 219 85 210 105 193 99 201 83 497 | 498 | square 499 | false 500 | 0 501 | Rectangle -7500403 true true 30 30 270 270 502 | 503 | square 2 504 | false 505 | 0 506 | Rectangle -7500403 true true 30 30 270 270 507 | Rectangle -16777216 true false 60 60 240 240 508 | 509 | star 510 | false 511 | 0 512 | Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 513 | 514 | target 515 | false 516 | 0 517 | Circle -7500403 true true 0 0 300 518 | Circle -16777216 true false 30 30 240 519 | Circle -7500403 true true 60 60 180 520 | Circle -16777216 true false 90 90 120 521 | Circle -7500403 true true 120 120 60 522 | 523 | tree 524 | false 525 | 0 526 | Circle -7500403 true true 118 3 94 527 | Rectangle -6459832 true false 120 195 180 300 528 | Circle -7500403 true true 65 21 108 529 | Circle -7500403 true true 116 41 127 530 | Circle -7500403 true true 45 90 120 531 | Circle -7500403 true true 104 74 152 532 | 533 | triangle 534 | false 535 | 0 536 | Polygon -7500403 true true 150 30 15 255 285 255 537 | 538 | triangle 2 539 | false 540 | 0 541 | Polygon -7500403 true true 150 30 15 255 285 255 542 | Polygon -16777216 true false 151 99 225 223 75 224 543 | 544 | truck 545 | false 546 | 0 547 | Rectangle -7500403 true true 4 45 195 187 548 | Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 549 | Rectangle -1 true false 195 60 195 105 550 | Polygon -16777216 true false 238 112 252 141 219 141 218 112 551 | Circle -16777216 true false 234 174 42 552 | Rectangle -7500403 true true 181 185 214 194 553 | Circle -16777216 true false 144 174 42 554 | Circle -16777216 true false 24 174 42 555 | Circle -7500403 false true 24 174 42 556 | Circle -7500403 false true 144 174 42 557 | Circle -7500403 false true 234 174 42 558 | 559 | turtle 560 | true 561 | 0 562 | Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 563 | Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 564 | Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 565 | Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 566 | Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 567 | Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 568 | 569 | wheel 570 | false 571 | 0 572 | Circle -7500403 true true 3 3 294 573 | Circle -16777216 true false 30 30 240 574 | Line -7500403 true 150 285 150 15 575 | Line -7500403 true 15 150 285 150 576 | Circle -7500403 true true 120 120 60 577 | Line -7500403 true 216 40 79 269 578 | Line -7500403 true 40 84 269 221 579 | Line -7500403 true 40 216 269 79 580 | Line -7500403 true 84 40 221 269 581 | 582 | wolf 583 | false 584 | 0 585 | Polygon -16777216 true false 253 133 245 131 245 133 586 | Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105 587 | Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113 588 | 589 | x 590 | false 591 | 0 592 | Polygon -7500403 true true 270 75 225 30 30 225 75 270 593 | Polygon -7500403 true true 30 75 75 30 270 225 225 270 594 | @#$#@#$#@ 595 | NetLogo 6.2.2 596 | @#$#@#$#@ 597 | @#$#@#$#@ 598 | @#$#@#$#@ 599 | 600 | 601 | setup 602 | go 603 | 604 | canonized-true 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | @#$#@#$#@ 624 | @#$#@#$#@ 625 | default 626 | 0.0 627 | -0.2 0 0.0 1.0 628 | 0.0 1 1.0 0.0 629 | 0.2 0 0.0 1.0 630 | link direction 631 | true 632 | 0 633 | Line -7500403 true 150 150 90 180 634 | Line -7500403 true 150 150 210 180 635 | @#$#@#$#@ 636 | 0 637 | @#$#@#$#@ 638 | -------------------------------------------------------------------------------- /ch03_schelling/segregation.nlogo: -------------------------------------------------------------------------------- 1 | globals [ 2 | average-similarity ;; avg proportion of similar neighbors 3 | unhappiness ;; proprortion of the agents that are unhappy 4 | ] 5 | 6 | turtles-own [ 7 | happy? ;; are a sufficient proportion of my neighbors like me? 8 | prop-similar-neighbors ;;proportion of neighbors like me 9 | ] 10 | 11 | to setup 12 | clear-all 13 | make-turtles 14 | update-turtles 15 | update-globals 16 | reset-ticks 17 | end 18 | 19 | ;; create turtles on random patches. 20 | to make-turtles 21 | ask patches [ 22 | if random-float 1 < density [ ;; set the occupancy density 23 | sprout 1 [ 24 | set shape "square" 25 | set color one-of [yellow blue] 26 | ] 27 | ] 28 | ] 29 | end 30 | 31 | 32 | ;; run the model for one tick 33 | to go 34 | if all? turtles [ happy? ] [ stop ] 35 | move-unhappy-turtles 36 | update-turtles 37 | update-globals 38 | tick 39 | end 40 | 41 | ;; unhappy agemts try a new spot 42 | to move-unhappy-turtles 43 | ask turtles with [ not happy? ] 44 | [ move-to one-of patches with [not any? turtles-here] 45 | ] 46 | end 47 | 48 | ;;set turtles to unhapy if proportion of similar neighbors is below threshold, otherwise set to happy 49 | to update-turtles 50 | ask turtles [ 51 | ;; in next two lines, we use "neighbors" to test the eight patches 52 | ;; surrounding the current patch 53 | let similar-nearby count (turtles-on neighbors) with [ color = [ color ] of myself ] 54 | let total-nearby count (turtles-on neighbors) 55 | ifelse (total-nearby = 0) 56 | [set prop-similar-neighbors 1] ;;always happy if alone. 57 | [set prop-similar-neighbors (similar-nearby / total-nearby)] 58 | set happy? (prop-similar-neighbors >= similarity-threshold) 59 | ] 60 | end 61 | 62 | to update-globals 63 | let similar-neighbors sum [ prop-similar-neighbors ] of turtles 64 | set average-similarity (similar-neighbors / count turtles) 65 | set unhappiness (count turtles with [ not happy? ]) / (count turtles) 66 | end 67 | 68 | 69 | 70 | ; Copyright 2023 Paul E. Smaldino. 71 | ; See Info tab for full copyright and license. 72 | @#$#@#$#@ 73 | GRAPHICS-WINDOW 74 | 353 75 | 10 76 | 769 77 | 427 78 | -1 79 | -1 80 | 8.0 81 | 1 82 | 10 83 | 1 84 | 1 85 | 1 86 | 0 87 | 1 88 | 1 89 | 1 90 | -25 91 | 25 92 | -25 93 | 25 94 | 1 95 | 1 96 | 1 97 | ticks 98 | 30.0 99 | 100 | MONITOR 101 | 262 102 | 350 103 | 349 104 | 395 105 | unhappiness 106 | unhappiness 107 | 3 108 | 1 109 | 11 110 | 111 | MONITOR 112 | 262 113 | 191 114 | 331 115 | 236 116 | avg sim 117 | average-similarity 118 | 3 119 | 1 120 | 11 121 | 122 | PLOT 123 | 14 124 | 141 125 | 257 126 | 294 127 | Average Similarity 128 | time 129 | similarity 130 | 0.0 131 | 5.0 132 | 0.0 133 | 1.0 134 | true 135 | false 136 | "" "" 137 | PENS 138 | "percent" 1.0 0 -2674135 true "" "plot average-similarity" 139 | 140 | SLIDER 141 | 20 142 | 95 143 | 281 144 | 128 145 | similarity-threshold 146 | similarity-threshold 147 | 0 148 | 1 149 | 0.3 150 | .01 151 | 1 152 | NIL 153 | HORIZONTAL 154 | 155 | BUTTON 156 | 19 157 | 15 158 | 99 159 | 48 160 | setup 161 | setup 162 | NIL 163 | 1 164 | T 165 | OBSERVER 166 | NIL 167 | NIL 168 | NIL 169 | NIL 170 | 1 171 | 172 | BUTTON 173 | 198 174 | 15 175 | 278 176 | 48 177 | go 178 | go 179 | T 180 | 1 181 | T 182 | OBSERVER 183 | NIL 184 | NIL 185 | NIL 186 | NIL 187 | 0 188 | 189 | BUTTON 190 | 103 191 | 15 192 | 193 193 | 48 194 | go once 195 | go 196 | NIL 197 | 1 198 | T 199 | OBSERVER 200 | NIL 201 | NIL 202 | NIL 203 | NIL 204 | 0 205 | 206 | SLIDER 207 | 20 208 | 54 209 | 280 210 | 87 211 | density 212 | density 213 | 0 214 | .99 215 | 0.9 216 | .01 217 | 1 218 | NIL 219 | HORIZONTAL 220 | 221 | PLOT 222 | 14 223 | 301 224 | 257 225 | 470 226 | Unhappiness 227 | time 228 | unhappiness 229 | 0.0 230 | 5.0 231 | 0.0 232 | 1.0 233 | true 234 | false 235 | "" "" 236 | PENS 237 | "default" 1.0 0 -14439633 true "" "plot unhappiness" 238 | 239 | MONITOR 240 | 261 241 | 302 242 | 349 243 | 347 244 | num-unhappy 245 | count turtles with [not happy?] 246 | 1 247 | 1 248 | 11 249 | 250 | MONITOR 251 | 261 252 | 141 253 | 331 254 | 186 255 | # agents 256 | count turtles 257 | 1 258 | 1 259 | 11 260 | 261 | @#$#@#$#@ 262 | ## Model Information and Materials 263 | 264 | This model is original material created by Paul E. Smaldino, building on previous work by Uri Wilensky. 265 | 266 | ## References and Citation 267 | 268 | For this model: 269 | 270 | * Smaldino PE (2023). Segregation. Modeling Social Behavior. https://github.com/psmaldino/modsoc/ 271 | 272 | For the book: 273 | 274 | * Smaldino PE (2023). Modeling Social Behavior: Mathematical and Agent-Based Models of Social Dynamics and Cultural Evolution. Princeton University Press. 275 | 276 | Original model upon which this code is built: 277 | 278 | * Wilensky, U. (1997). NetLogo Segregation model. http://ccl.northwestern.edu/netlogo/models/Segregation. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. 279 | 280 | For the NetLogo: 281 | 282 | * Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. 283 | 284 | 285 | ## Licence 286 | 287 | ![CC BY-NC-SA 4.0](http://ccl.northwestern.edu/images/creativecommons/byncsa.png) 288 | 289 | This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/ 290 | @#$#@#$#@ 291 | default 292 | true 293 | 0 294 | Polygon -7500403 true true 150 5 40 250 150 205 260 250 295 | 296 | airplane 297 | true 298 | 0 299 | Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 300 | 301 | arrow 302 | true 303 | 0 304 | Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 305 | 306 | box 307 | false 308 | 0 309 | Polygon -7500403 true true 150 285 285 225 285 75 150 135 310 | Polygon -7500403 true true 150 135 15 75 150 15 285 75 311 | Polygon -7500403 true true 15 75 15 225 150 285 150 135 312 | Line -16777216 false 150 285 150 135 313 | Line -16777216 false 150 135 15 75 314 | Line -16777216 false 150 135 285 75 315 | 316 | bug 317 | true 318 | 0 319 | Circle -7500403 true true 96 182 108 320 | Circle -7500403 true true 110 127 80 321 | Circle -7500403 true true 110 75 80 322 | Line -7500403 true 150 100 80 30 323 | Line -7500403 true 150 100 220 30 324 | 325 | butterfly 326 | true 327 | 0 328 | Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 329 | Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 330 | Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 331 | Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 332 | Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 333 | Circle -16777216 true false 135 90 30 334 | Line -16777216 false 150 105 195 60 335 | Line -16777216 false 150 105 105 60 336 | 337 | car 338 | false 339 | 0 340 | Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 341 | Circle -16777216 true false 180 180 90 342 | Circle -16777216 true false 30 180 90 343 | Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 344 | Circle -7500403 true true 47 195 58 345 | Circle -7500403 true true 195 195 58 346 | 347 | circle 348 | false 349 | 0 350 | Circle -7500403 true true 0 0 300 351 | 352 | circle 2 353 | false 354 | 0 355 | Circle -7500403 true true 0 0 300 356 | Circle -16777216 true false 30 30 240 357 | 358 | cow 359 | false 360 | 0 361 | Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 362 | Polygon -7500403 true true 73 210 86 251 62 249 48 208 363 | Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 364 | 365 | cylinder 366 | false 367 | 0 368 | Circle -7500403 true true 0 0 300 369 | 370 | dot 371 | false 372 | 0 373 | Circle -7500403 true true 90 90 120 374 | 375 | face happy 376 | false 377 | 0 378 | Circle -7500403 true true 8 8 285 379 | Circle -16777216 true false 60 75 60 380 | Circle -16777216 true false 180 75 60 381 | Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 382 | 383 | face neutral 384 | false 385 | 0 386 | Circle -7500403 true true 8 7 285 387 | Circle -16777216 true false 60 75 60 388 | Circle -16777216 true false 180 75 60 389 | Rectangle -16777216 true false 60 195 240 225 390 | 391 | face sad 392 | false 393 | 0 394 | Circle -7500403 true true 8 8 285 395 | Circle -16777216 true false 60 75 60 396 | Circle -16777216 true false 180 75 60 397 | Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 398 | 399 | face-happy 400 | false 401 | 0 402 | Circle -7500403 true true 8 8 285 403 | Circle -16777216 true false 60 75 60 404 | Circle -16777216 true false 180 75 60 405 | Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 406 | 407 | face-sad 408 | false 409 | 0 410 | Circle -7500403 true true 8 8 285 411 | Circle -16777216 true false 60 75 60 412 | Circle -16777216 true false 180 75 60 413 | Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 414 | 415 | fish 416 | false 417 | 0 418 | Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 419 | Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 420 | Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 421 | Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 422 | Circle -16777216 true false 215 106 30 423 | 424 | flag 425 | false 426 | 0 427 | Rectangle -7500403 true true 60 15 75 300 428 | Polygon -7500403 true true 90 150 270 90 90 30 429 | Line -7500403 true 75 135 90 135 430 | Line -7500403 true 75 45 90 45 431 | 432 | flower 433 | false 434 | 0 435 | Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 436 | Circle -7500403 true true 85 132 38 437 | Circle -7500403 true true 130 147 38 438 | Circle -7500403 true true 192 85 38 439 | Circle -7500403 true true 85 40 38 440 | Circle -7500403 true true 177 40 38 441 | Circle -7500403 true true 177 132 38 442 | Circle -7500403 true true 70 85 38 443 | Circle -7500403 true true 130 25 38 444 | Circle -7500403 true true 96 51 108 445 | Circle -16777216 true false 113 68 74 446 | Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 447 | Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 448 | 449 | house 450 | false 451 | 0 452 | Rectangle -7500403 true true 45 120 255 285 453 | Rectangle -16777216 true false 120 210 180 285 454 | Polygon -7500403 true true 15 120 150 15 285 120 455 | Line -16777216 false 30 120 270 120 456 | 457 | leaf 458 | false 459 | 0 460 | Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 461 | Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 462 | 463 | line 464 | true 465 | 0 466 | Line -7500403 true 150 0 150 300 467 | 468 | line half 469 | true 470 | 0 471 | Line -7500403 true 150 0 150 150 472 | 473 | pentagon 474 | false 475 | 0 476 | Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 477 | 478 | person 479 | false 480 | 0 481 | Circle -7500403 true true 110 5 80 482 | Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 483 | Rectangle -7500403 true true 127 79 172 94 484 | Polygon -7500403 true true 195 90 240 150 225 180 165 105 485 | Polygon -7500403 true true 105 90 60 150 75 180 135 105 486 | 487 | person2 488 | false 489 | 0 490 | Circle -7500403 true true 105 0 90 491 | Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 492 | Rectangle -7500403 true true 127 79 172 94 493 | Polygon -7500403 true true 195 90 285 180 255 210 165 105 494 | Polygon -7500403 true true 105 90 15 180 60 195 135 105 495 | 496 | plant 497 | false 498 | 0 499 | Rectangle -7500403 true true 135 90 165 300 500 | Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 501 | Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 502 | Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 503 | Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 504 | Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 505 | Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 506 | Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 507 | 508 | square 509 | false 510 | 0 511 | Rectangle -7500403 true true 30 30 270 270 512 | 513 | square - happy 514 | false 515 | 0 516 | Rectangle -7500403 true true 30 30 270 270 517 | Polygon -16777216 false false 75 195 105 240 180 240 210 195 75 195 518 | 519 | square - unhappy 520 | false 521 | 0 522 | Rectangle -7500403 true true 30 30 270 270 523 | Polygon -16777216 false false 60 225 105 180 195 180 240 225 75 225 524 | 525 | square 2 526 | false 527 | 0 528 | Rectangle -7500403 true true 30 30 270 270 529 | Rectangle -16777216 true false 60 60 240 240 530 | 531 | square-small 532 | false 533 | 0 534 | Rectangle -7500403 true true 45 45 255 255 535 | 536 | square-x 537 | false 538 | 0 539 | Rectangle -7500403 true true 30 30 270 270 540 | Line -16777216 false 75 90 210 210 541 | Line -16777216 false 210 90 75 210 542 | 543 | star 544 | false 545 | 0 546 | Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 547 | 548 | target 549 | false 550 | 0 551 | Circle -7500403 true true 0 0 300 552 | Circle -16777216 true false 30 30 240 553 | Circle -7500403 true true 60 60 180 554 | Circle -16777216 true false 90 90 120 555 | Circle -7500403 true true 120 120 60 556 | 557 | tree 558 | false 559 | 0 560 | Circle -7500403 true true 118 3 94 561 | Rectangle -6459832 true false 120 195 180 300 562 | Circle -7500403 true true 65 21 108 563 | Circle -7500403 true true 116 41 127 564 | Circle -7500403 true true 45 90 120 565 | Circle -7500403 true true 104 74 152 566 | 567 | triangle 568 | false 569 | 0 570 | Polygon -7500403 true true 150 30 15 255 285 255 571 | 572 | triangle 2 573 | false 574 | 0 575 | Polygon -7500403 true true 150 30 15 255 285 255 576 | Polygon -16777216 true false 151 99 225 223 75 224 577 | 578 | triangle2 579 | false 580 | 0 581 | Polygon -7500403 true true 150 0 0 300 300 300 582 | 583 | truck 584 | false 585 | 0 586 | Rectangle -7500403 true true 4 45 195 187 587 | Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 588 | Rectangle -1 true false 195 60 195 105 589 | Polygon -16777216 true false 238 112 252 141 219 141 218 112 590 | Circle -16777216 true false 234 174 42 591 | Rectangle -7500403 true true 181 185 214 194 592 | Circle -16777216 true false 144 174 42 593 | Circle -16777216 true false 24 174 42 594 | Circle -7500403 false true 24 174 42 595 | Circle -7500403 false true 144 174 42 596 | Circle -7500403 false true 234 174 42 597 | 598 | turtle 599 | true 600 | 0 601 | Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 602 | Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 603 | Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 604 | Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 605 | Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 606 | Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 607 | 608 | wheel 609 | false 610 | 0 611 | Circle -7500403 true true 3 3 294 612 | Circle -16777216 true false 30 30 240 613 | Line -7500403 true 150 285 150 15 614 | Line -7500403 true 15 150 285 150 615 | Circle -7500403 true true 120 120 60 616 | Line -7500403 true 216 40 79 269 617 | Line -7500403 true 40 84 269 221 618 | Line -7500403 true 40 216 269 79 619 | Line -7500403 true 84 40 221 269 620 | 621 | x 622 | false 623 | 0 624 | Polygon -7500403 true true 270 75 225 30 30 225 75 270 625 | Polygon -7500403 true true 30 75 75 30 270 225 225 270 626 | @#$#@#$#@ 627 | NetLogo 6.3.0 628 | @#$#@#$#@ 629 | @#$#@#$#@ 630 | @#$#@#$#@ 631 | 632 | 633 | setup 634 | go 635 | 636 | average-similarity 637 | unhappiness 638 | 639 | 640 | 641 | 642 | @#$#@#$#@ 643 | @#$#@#$#@ 644 | default 645 | 0.0 646 | -0.2 0 0.0 1.0 647 | 0.0 1 1.0 0.0 648 | 0.2 0 0.0 1.0 649 | link direction 650 | true 651 | 0 652 | Line -7500403 true 150 150 90 180 653 | Line -7500403 true 150 150 210 180 654 | @#$#@#$#@ 655 | 0 656 | @#$#@#$#@ 657 | --------------------------------------------------------------------------------