-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathAssimilation.nlogo
1600 lines (1401 loc) · 50.2 KB
/
Assimilation.nlogo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;; NOTES TO READER:
;;
;; 1) I used 2007-2011, 5-yr, American Community Survey data to contextualize model with real world statistics, except where otherwise stated.
;; (additional data is primariy from CIA World FactBook, Census Bureau, and a few numbers are lightly invented)
;;
;; 2) ALL plotting commands, except histograms, are in the plots themselves (I decided it's less cluttered there)
;; I use the word "socialize" loosely in comments... I think of it as social/work/school/some other interaction/etc all rolled into one
;;
;; 3) Lastly, thanks to Uri Wilensky for inspiring some of the critical components of this model.
;; The functions called "be-social", "acquire-english", and "marry" borrow a socializing function from Wilensky's AIDS model, available in the
;; NetLogo libary, part of the standard installation at the time of this code's writing.
;;
;;************************;;
;;INITIAL SETUP PROCEDURES;;
;;************************;;
breed [natives native]
breed [foreigns foreign] ;; this should be divided into more specific groups in a future model
globals [
;;----------------------------------------------;;
;;CUSTOMIZE THESE VALUES IN FUNCTION: "TO SETUP";;
;; (or use sliders when available) ;;
;;----------------------------------------------;;
population ;; total population size
proportion-native ;; proportion native to the stage under observation at init
proportion-foreign ;; this + proprortion = 1
pop-init-native ;; this lets the model output the starting native population size
pop-init-foreign ;; same, but for foreign breed
birth-rate ;; a constant based on annual birth rate, converted for the model
death-rate ;; a constant based on annual death rate, converted for the model
mig-arrive-rate ;; a constant based on annual in-migration rate, converted for the model
mig-depart-rate ;; a constant based on annual out-migration rate, converted for the model
;;---------------------------------------------;;
;;THESE ARE COUNTERS, NOTHING HERE TO CUSTOMIZE;;
;;---------------------------------------------;;
birth-growth ;; a value-holder that increases at the rate above each tick; when it reaches 1, a new agent is "born" and this counter is reduced by 1.
death-growth ;; a value-holder that increases at the rate above each tick; when it reaches 1, an agent is set to "dead." If deaths from old age are common, this value will be negative
mig-arrive-growth ;; a value-holder that increases at the rate above; when it reaches 1, a new agent is "arrives"
mig-depart-growth ;; a value-holder that increases at the rate above; when it reaches 1, a new agent "departs"
births ;; just a counter for population increase via births (informational purposes only)
deaths ;; just a counter for population decrease via deaths (informational purposes only)
in-mig ;; just a counter for population increase via migration (informational purposes only)
out-mig ;; just a counter for population decrease via migration (informational purposes only)
]
turtles-own [
;;-----------------------------------------------------;;
;; MEASURE THESE TO CHECK FOR ASSIMILATED INDIVIDUALS ;;
;;(SES, english, intermarriage?, spatial-concentration);;
;;-----------------------------------------------------;;
SES ;; A proxy for class. Uses six options derived from custom ACS variable: 1, 2, 3, 4, 5, 6 (Poverty, Working, Lower, Middle, Upper-Mid, Upper)
english ;; proportional fluency (0 to 1) to native group of same status--unrealistic 1 IS attainable over time, but won't occur for all foreigns
intermarriage? ;; married to other group? (only intermarried foreigns count for assimilation)
spatial-concentration ;; Proxy: defined for each agent as the calculation of (number of other same-breed in proximity / number of other breed in proximity) <- excludes self from calculation
assimilated? ;; foreign-use only! (Natives always set this to 0 rather than T/F). Returns True if 3/4 conditions are met.
;; these variables are checked and updated every tick. They influence what actions are available and the probability of certain functions triggering a pass/fail
social?
age
;; these variables are set, permitted to update once, then remain static ("intermarriage?" follows this rule, too!)
married?
marriage-partner ;; will report nobody if partner dies, but remarrying is not currently an option
]
to setup
clear-all
set population set-population-size ;; estimated 307M population in 2011 (ACS data)
set proportion-native (set-percent-native / 100) * population
set proportion-foreign (1 - (set-percent-native / 100)) * population
;; These rates calculated by the following:
;; (rate per 1000 population) * 307000 / 1000000 / 52 ;; In English: (constant rate from data) * (307000 to reach estimated 3.7M population in 2011) / (1000000 to scale back to my model's size) / (52 weeks in year) = rate of growth per week (tick)
;;
;; The default values are based on rates provided by CIA WorldFactBook 2011 data as follows:
;; birth-rate: 13.83
;; death-rate: 8.38
;; Net-migration: 4.18 (I split it as follows to allow people to leave and arrive: ...)
;; In-migration: 5.18
;; Out-migration: 1.00
set birth-rate .08
set death-rate .05
set mig-arrive-rate 0.03
set mig-depart-rate 0.006
set-default-shape turtles "person"
population-init
updateHistogram ;; these are SES histograms
reset-ticks ;; set ticks to 0. Each tick = 1 week in this model
end
;;--------------------------------------------------------------------------------------------------------------------------------------------------;;
;; INITIAL POPULATION DATA IS BASED ON NORMAL DISTRIBUTION FROM SURVEY CALCULATIONS OR OFFICIAL NATIONAL DATA ;;
;;(the "native" breed distributions also apply to newborns if the born_as_native_always? is set to true. Otherwise, newborns inherit parent's data) ;;
;;--------------------------------------------------------------------------------------------------------------------------------------------------;;
to population-init
ask n-of proportion-native patches[
sprout-natives 1
[
setxy random-xcor random-ycor
set color blue ;; distinguishes one breed from another
set social? False ;; not born socializing
set SES round abs random-normal 2.72 1.67 ;; set economic/class status
set age random-normal 36.47 23.19 ;; initial populations aren't born simultaneously
set english 1 ;; I don't see a point in setting this below 1 for natives (see actual data on the lines immediately below this)
;set english random-normal 0.974 0.086 ;; In 2011 (ACS dataset) values are Mean: 4.87 Std Dev: .43 on 1-5 scale. Here, converted to 0-1 scale.
set married? False ;; by default set everyone unmarried at init. Probably of marriage increases with age starting at 18
set intermarriage? False ;; not born intermarried -- might change once marriage partner is found
;;after everything is set for an agent, check the agent's normally-distributed values for realism and re-try until corrected
while [SES < 1 or SES = 0 or SES < 0 or SES > 6]
[
set SES round abs random-normal 2.72 1.67
]
while [age < 0] ;; in most tests, this check is unnecessary--added for safety
[
set age random-normal 36.47 23.19
]
;;set spatial-concentration 0 ;; actually, this is calculated at every tick--no need to set a default
;; no "assimilated?" parameter needed for native-born... will report as "0" for natives, but is never used
]
]
ask n-of proportion-foreign patches[
sprout-foreigns 1
[
setxy random-xcor random-ycor
set color red ;; distinguishes one breed from another
set social? False ;; not born socializing
set SES round random-normal 2.27 1.44 ;; set economic/class status
set age random-normal 42.04 17.99 ;; initial populations aren't born simultaneously
set english random-normal 0.646 0.246 ;; In 2011 (ACS dataset) values are Mean: 3.23 Std Dev: 1.23 on 1-5 scale. Here, converted to 0-1 scale.
if english < 0
[
set english 0
]
set married? False ;; by default set everyone unmarried at init. Probably of marriage increases with age starting at 18
set intermarriage? False ;; not born intermarried -- might change once marriage partner is found
;;set spatial-concentration 0 ;; actually, this is calculated at every tick--no need to set a default
set assimilated? False ;; This is set to True by another function. Once "True" it won't revert to "False"
;;after everything is set for an agent, check the agent's normally-distributed values for realism and re-try until corrected
while [SES < 1 or SES = 0 or SES < 0 or SES > 6] ;; in most tests, this check is unnecessary--added for safety
[
set SES round random-normal 2.27 1.44
]
while [age < 0] ;; in most tests, this check is unnecessary--added for safety
[
set age random-normal 42.04 17.99
]
]
]
set pop-init-native count natives
set pop-init-foreign count foreigns
end
;;************************;;
;; POST-SETUP ACTIVITIES ;;
;; (finally some action!) ;;
;;************************;;
to go
;;--------------------;;
;;MAKE AGENTS DO STUFF;;
;;--------------------;;
ask turtles
[
agify ;; make the turtles get older (and show it!)
move ;; Can't be social if nobody gets together
be-social ;; Initiate a check that the conditions to socialize are met--and adjust status accordingly
un-social ;; un-social check is initiated immediately before other social-dependent functions... Therefore, if socializing fails or ends, nothing else can happen.
acquire-english ;; While socializing, English ability improves
marry ;; sets probability for marriage, but only occurs while socializing
spatial-concentration-check ;; Checks who neighbors are, regardless of "social?" status
assimilation-check ;; every round, see if assimilation conditions are met for each agent and report
]
;;---------------------;;
;;POP CHANGE FUNCTIONS ;;
;;(world-level changes);;
;;---------------------;;
birth-check ;; controls birth rate (breed is loosely controlled by "born_as_native_always?" variable)
migrant-arrive ;; controls arrival
death-check ;; controls death rates--well, tries to. People also die at age 115, so if the model runs long enough then this check only prevents people UNDER age 115 from dieing
migrant-depart ;; controls departure rate (anyone can be selected to leave)
updateHistogram
tick ;; 1 tick = 1 week.
end
;;---------------------------------------------;;
;; UPDATE HISTOGRAMS ;;
;;(other plots have codes inside, on interface);;
;;---------------------------------------------;;
to updateHistogram
set-current-plot "plot-immigrant-SES"
set-plot-pen-mode 1
histogram [SES] of foreigns
set-current-plot "plot-native-SES"
set-plot-pen-mode 1
histogram [SES] of natives
set-current-plot "plot-age"
set-plot-pen-mode 1
histogram [age] of turtles
end
;;-------------------------------------------------------------------------------------;;
;; THIS IS THE BEGINNING OF THE FLOW-CHART ACTIVITY SHOWN/DESCRIBED IN THE PAPER ;;
;;(ALL agents do the following; "social?" state is checked within the actual functions);;
;;-------------------------------------------------------------------------------------;;
to agify ;; I like to make up new words
ifelse breed = natives [
set color scale-color blue age 200 -100 ;; This range scales colors from light to dark based on agent's age. The large range prevents white and black extremes by extending well beyond the possible values of "age."
set age age + 1 / 52
]
[
set color scale-color red age 200 -100
set age age + 1 / 52
]
if age >= 78[ ;; This will be checked every week after the agent turns 78.0 years of age
if random-float 1 < age / 156 / 52 ;; this sub-function gives my agents approximately 1% chance to die at its 78.0th year of age. This value increases slightly each week.
[
if death-growth > 0 [
set death-growth death-growth - 1 ;; helps mitigate excessive death of population
set deaths deaths + 1
ask (patch-here) [set pcolor black] ;; reset patch
die ;; kill turtle -- last thing to do because the turtle is ASKED to do the other things!
]
]
]
if age >= 115
[
set death-growth death-growth - 1 ;; helps mitigate excessive death of population
set deaths deaths + 1 ;; must be adjusted before turtle actually dies, because the turtle is "asked" to do this!
ask (patch-here) [set pcolor black] ;; reset patch
die ;; kill turtle -- last thing to do because the turtle is ASKED to do other things!
]
end
to move
if social? = false[
let nearest-similar min-one-of (other turtles with [((breed = [breed] of myself) or (assimilated? = [assimilated?] of myself)) and ((SES = [SES] of myself) or (SES = [SES] of myself + 1)) and ((age - [age] of myself < 5) or ([age] of myself - age < 5))]) [ distance myself ] ;; locate the person MOST like myself and move that direction (can stop to socialize with others along the way)
if nearest-similar = nobody ;; in place for safety... has crashed with this condition left unchecked
[
set nearest-similar min-one-of (other turtles with [(SES = [SES] of myself or SES = [SES] of myself + 1 or breed = [breed] of myself) and ((age - [age] of myself < 5) or ([age] of myself - age < 5))]) [ distance myself ] ;; if all conditions aren't met, settle for basics and choose one of major categories within age range
face nearest-similar ;; face that similar other so you can move towards him/her
]
forward 3 ;; get closer and maybe say "hi!" to someone along the way! (find out in the next function "be-social")
]
end
to be-social ;; This function adapted and modified from the AIDS model by Uri Wilensky, copyright 1997, available in NetLogo's model library. I use this type of function (the "potential-partner" evaluation/social? status change) multiple times, but I swear they're all copied equally from the same source...
let potential-partner one-of other (turtles in-radius 2) with [((SES = [SES] of myself) or (breed = [breed] of myself) or (assimilated? = [assimilated?] of myself)) and ((age - [age] of myself < 5) or ([age] of myself - age < 5)) and ((breed = [breed] of myself) or (english > [english] of myself - .1 and english < [english] of myself + .1)) ] ;; make sure we have SOMETHING in common and communicate reasonably well
if potential-partner != nobody;; make sure I am capable of interacting as well
[
set social? True ;; "I can be social with multiple turtles... if they come to me (I don't move while social)"
move-to patch-here ;; move to center of patch
ask patch-here [ set pcolor [color] of myself - 3 ]
ask potential-partner [ ;; do all the same stuff I do
set social? True
move-to patch-here
ask patch-here [ set pcolor [color] of myself - 3 ]
]
]
end
to un-social
if social?
[ if random-float 1 < age / 115 [ ;; Agent becomes less tolerant of interaction as with age. 115 is the the maximum an agent can live, so there's always at least a small chance of being social
set social? False ;; Quit being social
ask patch-here [ set pcolor black ] ;; reset patch so it doesn't draw observer's attention
]
let potential-partner one-of other (turtles in-radius 1) with [SES = [SES] of myself and english > 0] ;; check again... if nobody around, stop talking to yourself!
if potential-partner = nobody[ ;; friends all left
set social? False ;; You're not talking to anyone... don't lie about it
ask patch-here [ set pcolor black ] ;; reset patch so it doesn't draw observer's attention
]
]
end
to acquire-english ;; based on the "be-social" function above. See comments there for more info including additional citation info.
let potential-speaker one-of other (turtles in-radius 2) with [social?] ;; this just ensures that at least one person is nearby and talking
if social? and potential-speaker != nobody;; only increase English proficiency while near English speakers
[
ifelse english < 1 ;; if I'm not fluent in English
[ let potential-speaker-fluency ((sum [english] of other (turtles in-radius 2) with [social?]) / count other (turtles in-radius 2) with [social?]) ;; then figure out the rate at which English is being used (it's not actually used... this is an assumption)
if potential-speaker-fluency != 0 ;; if I can hear some english...
[
ifelse age > 13 ;; and I'm either above the critical threshhold for becoming a native speaker or I'm not...
[ let english-rate ((0.00526 * 1 * potential-speaker-fluency) / (age - 13) + .001) ;; if not, I'll probably learn English at a maximum rate of .001. This means I'd take close to 20 yrs to approach nativity without any knowledge of English already
set english english + english-rate ]
[ let english-rate (0.00526 * 1 * potential-speaker-fluency) ;; if I'm 13 or younger, I can learn much faster
set english english + english-rate ]
]
] ;; rate = 1/190.06 = 1/3.655*52 = 1 / (average time for children to reach native proficiency * 52 weeks/yr) = 0.00526
[set english 1] ;; a check to make sure English never exceeds 1
]
end
to marry ;; based on the "be-social" function above. See comments there for more info including additional citation info.
if social? and not married? and age >= 18
[
let potential-partner one-of other (turtles in-radius 2) with [social? and not married? and ((SES = [SES] of myself) or (SES = [SES] of myself + 1) or (SES = [SES] of myself - 1)) and ((english < [english] of myself + 0.1 and english > [english] of myself - 0.1) or breed = [breed] of myself) and age >= 18]
if potential-partner != nobody[
if random-float 1 < age / 52 ;; probability for marriage remains above 0 and increases with age
[
if random-float 1 < [age] of potential-partner / 52
[
set married? True
set marriage-partner potential-partner
ask potential-partner
[
set married? True
set marriage-partner myself
]
if breed != [breed] of marriage-partner
[
set intermarriage? True
ask marriage-partner
[
set intermarriage? True
]
]
if SES != [SES] of marriage-partner ;; partner with lowest SES inherits the status of the larger SES
[
if SES > [SES] of marriage-partner
[
ask marriage-partner
[
set SES [SES] of myself
]
]
if SES < [SES] of marriage-partner
[
set SES [SES] of marriage-partner
]
]
]
]
]
]
end
to spatial-concentration-check ;; constantly changes--this is the wildcard of the model; because assimilation is perceived, perception can be somewhat altered
let spatial-concentration-diff count (other turtles in-radius 1) with [breed != [breed] of myself]
let spatial-concentration-same count (other turtles in-radius 1) with [breed = [breed] of myself]
if spatial-concentration-same != 0 or spatial-concentration-diff != 0
[
set spatial-concentration spatial-concentration-same / (spatial-concentration-diff + spatial-concentration-same) ;; calculate 0-1 concentration. Assimlation condition is met if <= 0.5
]
end
to assimilation-check ;; this check goes in one direction. Once someone earns assimilation status, it can't be unearned (not too realistic, if we're honest)
if assimilated? = false[
let assimilation-value 0
if SES >= mean [SES] of natives [
set assimilation-value assimilation-value + 1
]
if english = 1[
set assimilation-value assimilation-value + 1
]
if intermarriage?[
set assimilation-value assimilation-value + 1
]
if spatial-concentration < 0.5[
set assimilation-value assimilation-value + 1
]
set assimilation-value assimilation-value / 4
if assimilation-value >= .75
[set assimilated? True]
]
end
;;-------------------------------------------------------------------------------------;;
;; THESE FUNCTIONS CONTROL THE POPULATION CHANGES THAT RECUR AT REGULAR INTERVALS ;;
;; (if you like the normally distribtued values, none of this should require changing) ;; <--- NO! Udate these values to variables in a future version. One-stop place for value updates. Maybe add sliders?
;;-------------------------------------------------------------------------------------;;
to birth-check
set birth-growth birth-growth + birth-rate
ifelse born_as_native_always? = True
[;; born_as_native_always? = True
if birth-growth >= 1 ;; if the variable increases to a whole value, let's make that whole born--because the growth per tick is a decimal, 1 is a sufficiently large whole value
[
ask one-of turtles
[
hatch-natives 1
[
set color blue
set social? False ;; not born socializing
set SES round random-normal 2.72 1.67 ;; set economic/class status
set age 0 ;; can't be born with an age > 0!
set english 1 ;; I don't see a point in setting this below 1 (see actual data on the line below this)
;set english random-normal 0.974 0.086 ;; In 2011 (ACS dataset) values are Mean: 4.87 Std Dev: .43 on 1-5 scale. Here, converted to 0-1 scale.
set married? False ;; by default set everyone unmarried at init. Probably of marriage increases with age starting at 18
set intermarriage? False ;; not born intermarried -- might change once marriage partner is found
set marriage-partner nobody
while [SES < 1 or SES > 6] ;; in most tests, this check is unnecessary--added for safety
[
set SES round random-normal 2.72 1.67
]
]
]
set birth-growth birth-growth - 1 ;; subtract the one that was born from the variable
set births births + 1
]
]
[;; born_as_native_always? = False
if birth-growth >= 1 ;; if the variable increases to a whole value, let's make that whole born--because the growth per tick is a decimal, 1 is a sufficiently large whole value
[
ask one-of turtles
[
hatch 1
[
set social? False ;; not born socializing
;set SES ;; should be inherited
set age 0 ;; can't be born with an age > 0!
set english 1 ;; I don't see a point in setting this below 1 for anyone born in the U.S.
set married? False ;; by default set everyone unmarried at init. Probably of marriage increases with age starting at 18
set intermarriage? False ;; not born intermarried -- might change once marriage partner is found
set marriage-partner nobody
]
]
set birth-growth birth-growth - 1 ;; subtract the one that was born from the variable
set births births + 1
]
]
end
to migrant-arrive
set mig-arrive-growth mig-arrive-growth + mig-arrive-rate
if mig-arrive-growth >= 1 ;; if the variable increases to a whole value, let's make that whole born--because the growth per tick is a decimal, 1 is a sufficiently large whole value
[
ask one-of patches
[
sprout-foreigns 1
[
set color red
set social? False ;; doesn't arrive socializing
set SES round random-normal 2.27 1.44 ;; set economic/class status
set age random-normal 42.04 17.99 ;; maintain normal distribution of age for foreigns
set english random-normal 0.646 0.246 ;; In 2011 (ACS dataset) values are Mean: 3.23 Std Dev: 1.23 on 1-5 scale. Here, converted to 0-1 scale.
if english < 0
[
set english 0
]
set married? False ;; by default set everyone unmarried at init. Probably of marriage increases with age starting at 18
set intermarriage? False ;; not born intermarried -- might change once marriage partner is found
;;set spatial-concentration 0 ;; actually, this is calculated at every tick--no need to set a default
set assimilated? False ;; by default -- has to be earned
while [SES < 1 or SES > 6] ;; in most tests, this check is unnecessary--added for safety
[
set SES round random-normal 2.27 1.44
]
while [age < 0]
[
set age random-normal 42.04 17.99
]
]
set in-mig in-mig + 1
set mig-arrive-growth mig-arrive-growth - 1
]
]
end
to death-check
set death-growth death-growth + death-rate
if death-growth >= 1 ;; if the variable increases to a whole value, let's make that whole born--because the growth per tick is a decimal, 1 is a sufficiently large whole value
[
ask one-of turtles
[
ask (patch-here) [set pcolor black] ;; reset patch
die ;; kill turtle - last thing to do because agent is ASKED to do the other things!
]
set death-growth death-growth - 1 ;; subtract the one that was born from the variable
set deaths deaths + 1
]
end
to migrant-depart
set mig-depart-growth mig-depart-growth + mig-depart-rate
if mig-depart-growth >= 1 ;; if the variable increases to a whole value, let's make that whole born--because the growth per tick is a decimal, 1 is a sufficiently large whole value
[
ask one-of turtles
[
ask (patch-here) [set pcolor black] ;; reset patch
die
]
set out-mig out-mig + 1
set mig-depart-growth mig-depart-growth - 1
]
end
;;*******************************************************************;;
;; GIVE ME SOME RESULTS! ;;
;;(modify this at your discretion to output some results, as desired);;
;;*******************************************************************;;
to sweep ;; borrowed from code provided by Steve Scott
let num-replicates 10 ;; 30 runs of the model should be enough to get an idea
let num-ticks 4056 ;; run for 78 simulated years. This is roughly the median lifespan for an American... how much will change in one lifetime?
let i 0
let results-list []
; Case 1:
; born_as_always? True
;
; print CSV headers
file-open "case_1.csv"
;file-print ("run_num, born_as_native_always?, Initial_Native_Pop, Initial_Foreign_Pop, Prop_Init_Foreign, Final_Native_Pop, Final_Foreign_Pop, Prop_Final_Foreign, births_tot, deaths_tot, in-mig_tot, english?_prop, ses?_prop, intermarriage?_prop, spatial?_prop, assimilated?_prop")
file-close
set i 0
set born_as_native_always? True
set results-list []
while [ i < num-replicates ]
[
setup
repeat num-ticks [ go ]
;set results-list (fput (count foreigns with [assimilated?]) results-list)
set i (i + 1)
file-open "case_1.csv"
file-print (list i "," born_as_native_always? "," pop-init-native "," pop-init-foreign "," (pop-init-foreign / (pop-init-foreign + pop-init-native)) "," count natives "," count foreigns "," (count foreigns / count turtles) "," births "," deaths "," in-mig "," (count foreigns with [english >= .75] / count foreigns) "," (count foreigns with [SES >= mean [SES] of natives] / count foreigns) "," (count foreigns with [intermarriage? = true] / count foreigns) "," (count foreigns with [spatial-concentration > 0 and spatial-concentration <= 0.5] / count foreigns) "," (count foreigns with [assimilated? = True] / count foreigns))
file-close
]
; Case 2:
; born_as_always? False
;
file-open "case_2.csv"
file-print ("run_num, born_as_native_always?, Initial_Native_Pop, Initial_Foreign_Pop, Prop_Init_Foreign, Final_Native_Pop, Final_Foreign_Pop, Prop_Final_Foreign, births_tot, deaths_tot, in-mig_tot, english?_prop, ses?_prop, intermarriage?_prop, spatial?_prop, assimilated?_prop")
file-close
set i 0
set born_as_native_always? False
set results-list []
while [ i < num-replicates ]
[
setup
repeat num-ticks [ go ]
;set results-list (fput (count foreigns with [assimilated?]) results-list)
set i (i + 1)
file-open "case_2.csv"
file-print (list i "," born_as_native_always? "," pop-init-native "," pop-init-foreign "," (pop-init-foreign / (pop-init-foreign + pop-init-native)) "," count natives "," count foreigns "," (count foreigns / count turtles) "," births "," deaths "," in-mig "," (count foreigns with [english >= .75] / count foreigns) "," (count foreigns with [SES >= mean [SES] of natives] / count foreigns) "," (count foreigns with [intermarriage? = true] / count foreigns) "," (count foreigns with [spatial-concentration > 0 and spatial-concentration <= 0.5] / count foreigns) "," (count foreigns with [assimilated? = True] / count foreigns))
file-close
]
;----------------------------------------------------------;
; Sweeps always use born_as_native_always? True ;
;(less noise and better understanding of parameter impacts); <-- you could change it, though, if you REALLY want to...
;----------------------------------------------------------;
; Sweep 1:
; Maximum Population
;
file-open "sweep_maxpop.csv"
file-print ("run_num, born_as_native_always?, Initial_Native_Pop, Initial_Foreign_Pop, Prop_Init_Foreign, Final_Native_Pop, Final_Foreign_Pop, Prop_Final_Foreign, births_tot, deaths_tot, in-mig_tot, english?_prop, ses?_prop, intermarriage?_prop, spatial?_prop, assimilated?_prop")
file-close
set i 0
set born_as_native_always? False
while [ i < num-replicates ]
[
set born_as_native_always? True
set set-population-size 400
set set-percent-native 87
setup
repeat num-ticks [ go ]
set i (i + 1)
print "Max Pop" print i
file-open "sweep_maxpop.csv"
file-print (list i "," born_as_native_always? "," pop-init-native "," pop-init-foreign "," (pop-init-foreign / (pop-init-foreign + pop-init-native)) "," count natives "," count foreigns "," (count foreigns / count turtles) "," births "," deaths "," in-mig "," (count foreigns with [english >= .75] / count foreigns) "," (count foreigns with [SES >= mean [SES] of natives] / count foreigns) "," (count foreigns with [intermarriage? = true] / count foreigns) "," (count foreigns with [spatial-concentration > 0 and spatial-concentration <= 0.5] / count foreigns) "," (count foreigns with [assimilated? = True] / count foreigns))
file-close
]
; Sweep 2:
; Minimum Population
;
file-open "sweep_minpop.csv"
file-print ("run_num, born_as_native_always?, Initial_Native_Pop, Initial_Foreign_Pop, Prop_Init_Foreign, Final_Native_Pop, Final_Foreign_Pop, Prop_Final_Foreign, births_tot, deaths_tot, in-mig_tot, english?_prop, ses?_prop, intermarriage?_prop, spatial?_prop, assimilated?_prop")
file-close
set i 0
set born_as_native_always? True
set set-population-size 100
set set-percent-native 87
while [ i < num-replicates ]
[
setup
repeat num-ticks [ go ]
set i (i + 1)
print "Min Pop" print i
file-open "sweep_minpop.csv"
file-print (list i "," born_as_native_always? "," pop-init-native "," pop-init-foreign "," (pop-init-foreign / (pop-init-foreign + pop-init-native)) "," count natives "," count foreigns "," (count foreigns / count turtles) "," births "," deaths "," in-mig "," (count foreigns with [english >= .75] / count foreigns) "," (count foreigns with [SES >= mean [SES] of natives] / count foreigns) "," (count foreigns with [intermarriage? = true] / count foreigns) "," (count foreigns with [spatial-concentration > 0 and spatial-concentration <= 0.5] / count foreigns) "," (count foreigns with [assimilated? = True] / count foreigns))
file-close
]
; Sweep 3:
; Maximum Natives (Percent)
;
file-open "sweep_maxnat.csv"
file-print ("run_num, born_as_native_always?, Initial_Native_Pop, Initial_Foreign_Pop, Prop_Init_Foreign, Final_Native_Pop, Final_Foreign_Pop, Prop_Final_Foreign, births_tot, deaths_tot, in-mig_tot, english?_prop, ses?_prop, intermarriage?_prop, spatial?_prop, assimilated?_prop")
file-close
set i 0
set born_as_native_always? True
set set-population-size 306.7
set set-percent-native 98
while [ i < num-replicates ]
[
setup
repeat num-ticks [ go ]
set i (i + 1)
print "Max Nat" print i
file-open "sweep_maxnat.csv"
file-print (list i "," born_as_native_always? "," pop-init-native "," pop-init-foreign "," (pop-init-foreign / (pop-init-foreign + pop-init-native)) "," count natives "," count foreigns "," (count foreigns / count turtles) "," births "," deaths "," in-mig "," (count foreigns with [english >= .75] / count foreigns) "," (count foreigns with [SES >= mean [SES] of natives] / count foreigns) "," (count foreigns with [intermarriage? = true] / count foreigns) "," (count foreigns with [spatial-concentration > 0 and spatial-concentration <= 0.5] / count foreigns) "," (count foreigns with [assimilated? = True] / count foreigns))
file-close
]
; Sweep 4:
; Minimum Natives (Percent)
;
file-open "sweep_minnat.csv"
file-print ("run_num, born_as_native_always?, Initial_Native_Pop, Initial_Foreign_Pop, Prop_Init_Foreign, Final_Native_Pop, Final_Foreign_Pop, Prop_Final_Foreign, births_tot, deaths_tot, in-mig_tot, english?_prop, ses?_prop, intermarriage?_prop, spatial?_prop, assimilated?_prop")
file-close
set i 0
set born_as_native_always? True
set set-population-size 306.7
set set-percent-native 2
while [ i < num-replicates ]
[
setup
repeat num-ticks [ go ]
set i (i + 1)
print "Min Nat" print i
file-open "sweep_minnat.csv"
file-print (list i "," born_as_native_always? "," pop-init-native "," pop-init-foreign "," (pop-init-foreign / (pop-init-foreign + pop-init-native)) "," count natives "," count foreigns "," (count foreigns / count turtles) "," births "," deaths "," in-mig "," (count foreigns with [english >= .75] / count foreigns) "," (count foreigns with [SES >= mean [SES] of natives] / count foreigns) "," (count foreigns with [intermarriage? = true] / count foreigns) "," (count foreigns with [spatial-concentration > 0 and spatial-concentration <= 0.5] / count foreigns) "," (count foreigns with [assimilated? = True] / count foreigns))
file-close
]
end
@#$#@#$#@
GRAPHICS-WINDOW
342
15
680
354
-1
-1
10.0
1
10
1
1
1
0
1
1
1
-16
16
-16
16
0
0
1
ticks
1.0
BUTTON
277
71
340
104
setup
setup
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
277
106
340
139
go
go
T
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
PLOT
144
144
344
294
How many social?
NIL
NIL
0.0
10.0
0.0
1.0
true
false
"" ""
PENS
"default" 1.0 0 -16777216 true "" "plot (count turtles with [social?] / count turtles)"
PLOT
684
168
884
318
english = 1.0
NIL
NIL
0.0
10.0
0.0
1.0
true
false
"" ""
PENS
"immigrants" 1.0 0 -2674135 true "" "plot (count foreigns with [english >= 1] / count foreigns)"
MONITOR
247
14
337
59
Years Elapsed
ticks / 52
2
1
11
PLOT
683
19
883
169
intermarried immigrant?
NIL
NIL
0.0
10.0
0.0
1.0
true
false
"" ""
PENS
"yes" 1.0 0 -2674135 true "" "plot (count foreigns with [married? = True and intermarriage? = True] / count foreigns)"
PLOT
883
18
1083
168
spatial concentration < 0.5
NIL
NIL
0.0
10.0
0.0
1.0
true
false
"" ""
PENS
"foreigns" 1.0 0 -2674135 true "" "plot (count foreigns with [spatial-concentration > 0 and spatial-concentration <= 0.5] / count foreigns)"
MONITOR
412
377
470
422
foreigns
count foreigns
17
1
11
MONITOR
472
377
529
422
natives
count natives
17
1
11
MONITOR
529
377
600
422
population
count turtles
17
1
11
PLOT
783
318
983
468
Assimilated?
NIL
NIL
0.0
10.0
0.0
1.0
true
false
"" ""
PENS
"default" 1.0 0 -13840069 true "" "plot (count foreigns with [(assimilated? = True)] / count foreigns)"
PLOT
884
168
1084
318
immigrants with SES >= avg native SES
NIL
NIL
0.0
10.0
0.0
1.0
true
false
"" ""
PENS
"immigrants" 1.0 0 -2674135 true "" "plot (count foreigns with [SES >= mean [SES] of natives] / count foreigns)"
MONITOR
8
170
65
215
SES = 1
count natives with [SES = 1]
17
1
11
MONITOR
8
219
65
264
SES = 2
count natives with [SES = 2]
17
1
11
MONITOR
8
263
65
308
SES = 3
count natives with [SES = 3]
17
1
11
MONITOR
7
307
64
352
SES = 4
count natives with [SES = 4]
17
1
11
MONITOR
7
352
64
397
SES = 5
count natives with [SES = 5]
17
1
11
MONITOR
7
396
64
441
SES = 6
count natives with [SES = 6]
17
1
11
MONITOR
80
173
137
218
SES = 1
count foreigns with [SES = 1]
17
1
11
MONITOR
82
218
139
263
SES = 2
count foreigns with [SES = 2]
17
1
11