-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreporters.nls
80 lines (72 loc) · 2.62 KB
/
reporters.nls
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
;t1 recruited citizens
to-report t1
report count citizens with [ recruited? ]
end
;t2 citizen at risk (over threshold)
to-report t2
report count citizens with [ risk > radicalization-threshold ]
end
;t3 risk of citizens
to-report t3.mean
report mean [ risk ] of citizens
end
to-report t3.median
report median [ risk ] of citizens
end
to-report t3.sd
report standard-deviation [ risk ] of citizens
end
to-report t3 [ operator the-area ]
ifelse the-area = 0 [
report runresult (word operator " [ risk ] of citizens")
] [
report runresult (word operator " [ risk ] of citizens with [ area = " the-area " ]")
]
end
to-report t3.bins
report make-histo " [ risk ] of citizens " 10 -0.662 3.05
end
;t4.mean, t4.median, t4.sd mean, median and standard deviation of propensity of citizens (constants)
to-report t4 [ operator the-area ]
ifelse the-area = 0 [
report runresult (word operator " [ propensity ] of citizens")
] [
report runresult (word operator " [ propensity ] of citizens with [ area = " the-area " ]")
]
end
; t5, opinions
to-report t5 [ operator opinion the-area ]
let query (word operator " [ value ] of link-set [ my-in-topic-links with [ [ breed ] of other-end = citizens")
if the-area != 0 [ set query (word query " and [ area ] of other-end = " the-area) ]
set query (word query " ] ] of topic-by-name \"" opinion "\"")
report runresult query
end
; t6, locations
to-report t6 [ building the-area ]
ifelse the-area = 0 [
report count citizens with [ [ shape ] of locations-here = (list building) ]
] [
report count citizens with [ [ shape ] of locations-here = (list building) and [ area-id ] of patch-here = the-area ]
]
end
;t5.bins "Collective relative deprivation"
; t5, opinion bins
to-report t5.bins [ opinion ]
let query (word " [ value ] of [ my-in-topic-links] of topic-by-name \"" opinion "\"")
report make-histo query 20 -2 2
end
; this procedure creates a list of values counting the number of citizens in the bins as created. For example,
; [[-0.662 3] [-0.2 34] [0.07 80]] means that in the second bin, the one from -0.2 to 0.07, there are 34 cases.
; objects falling outside of bins are not counte
to-report make-histo [ reporter bins min-v max-v ]
let values filter [ i -> i >= min-v and i < max-v ] runresult reporter
let counts n-values bins [ 0 ]
let thresholds (sentence (range min-v max-v ((max-v - min-v) / bins)) max-v)
let i 0
foreach values [ v ->
set i 0
while [ v > item (i + 1) thresholds ] [ set i i + 1 ]
set counts replace-item i counts (item i counts + 1)
]
report (map [ [ a b ] -> (list a b) ] but-last thresholds counts)
end