-
Notifications
You must be signed in to change notification settings - Fork 0
/
reported_statistics.py
187 lines (118 loc) · 5.13 KB
/
reported_statistics.py
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
#!/usr/bin/env python
# https://stackoverflow.com/a/2429517/
# Multiple quantities are reported in the Results/Discussion/Supplementary
# Information sections of my paper. However, as there is no "big table of
# results", only figures visualising the findings, the following code is used
# to obtain the reported quantities as needed and it is included on GitHub
# for transparency/reproducibility. Note that this script will only
# run without error after running "visualiation.py" in full as the Pandas
# dataframe of results — i.e., "model_pmeans" — is created therin.
# Note, for pd.query(), the strings tested for equality must be wrapped in quotes.
# https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.query.html
# Reported quantities (i.e., the fraction of lenders of various types) only
# only relate to the baeline model, not the "Extended" or "Sex"-specific models.
model, parm = "Baseline", "frac"
# Posterior Mean Proportion of Lenders Who are Non-indebted Non-Friend Kin
model_pmeans.query(
f"model == '{model}' and parameter == '{parm}' and categories == 'family_lender_ij'",
inplace = False
)
# Posterior Mean Proportion of Lenders Who are Non-indebted Non-Kin-Who-Are-Not-Friends (i.e., Strangers)
model_pmeans.query(
f"model == '{model}' and parameter == '{parm}' and categories == 'stranger_lender_ij'",
inplace = False
)
# Posterior Mean Proportion of Lenders Who are Non-indebted Non-Kin Friends
model_pmeans.query(
f"model == '{model}' and parameter == '{parm}' and categories == 'friend_lender_ij'",
inplace = False
)
# Posterior Mean Proportion of Lenders Who are Non-indebted Friends-Who-Are-Kin
model_pmeans.query(
f"model == '{model}' and parameter == '{parm}' and categories == 'friend_family_lender_ij'",
inplace = False
)
# Village-Specific Posterior Mean Proportion of Lenders Who are Non-indebted Friends-Who-Are-Kin
# Note, model_pmeans includes posterior means and HDIs for parameters from all three models
# On the calling of local variables in pd.query with "@", see:
# https://stackoverflow.com/a/57696055
np.sort(
model_pmeans.query(
f"parameter.isin(@fraction_parameter_names) and model == 'Extended' and categories == 'friend_family_lender_ij'",
inplace = False
)["pmean"].values
)
model_pmeans.query(
f"parameter.isin(@fraction_parameter_names) and model == 'Extended' and categories == 'friend_family_lender_ij'",
inplace = False
).sort_values(by = "pmean")
# Posterior Mean Proportion of Lenders Who are Indebted Non-Kin-Who-Are-Not-Friends (i.e., Pure Reciprocity)
model_pmeans.query(
f"model == '{model}' and parameter == '{parm}' and categories == 'lender_ij_lender_ji'",
inplace = False
)
# Posterior Mean Proportion of Lenders Who are Indebted Non-Friend Kin
model_pmeans.query(
f"model == '{model}' and parameter == '{parm}' and categories == 'family_lender_ij_lender_ji'",
inplace = False
)
# Posterior Mean Proportion of Lenders Who are Indebted Non-Kin Friends
model_pmeans.query(
f"model == '{model}' and parameter == '{parm}' and categories == 'friend_lender_ij_lender_ji'",
inplace = False
)
# Posterior Mean Proportion of Lenders Who are Indebted Friends-Who-Are-Kin
model_pmeans.query(
f"model == '{model}' and parameter == '{parm}' and categories == 'friend_family_lender_ij_lender_ji'",
inplace = False
)
# Sum of Posterior Mean Proportions of Lenders of Any Type Who are Indebted
types_of_lender_indebted = [
"friend_lender_ij_lender_ji",
"family_lender_ij_lender_ji",
"friend_family_lender_ij_lender_ji",
"lender_ij_lender_ji"
]
sum([
model_pmeans.query(
f"model == '{model}' and parameter == '{parm}' and categories == '{lender}'",
inplace = False
)["pmean"].item()
for lender in types_of_lender_indebted
])
# Sum of Posterior Mean Proportions of Lenders Who are Intimates, Ignoring Indebtedness
types_of_lender_intimates = [
"friend_lender_ij",
"family_lender_ij",
"friend_family_lender_ij",
"friend_lender_ij_lender_ji",
"family_lender_ij_lender_ji",
"friend_family_lender_ij_lender_ji"
]
sum([
model_pmeans.query(
f"model == '{model}' and parameter == '{parm}' and categories == '{lender}'",
inplace = False
)["pmean"].item()
for lender in types_of_lender_intimates
])
# Sum of Posterior Mean Proportions of Lenders Who Non-Indebted
types_of_lender_not_indebted = [
"friend_lender_ij",
"family_lender_ij",
"friend_family_lender_ij",
"stranger_lender_ij"
]
sum([
model_pmeans.query(
f"model == '{model}' and parameter == '{parm}' and categories == '{lender}'",
inplace = False
)["pmean"].item()
for lender in types_of_lender_not_indebted
])
# Percentage of 3,184 Villagers Naming the Maximum Number of Lenders and Friends (i.e., 5)
max_nominations = pd.get_dummies(nominations, columns = ["type"])
max_nominations = max_nominations.loc[:, ["i_ID", "type_lender", "type_friend"]]
max_nominations = max_nominations.groupby(by = ["i_ID"]).sum(numeric_only = True)
max_nominations["type_lender"].value_counts()/3184
max_nominations["type_friend"].value_counts()/3184