-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMODEL_Logone_Floodplain.nlogo
2235 lines (1864 loc) · 79.1 KB
/
MODEL_Logone_Floodplain.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
extensions [ GIS profiler array]
patches-own [
land-cover
village-num
testing-zone
]
turtles-own [
head-age ; The age of the household head
num-wives ; The number of wives in the household (0 to 4)
wives-marriage-age ; A list containing the ages of all wives in a household when they were first married
wives-current-age ; A list containing the current ages of all wives in a household
num-children ; The total number of children in the household
num-boys ; The total number of boys in the household
boys-ages ; A list containing the current ages of all boys in a household
num-girls ; The total number of girls in the household
girls-ages ; A list containing the current ages of all girls in a household
widows-ages ; A list containing the current ages of all widows in a household
num-widows ; The total number of widows in the household
fishing-payoff-this-yr
fishing-payoff-past-5-yrs
fishing-expected-payoff
num-canals ; Number of canals owned by the household
canal-payoff-this-yr
canal-payoff-past-5-yrs
canal-expected-payoff
num-fields ; Number of rice fields owned by the household
field-payoff-this-yr
field-payoff-past-5-yrs
field-expected-payoff
total-wealth ; The amount of existing wealth owned by a household. Wealth is accumulated from
; fishing, canals, and rice farming. It is spent on family members, marriage, and
; investments.
expected-income ; The amount of income that a household head expects for next year based on his current investments
annual-family-costs ; The amount of income that a household head expects to spend on his family
getting-married ; Household heads cannot get married and make investments in the same year. Additionally, a household will
; not invest if they are eligible to get married in the following year. This variable determines whether
; or not a household will invest in productive assets in a given year
]
globals [
; Related to the environment
ground-raster ; Loads information about floodplain background from ASCII file
village-raster ; Loads information about village locations from ASCII file
testing-zones-raster ; Loads data that separates the habitable cells into four distinct zones for experimentation
this-year ; An integer listing the current year (starts in 1985)
; Related to demographics
wife-max-childbearing-age ; the oldest age at which a wife might have a child
wife-annual-childbearing-prob ; the yearly probability that a wife will give birth to a child, given that her age is
; below or equal to wife-max-childbearing-age
emigration-probability ; The probability that a boy will leave the floodplain upon marriage
stay-in-village-prob ; The probability that a boy will stay in his own village upon forming a new household,
; assuming he does not leave the floodplain
; Annual Revenues
; NOTE: Each of these follow a log-normal distribution
nco-fishing-payoff-mean
nco-fishing-payoff-sd
co-fishing-payoff-mean
co-fishing-payoff-sd
canal-payoff-mean
canal-payoff-sd
field-payoff-mean
field-payoff-sd
field-maintenance-cost
; Costs for investment and marriage
;canal-cost
field-cost
;marriage-cost
;first-marriage-extra-cost
; Thresholds for canal ownership
max-num-canals
max-num-fields
; Annual expenses
adult-annual-cost
child-annual-cost
infant-annual-cost
elderly-annual-cost
;income-tax-rate
annual-fishing-cost
canal-maintenance-cost-mean
canal-maintenance-cost-sd
canal-annual-taxes
;Effects of Boko Haram
;boko-haram-start
;boko-haram-durationf
;bh-revenue-multiplier
boko-haram-end
original-income-tax
revenue-multiplier
]
; ==============================================================================================================
; ===================== PROGRAM FLOW: INITIALIZATION AND YEARLY ACTIONS =====================
; ==============================================================================================================
to setup
;; (for this model to work with NetLogo's new plotting features,
;; __clear-all-and-reset-ticks should be replaced with clear-all at
;; the beginning of your setup procedure and reset-ticks at the end
;; of the procedure.)
ca
initialize-globals
load-gis
place-households
ask turtles [
initialize-expected-payoffs
initialize-household-attributes
]
reset-ticks
set this-year 1975
end
to go
update-year
if this-year = boko-haram-start and boko-haram-duration > 0 [begin-boko-haram-effects]
if this-year = boko-haram-end [end-boko-haram-effects]
ask turtles [
update-ages
children-born
children-leave-household true
wives-die
widows-die
children-die
head-dies
; Wealth and expenses
update-payoffs
update-expected-payoffs
update-wealth
update-expected-income
; Spending wealth
marriage-decision
investment-decision
]
tick
end
; ==============================================================================================================
; ===================== SETTING GLOBAL VARIABLES =====================
; ==============================================================================================================
; The following function loads global variable for family dynamics
to initialize-globals
set wife-max-childbearing-age 45
set wife-annual-childbearing-prob 0.2562
set emigration-probability 0.1
set stay-in-village-prob 0.5
; Annual Revenues
; NOTE: Each of these follows a log-normal distribution
set nco-fishing-payoff-mean 460935
set nco-fishing-payoff-sd 321409
set co-fishing-payoff-mean 202356
set co-fishing-payoff-sd 288867
set canal-payoff-mean 571780
set canal-payoff-sd 556762
; Unlike canals and fishing, field revenues follow a standard normal distribution
set field-payoff-mean 153516
set field-payoff-sd 113152
set field-maintenance-cost 50000
; Costs for investment and marriage
;set canal-cost 509950
set field-cost 300000
; Annual expenses
set adult-annual-cost 140000
set child-annual-cost 70000
set infant-annual-cost 35000
set elderly-annual-cost 70000
;set income-tax-rate 0.1 ; NOTE: As a percentage of total annual income
set annual-fishing-cost 70000
set canal-maintenance-cost-mean 168839
set canal-maintenance-cost-sd 151567
set canal-annual-taxes 100000
; Thresholds for canal and field ownership
;set min-children-per-canal 2
set max-num-fields 3
set max-num-canals 2
; The year that the effects of Boko Haram end
set boko-haram-end boko-haram-start + boko-haram-duration
set original-income-tax income-tax-rate
set revenue-multiplier 1
end
; ==============================================================================================================
; ===================== INITIALIZING THE FLOODPLAIN =====================
; ==============================================================================================================
; The following function loads the GIS raster with vegetation data
to load-gis
set ground-raster gis:load-dataset "land_cover_v3.asc" ; loads raster for background
set village-raster gis:load-dataset "village_boundaries.asc" ; loads raster for village locations
;set testing-zones-raster gis:load-dataset "testing_districts.asc" ; loads raster for testing zones
; Sets the geographic extent of the world equal to the background data extent
gis:set-world-envelope gis:envelope-of ground-raster
; This section applies the raster data (global) to variables owned by patches
gis:apply-raster ground-raster land-cover
gis:apply-raster village-raster village-num
;gis:apply-raster testing-zones-raster testing-zone
ask patches [ if land-cover = 0 [set pcolor gray] ; Plain pixels (not rivers or depressions) are set to gray
if land-cover = 1 [set pcolor lime] ; Depression pixels are set to the lime color
if land-cover = 2 [set pcolor blue] ; River pixels are set to blue
if land-cover = 3 [set pcolor brown] ; Habitable pixels are set to brown. These pixels will hold all households for the model!
]
; Uncomment the following line of code to see the four testing zones
; ask patches [if land-cover = 3 [set pcolor scale-color brown testing-zone 0 4]]
; Uncomment the following line of code to see habitable areas by village
ask patches [if land-cover = 3 [set pcolor scale-color red village-num 1 33]]
end
; The following function places actors representing households for each of the 36 villages
to place-households
; The following two lists contain the estimated number of non-canal-owning and canal-owning household per village, respectively
let nco-hh [11 11 28 9 9 5 9 5 16 38 127 57 3 3 26 21 45 0 106 33 259 165 28 47 92 141 429 9 24 14 19 143 41]
let co-hh [6 2 2 1 3 1 3 2 5 8 9 4 1 1 9 6 5 0 34 2 23 12 1 10 7 10 39 1 3 1 3 13 3]
; This populates the study area with each sub-population by village
populate-group nco-hh 0 orange
populate-group co-hh 1 yellow
end
; The following function creates households for a given sub-population in the study area based on a list
; of the number of households in each village
to populate-group [group-list number-of-canals group-color]
let num-villages length group-list
let village-iterator 0
; First, we will create a loop to iterate through the populations within each village
; With our current data, the iterator should run 36 times
while [ village-iterator < num-villages ] [
; Within each village, the variable "num-group-members" will represent
; The number of households from a certain demographic who live in the village
let num-group-members item village-iterator group-list
; Creates all of the turtles for a given village
create-turtles num-group-members [
set size 1.2
set color group-color
; If the household is canal-owning, it will start off with one canal. Otherwise, it will start with 0 canals
set num-canals number-of-canals
; Moves the turtle to one of the tiles assigned to one of their village patches
move-to one-of patches with [village-num = village-iterator + 1 and land-cover = 3]
; Randomly positions the turtle within that patch
set heading 0
fd random-float 1 - 0.5
set heading 90
fd random-float 1 - 0.5 ]
; This sub-population has now been initialized within a particular village
set village-iterator village-iterator + 1 ; Increments our top iterator by 1
]
end
; This turtle function assigns demographic values to each household
; For now, this is kept simple: the model is initialized with one household head,
; no wives, no children, and no assets
to initialize-household-attributes
; *** Initial demographic attributes assigned according to the demographic model ***
; Initial household attributes are assigned differently depending on whether or not the household
; owns a canal
ifelse num-canals = 0 [
; Household head age mean, std.dev.: 35.01, 14.84
set head-age round (random-normal 35.01 14.84)
; Minimum household head age is 18
if head-age < 18 [set head-age 18]
; Derived equation for number of wives within non-canal-owning households:
; Num Wives = -0.00275 + 0.0320 * head-age + Normal(0,0.681)
initialize-wives -0.00275 0.0320 0.681
][
; Household head age mean, std.dev.: 54.07, 16.73
set head-age round (random-normal 54.07 16.73)
; Minimum household head age is 18
if head-age < 18 [set head-age 18]
; Derived equation for number of wives within canal-owning households:
; Num Wives = 0.917 + 0.0146 * head-age + Normal(0,0.992)
initialize-wives 0.917 0.0146 0.992
]
initialize-children
set num-widows 0
set widows-ages []
; Each household starts out with no existing (liquid) wealth, and one field
set total-wealth 0
set num-fields 1
end
; This is a turtle function that sets the "num-wives" attribute based on a linear regression
; and a stochastic component.
; Intercept: X-intercept in a regression between household head age and number of wives
; Age-component: dx in a regression between household head age and number of wives
; Standard-dev: The standard deviation of residuals in the regression between household head age and number of wives
to initialize-wives[intercept age-component standard-dev]
; The number of wives will be assigned based on this formula:
; Num-wives = intercept + age-component * head-age + Normal(0,standard-dev)
set num-wives round ((intercept + age-component * head-age + random-normal 0 standard-dev) / 2)
; The number of wives must be at least 0 and no greater than 4
if num-wives < 0 [set num-wives 0]
if num-wives > 4 [set num-wives 4]
; Uncomment the following line of code to visualize families by the number of wives
;set color scale-color green num-wives 0 4
; The following section of code creates two lists describing the age of wives in the household
set wives-marriage-age [] ; This list provides the age of each wife at the time of marriage
set wives-current-age [] ; This list provides the current age of each wife
; wives-iterator is used to cycle between the wives in the household
; "wives-iterator = 0" corresponds to the first wife, "wives-iterator = 1" to the second wife, and so on
let wives-iterator 0
; The age of wives were found to strongly correlate with the husband's age at the time of marriage
; The husband's age at the time of marriage is therefore estimated for each wife, based on the marriage
; number and the husband's current age.
; Afterwards, the wife's age at marriage is estimated using the husband's age at marriage.
; This calculation is the same for all four sub-populations
let husband-marriage-intercepts [-9.3085 -6.9946 -2.4459 4.7801]
let husband-marriage-age-components [0.572 0.3995 0.2307 0.0643]
let husband-marriage-stochastic [9.187 9.215 7.183 12.119]
; Iterates over each wife
while [wives-iterator < num-wives][
; first, determine how long ago the nth marriage was
; this will be based on the lists created above
; These lists are based on statistical analysis for all households in the 2014 dataset
; Statistical testing did not find significant differences in the time of marriage between sub-populations
let marriage-years-ago round (item wives-iterator husband-marriage-intercepts + head-age * item wives-iterator husband-marriage-age-components + random-normal 0 item wives-iterator husband-marriage-stochastic)
; The marriage should be in the past
if marriage-years-ago < 0 [set marriage-years-ago 0]
; Next, determine the husband's age at that time
let husband-marriage-age head-age - marriage-years-ago
; Get the wife's age at marriage from a function, "get-wife-age-at-marriage"
let this-wife-marriage-age get-wife-age-at-marriage husband-marriage-age
; Now, add the wife's marriage age to the wives-marriage-age list
set wives-marriage-age lput this-wife-marriage-age wives-marriage-age
let this-wife-current-age this-wife-marriage-age + marriage-years-ago
; Add the wife's current age to the wives-current-age list
set wives-current-age lput this-wife-current-age wives-current-age
; Move on to the next item
set wives-iterator wives-iterator + 1
]
; The wives are now initialized in the lists wives-marriage age and wives-current-age
; The number of wives in the household, num-wives, should always be equal to either list length
end
to initialize-children
; This is a turtle function that determines the number and ages of boys and girls in the household
; based on the ages of the wives and when the wives were married
; This function is the same for all four sub-populations
set num-children 0
set boys-ages []
set girls-ages []
; First, determine the "child-bearing" time period for each wife
; This time period is defined as the length of time that each wife is married and is able to have children (ages 15 to 45)
; Iterates through the wives
let wives-birth-iterator 0 ; This iterates through the wives
while [ wives-birth-iterator < num-wives ][
let fertility-start-years-ago 0
let fertility-end-years-ago 0
; If this wife is over age 45:
ifelse item wives-birth-iterator wives-current-age > 45
[ifelse item wives-birth-iterator wives-marriage-age < 45
[ ; If the wife is over 45 and was married younger than 45
; She was able to start bearing children when she was married
; She stopped being able to bear children when she turned 45 (in this model)
set fertility-start-years-ago item wives-birth-iterator wives-current-age - item wives-birth-iterator wives-marriage-age
set fertility-end-years-ago item wives-birth-iterator wives-current-age - 45
]
[ ; If the wife was over 45 when married, then she was not able to bear children during the marriage
set fertility-start-years-ago 0
set fertility-end-years-ago 0
]
]
[ ; Otherwise, the wife is younger than 45 (and can therefore still bear children)
; She started being able to bear children when she was married
set fertility-end-years-ago 0
set fertility-start-years-ago item wives-birth-iterator wives-current-age - item wives-birth-iterator wives-marriage-age
]
; If there are any fertile years, potentially adds children
if fertility-end-years-ago < fertility-start-years-ago [
; A fairly consistent equation for a wife's number of children can be derived
; based on the number of "child-bearing years," or the number of married years
; when the wife is between the ages of 15 and 45
; The equation is y = 0.256 + 0.9495 * x, where "y" is number of children and "x" is child-bearing years
; There is a stochastic component based on the standard deviation of the residuals (1.9625)
let child-bearing-years fertility-start-years-ago - fertility-end-years-ago
let this-wife-children round (0.2562 * child-bearing-years + 0.9435 + random-normal 0 1.9625)
if this-wife-children > 0 [
; This initializes children in the household
; First, creates a list of all possible ages for the children by iterating
; through the numbers from fertile-end-years-ago to fertile-start-years-ago
let children-possible-ages []
let possible-ages-iterator fertility-end-years-ago
while [possible-ages-iterator <= fertility-start-years-ago][
set children-possible-ages lput possible-ages-iterator children-possible-ages
set possible-ages-iterator possible-ages-iterator + 1
]
; Now, iterates through the number of children assigned to that wife
let children-iterator 0
while [children-iterator < this-wife-children][
; Assigns gender with a 50% probability
ifelse random-float 1 > 0.5 [
; In this case, it's a boy
; Take a random age from the table of all possible ages and add it to the list of boys' ages
set boys-ages lput (one-of children-possible-ages) boys-ages
]
[
; In this case, it's a girl
; Take a random age from the table of all possible ages and add it to the list of girls' ages
set girls-ages lput (one-of children-possible-ages) girls-ages
]
set children-iterator children-iterator + 1
]
]
]
set wives-birth-iterator wives-birth-iterator + 1
]
; The number of children currently is calculated
set num-boys length boys-ages
set num-girls length girls-ages
set num-children length boys-ages + length girls-ages
; Checks once to see if the "split age" (the age at which a child leaves the household)
; is less than the current age for any of the children. If so, they would have already
; left the household when the model started, and they are removed.
; However, new househols are NOT spawned during initialization
;children-leave-household false
end
; Creates a household with the given ethnicity, household head age, and display color
; If "from-floodplain" is true, then the household may stay in the village of the original household
; The new household may appear in the same village as the old household, or in a random habitable
; location in the study area, based on the global variable "stay-in-village-prob"
; If "gets-married" is true, then the household head will get married at the same time the household
; is created
; ==============================================================================================================
; ===================== BASIC HOUSEHOLD FUNCTIONS: Initializing, wives, payoffs =====================
; ==============================================================================================================
to create-household [ how-many-canals how-many-fields this-head-age this-village from-floodplain gets-married ]
hatch 1 [
set size 0.7
set num-canals how-many-canals
set num-fields how-many-fields
set total-wealth 0
ifelse num-canals > 0 [set color yellow][set color orange]
set head-age this-head-age
; Initializes empty lists for family demographics
set num-wives 0
set wives-current-age []
set num-children 0
set num-boys 0
set num-girls 0
set boys-ages []
set girls-ages []
; In most cases, a husband will get married at the same time that he starts a new household
; This behavior is determined by the gets-married variable
if gets-married [
add-wife
]
; Based on the global variable stay-in-village-prob, the new household will either move
; to a patch with the same village value or move to a random habitable tile on the
; floodplain
ifelse (from-floodplain = true) and (random-float 1 < stay-in-village-prob) [
; Moves the turtle to a patch that is within the current village
move-to one-of patches with [ village-num = this-village ]
][
; Moves the turtle to a random habitable location on the floodplain
; This location is not necessarily the home village of the original household
move-to one-of patches with [land-cover = 3]
]
; Randomly positions the turtle within the given patch
set heading 0
fd random-float 1 - 0.5
set heading 90
fd random-float 1 - 0.5
]
end
to add-wife
; Estimate the age of this wife based on a reporter, "get-wife-age-at-marriage"
let this-wife-marriage-age get-wife-age-at-marriage head-age
; Update household variables accordingly
set num-wives num-wives + 1
set wives-current-age lput this-wife-marriage-age wives-current-age
set wives-marriage-age lput this-wife-marriage-age wives-marriage-age
end
; This turtle function sets expected payoffs for fishing, canals, and fields
to initialize-expected-payoffs
set fishing-payoff-past-5-yrs []
set canal-payoff-past-5-yrs []
set field-payoff-past-5-yrs []
let year-iterator 0
while [year-iterator < 5][
set fishing-payoff-past-5-yrs lput rand-fishing-payoff num-canals fishing-payoff-past-5-yrs
set canal-payoff-past-5-yrs lput rand-canal-payoff canal-payoff-past-5-yrs
set field-payoff-past-5-yrs lput rand-field-payoff field-payoff-past-5-yrs
set year-iterator year-iterator + 1
]
set fishing-expected-payoff mean fishing-payoff-past-5-yrs
set canal-expected-payoff mean canal-payoff-past-5-yrs
set field-expected-payoff mean field-payoff-past-5-yrs
update-expected-income
end
; ==============================================================================================================
; ===================== BASIC PAYOFF FUNCTIONS: FISHING, CANALS, AND FIELDS =====================
; ==============================================================================================================
; This reporter gives a household's baseline payoff from river fishing for the year
to-report rand-fishing-payoff [number-of-canals]
; The fishing payoff is determined by a LOG-NORMAL distribution
; The mean of the logged dataset is ln-fishing-payoff-mean and the standard deviation is ln-fishing-payoff-sd
ifelse number-of-canals = 0 [
let this-fishing-payoff ((log-normal nco-fishing-payoff-mean nco-fishing-payoff-sd) * revenue-multiplier)
if this-fishing-payoff < 0 [set this-fishing-payoff 0]
report this-fishing-payoff - annual-fishing-cost
][
; River fishing payoffs for canal-owning households
; Only about 70% of canal-owning households receive income from river fishing
let my-random-num random-float 1
ifelse my-random-num < .7 [
let this-co-fishing-payoff ((log-normal co-fishing-payoff-mean co-fishing-payoff-sd) * revenue-multiplier)
if this-co-fishing-payoff < 0 [set this-co-fishing-payoff 0]
report this-co-fishing-payoff - annual-fishing-cost
][report 0]
]
end
; This reporter gives a household's payoff per canal for the year
to-report rand-canal-payoff
; The canal payoff is determined by a LOG-NORMAL distribution
; The mean of the dataset is canal-payoff-mean and the standard deviation is canal-payoff-sd
; The canal is also associated with two costs, which are deducted from the net payoff
; Canal maintenance costs are distributed across a log-normal distribution
; Canal annual taxes are a fixed fee taken by the local government
let this-year-canal-payoff ((log-normal canal-payoff-mean canal-payoff-sd) * revenue-multiplier) - (random-normal canal-maintenance-cost-mean canal-maintenance-cost-sd)
if this-year-canal-payoff < 0 [set this-year-canal-payoff 0]
report this-year-canal-payoff - canal-annual-taxes
end
; This reporter gives a household's payoff per rice field for the year
to-report rand-field-payoff
; The field payoff is determined by a RANDOM NORMAL distribution
let this-field-payoff ((random-normal field-payoff-mean field-payoff-sd) * revenue-multiplier)
if this-field-payoff < 0 [set this-field-payoff 0]
report this-field-payoff - field-maintenance-cost
end
; ==============================================================================================================
; ===================== YEARLY FUNCTIONS: UPDATING DEMOGRAPHICS =====================
; ==============================================================================================================
; Observer function
; Update the year
to update-year
set this-year this-year + 1
end
; Turtle function adding 1 to the age of each household member
to update-ages
; Add 1 to the household head age
set head-age head-age + 1
; Set temporary lists that can be used to store the new values
let wives-temp-list []
; Read each value in the existing list and add those values plus one to the temporary list
foreach wives-current-age [set wives-temp-list lput (? + 1) wives-temp-list]
; Set the temporary list as the new ages list
set wives-current-age wives-temp-list
; This process is the same for wives, boys, girls, and widows in the family:
let boys-temp-list []
foreach boys-ages [set boys-temp-list lput (? + 1) boys-temp-list]
set boys-ages boys-temp-list
let girls-temp-list []
foreach girls-ages [set girls-temp-list lput (? + 1) girls-temp-list]
set girls-ages girls-temp-list
let widows-temp-list []
foreach widows-ages [set wives-temp-list lput (? + 1) wives-temp-list]
set widows-ages widows-temp-list
end
to children-born
; Children born within each household
; Iterates between the number of wives
if length wives-current-age > 0 [
let wives-iterator 0
while [wives-iterator < length wives-current-age] [
; Original code:
; If the wife's age is below 45, there is a chance she will have a child
;if item wives-iterator wives-current-age < 45 [
; Code with slider:
if item wives-iterator wives-current-age < wife-max-childbearing-age [
; Might have a child based on the regression
; num-children = 0.2562 * child-bearing-years + (other factors)
; Original code (without slider):
;if random-float 1 < 0.2562 [
; New code (with slider):
if random-float 1 < wife-annual-childbearing-prob [
; A child is added to the family
; 50% chance of male, 50% chance of female
ifelse random-float 1 < 0.5 [
; The child is a boy
set boys-ages lput 0 boys-ages
][
; The child is a girl
set girls-ages lput 0 girls-ages
]
]
]
set wives-iterator wives-iterator + 1
]
]
set num-children length boys-ages + length girls-ages
set num-boys length boys-ages
set num-girls length girls-ages
end
to children-leave-household[spawn-new-households]
; This function checks to see if children have exceeded the "threshold age"
; at which they will leave the house.
; Girls will marry into other households; their movement is not explicitly included.
; Boys are randomly assigned to either emigrate from the floodplain
; or to start a new household within the floodplain, in which case a new household
; is created.
; If "spawn-new-households" is set to false, then no new households will be created when
; boys leave the house. This setting is used during initialization. Otherwise,
; "spawn-new-households" should be set as true.
let boys-iterator length boys-ages - 1
; iterate through all the boys
; These lists iterate from maximum to 0, so that when items are removed
; from the list, it will not change the results of future iterations
while [boys-iterator >= 0][
let this-age item boys-iterator boys-ages
if leaves-household-this-year "male" this-age [
; If the child is leaving the household, remove him from the list
set boys-ages remove-item boys-iterator boys-ages
if spawn-new-households = true [
; Check to see whether the boy emigrates or starts a new household.
; The probability of emigration is a global variable that will eventually
; be controlled by the user. For now, it is set under the "setup" command
; directly above "initialize-household-attributes"
if random-float 1 < (1 - emigration-probability) [
; Spawn a new household
let how-many-canals 0
let village-here [village-num] of patch-here
let give-how-many-fields 0
if num-fields > 1 [
; The father gives his son a field
set give-how-many-fields 1
set num-fields num-fields - 1
]
create-household how-many-canals give-how-many-fields this-age village-here true false
]
]
]
set boys-iterator boys-iterator - 1
]
let girls-iterator length girls-ages - 1
; iterate through all the girls
while [girls-iterator >= 0][
; If the child is leaving the household, remove her from the list
let this-age item girls-iterator girls-ages
if leaves-household-this-year "female" this-age [
set girls-ages remove-item girls-iterator girls-ages
]
set girls-iterator girls-iterator - 1
]
set num-children length boys-ages + length girls-ages
set num-boys length boys-ages
set num-girls length girls-ages
end
; Children die at a set rate based on the dies-this-year function
to children-die
; Iterate BACKWARDS through each of the children
let boys-iterator length boys-ages - 1
let girls-iterator length girls-ages - 1
while [boys-iterator >= 0][
; Random selection based on chance
if dies-this-year "male" item boys-iterator boys-ages [
; One of the boys in the household dies
set boys-ages remove-item boys-iterator boys-ages
]
set boys-iterator boys-iterator - 1
]
while [girls-iterator >= 0][
; Random selection based on chance
if dies-this-year "female" item girls-iterator girls-ages [
; One of the girls in the household dies
set girls-ages remove-item girls-iterator girls-ages
]
set girls-iterator girls-iterator - 1
]
set num-children length boys-ages + length girls-ages
set num-boys length boys-ages
set num-girls length girls-ages
end
; Wives die if they reach their life expectancy
; If wives die, they are removed from the list
to wives-die
; Iterate BACKWARDS through each of the wives
let wives-iterator length wives-current-age - 1
while [wives-iterator >= 0][
; If the wife has reached her life expectancy, then she passes away
if dies-this-year "female" item wives-iterator wives-current-age [
; Remove the wife from the household lists
set wives-current-age remove-item wives-iterator wives-current-age
set wives-marriage-age remove-item wives-iterator wives-marriage-age
]
set wives-iterator wives-iterator - 1
]
; Update the number of wives
set num-wives length wives-current-age
end
; Widows die if they reach their life expectancy
; If widows die, they are removed from the list
to widows-die
let widows-iterator length widows-ages - 1
while [widows-iterator >= 0][
if dies-this-year "female" item widows-iterator widows-ages [
set widows-ages remove-item widows-iterator widows-ages
]
set widows-iterator widows-iterator - 1
]
; Update the number of widows
set num-widows length widows-ages
end
; This reporter determines whether or not a person dies in a given year
to-report dies-this-year [gender age]
let this-year-die-prob 0
ifelse gender = "male" [
; This switching logic applies to all males on the floodplain
if age < 1 [ set this-year-die-prob 0.066 ]
if age >= 1 and age < 5 [ set this-year-die-prob 0.0154545895 ]
if age >= 5 and age < 10 [ set this-year-die-prob 0.0043781693 ]
if age >= 10 and age < 15 [ set this-year-die-prob 0.00285627 ]
if age >= 15 and age < 20 [ set this-year-die-prob 0.0041950495 ]
if age >= 20 and age < 25 [ set this-year-die-prob 0.0066683425 ]
if age >= 25 and age < 30 [ set this-year-die-prob 0.0110202289 ]
if age >= 30 and age < 35 [ set this-year-die-prob 0.0149397744 ]
if age >= 35 and age < 40 [ set this-year-die-prob 0.016516663 ]
if age >= 40 and age < 45 [ set this-year-die-prob 0.0171588335 ]
if age >= 45 and age < 50 [ set this-year-die-prob 0.0177597107 ]
if age >= 50 and age < 55 [ set this-year-die-prob 0.0190954814 ]
if age >= 55 and age < 60 [ set this-year-die-prob 0.0213526036 ]
if age >= 60 and age < 65 [ set this-year-die-prob 0.0289931664 ]
if age >= 65 and age < 70 [ set this-year-die-prob 0.0440064017 ]
if age >= 70 and age < 75 [ set this-year-die-prob 0.0673121253 ]
if age >= 75 and age < 80 [ set this-year-die-prob 0.0978732061 ]
if age >= 80 and age < 85 [ set this-year-die-prob 0.1417353059 ]
if age >= 85 [ set this-year-die-prob .5 ]
][
; This switching logic applies to all females on the floodplain
if age < 1 [ set this-year-die-prob 0.0667 ]
if age >= 1 and age < 5 [ set this-year-die-prob 0.0145912622 ]
if age >= 5 and age < 10 [ set this-year-die-prob 0.0040527162 ]
if age >= 10 and age < 15 [ set this-year-die-prob 0.0026944814 ]
if age >= 15 and age < 20 [ set this-year-die-prob 0.0043171144 ]
if age >= 20 and age < 25 [ set this-year-die-prob 0.0081931603 ]
if age >= 25 and age < 30 [ set this-year-die-prob 0.0131619432 ]
if age >= 30 and age < 35 [ set this-year-die-prob 0.0154288071 ]
if age >= 35 and age < 40 [ set this-year-die-prob 0.0140915886 ]
if age >= 40 and age < 45 [ set this-year-die-prob 0.0132885068 ]
if age >= 45 and age < 50 [ set this-year-die-prob 0.0118369283 ]
if age >= 50 and age < 55 [ set this-year-die-prob 0.0123828983 ]
if age >= 55 and age < 60 [ set this-year-die-prob 0.0152585985 ]
if age >= 60 and age < 65 [ set this-year-die-prob 0.021374408 ]
if age >= 65 and age < 70 [ set this-year-die-prob 0.0329168754 ]
if age >= 70 and age < 75 [ set this-year-die-prob 0.0531841559 ]
if age >= 75 and age < 80 [ set this-year-die-prob 0.0797995056 ]
if age >= 80 and age < 85 [ set this-year-die-prob 0.1241857069 ]
if age >= 85 [ set this-year-die-prob .5 ]
]
; The person has a chance of dying equal to their assigned probability
; "True" means the person has died - "False" means the person does not die this year
ifelse random-float 1 < this-year-die-prob [report true][report false]
end
; This reporter determines a wife's age at marriage based on her husband's age at marriage
to-report get-wife-age-at-marriage [husband-age-at-marriage]
; Determine the wife's approximate age based on a known relationship
; between the husband's age at the time of marriage and the husband-wife age difference
let wife-marriage-age round (-12.316 + husband-age-at-marriage * 0.8906 + random-normal 0 19.21)
report wife-marriage-age
end
; This reporter determines whether or not a child will leave the household this year
to-report leaves-household-this-year [gender age]
let this-year-leave-prob 0
ifelse gender = "male" [
; This switching logic applies to all household boys on the floodplain
if age < 10 [set this-year-leave-prob 0 ]
if age >= 10 and age < 15 [set this-year-leave-prob 0.0026025076 ]
if age >= 15 and age < 20 [set this-year-leave-prob 0.0351760662 ]
if age >= 20 and age < 25 [set this-year-leave-prob 0.0725306346 ]
if age >= 25 and age < 30 [set this-year-leave-prob 0.1005856027 ]
if age >= 30 and age < 35 [set this-year-leave-prob 0.0691085223 ]
if age >= 35 and age < 40 [set this-year-leave-prob 0.0817666286 ]
if age >= 40 and age < 45 [set this-year-leave-prob 0.0627051909 ]
if age >= 45 and age < 50 [set this-year-leave-prob 0.0918698897 ]
if age >= 50 and age < 55 [set this-year-leave-prob 0.0778920885 ]
if age >= 55 and age < 60 [set this-year-leave-prob 0.0650801239 ]
if age >= 60 and age < 65 [set this-year-leave-prob 0.0688500849 ]
if age >= 65 and age < 70 [set this-year-leave-prob 0.0303597339 ]
if age >= 70 and age < 75 [set this-year-leave-prob 0.1972584382 ]
if age >= 75 and age < 80 [set this-year-leave-prob 0.1294494367 ]
if age >= 80 [ set this-year-leave-prob 1 ]
][
; This switching logic applies to all household girls on the floodplain
if age < 5 [set this-year-leave-prob 0.0060053797 ]
if age >= 5 and age < 10 [set this-year-leave-prob 0.0148213717 ]
if age >= 10 and age < 15 [set this-year-leave-prob 0.0968863666 ]
if age >= 15 and age < 20 [set this-year-leave-prob 0.2139969144 ]
if age >= 20 and age < 25 [set this-year-leave-prob 0.1097662007 ]
if age >= 25 and age < 30 [set this-year-leave-prob 0.0814662578 ]
if age >= 30 and age < 35 [set this-year-leave-prob 0.0596441767 ]
if age >= 35 and age < 40 [set this-year-leave-prob 0.1514244089 ]
if age >= 40 and age < 45 [set this-year-leave-prob 0.1141672897 ]
if age >= 45 and age < 50 [set this-year-leave-prob 0.1294494367 ]
if age >= 50 and age < 55 [set this-year-leave-prob 0.1972584382 ]
if age >= 55 [set this-year-leave-prob 1 ]
]
ifelse random-float 1 < this-year-leave-prob [report true][report false]
end
; Household heads die when they reach their life expectancy
; - If any males in the household are already near adulthood (15), they oldest son become the household head, and the wives turn into widows
; - If there are no boys nearing adulthood, the wives (as widows) and children are added to another household of the same ethnicity
to head-dies
if (dies-this-year "male" head-age) [
; Set the minimum age at which a boy from the family can become the new household head
let min-household-head-age 15
let maximum-boy-age 0
if length boys-ages > 0 [
set maximum-boy-age max boys-ages
]