-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExploratoryDataAnalysisCode.R
331 lines (269 loc) · 10 KB
/
ExploratoryDataAnalysisCode.R
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
library(tidyverse)
library(GGally)
library(knitr)
library(tsne)
options(warn=-1)
aave <- read_csv("data/AaveWalletSegmentationDataWithClusters.csv")
dem_vars <- c("agedays", "num_chains_active", "num_tokens", "aave_amt",
"bal_usd", "eth_bal_usd_", "aave_asset_usd", "aave_debt_usd",
"aave_net_usd", "lens_prof_count", "lens_id",
"lens_name", "lens_followers", "lens_following",
"lens_posts", "lens_comments", "lens_mirrors", "lens_publications",
"lens_collects", "snap_voted_aave_numprop",
"trustalabs_score")
aave <- aave %>%
mutate(`User Type` = ifelse(!iscontract & !ismultisig, "Single Wallets",
ifelse(iscontract & !ismultisig, "Contracts",
ifelse(ismultisig, "Multi-Signature Safes", "Other"))))
###
# Part One: Histograms
###
# C Histograms
p11 <- aave %>%
select(starts_with("C_")) %>%
gather(key = Chain, value = Value) %>%
ggplot(aes(x = Value, fill = Chain)) +
geom_histogram(colour = "black") +
facet_wrap(~Chain, ncol = 1, scales = "free_y") +
scale_fill_brewer(palette = "Dark2") +
scale_x_log10(labels = scales::comma, breaks = 10^(0:6)) +
scale_y_continuous(labels = scales::comma) +
theme(legend.position = "off") +
labs(
title = "Distribution of Number of Calls by Chain",
subtitle = "For AAVE",
x = "Number of Calls",
y = "Number of Wallet Addresses"
)
p11
ggsave(p11, filename = "images/p11.png", dpi = 300, width = 12, height = 12)
aave %>%
select(starts_with("C_")) %>%
gather(key = Chain, value = Value) %>%
summary(Value)
# E Histograms
p12 <- aave %>%
select(starts_with("E_")) %>%
gather(key = Chain, value = Value) %>%
ggplot(aes(x = Value, fill = Chain)) +
geom_histogram(colour = "black") +
facet_wrap(~Chain, ncol = 1, scales = "free_y") +
scale_fill_brewer(palette = "Set1") +
scale_x_log10(labels = scales::comma, breaks = 10^(0:6)) +
scale_y_continuous(labels = scales::comma) +
theme(legend.position = "off") +
labs(
title = "Distribution of Number of Call Types",
subtitle = "For AAVE",
x = "Number of Calls",
y = "Number of Wallet Addresses"
)
p12
ggsave(p12, filename = "images/p12.png", dpi = 300, width = 12, height = 12)
aave %>%
select(starts_with("E_")) %>%
gather(key = Chain, value = Value) %>%
summary(Value)
# E Histograms
p13 <- aave %>%
select(starts_with("V_")) %>%
gather(key = Chain, value = Value) %>%
ggplot(aes(x = Value, fill = Chain)) +
geom_histogram(colour = "black") +
facet_wrap(~Chain, ncol = 1, scales = "free_y") +
scale_fill_brewer(palette = "Set2") +
scale_x_log10(labels = scales::comma, breaks = 10^(0:6)) +
scale_y_continuous(labels = scales::comma) +
theme(legend.position = "off") +
labs(
title = "Distribution of Number of Version Calls",
subtitle = "For AAVE",
x = "Number of Calls",
y = "Number of Wallet Addresses"
)
p13
ggsave(p13, filename = "images/p13.png", dpi = 300, width = 12, height = 12)
aave %>%
select(starts_with("V_")) %>%
gather(key = Chain, value = Value) %>%
summary(Value)
###
# Part Two: User Type
###
# C Histograms
p21 <- aave %>%
select(`User Type`, starts_with("C_")) %>%
gather(key = Chain, value = Value, 2:ncol(.)) %>%
filter(!is.na(`User Type`)) %>%
ggplot(aes(x = Value, fill = Chain)) +
geom_histogram(colour = "black") +
facet_grid(Chain~`User Type`, scales = "free_y") +
scale_fill_brewer(palette = "Dark2") +
scale_x_log10(labels = scales::comma, breaks = 10^(0:6)) +
scale_y_continuous(labels = scales::comma) +
theme(legend.position = "off") +
labs(
title = "Distribution of Number of Calls by Chain",
subtitle = "For AAVE, Split by User Type",
x = "Number of Calls",
y = "Number of Wallet Addresses"
)
p21
ggsave(p21, filename = "images/p21.png", dpi = 300, width = 12, height = 12)
aave %>%
select(`User Type`, starts_with("C_")) %>%
gather(key = Chain, value = Value, 2:ncol(.)) %>%
filter(!is.na(`User Type`)) %>%
summary(Value)
# E Histograms
p22 <- aave %>%
select(`User Type`, starts_with("E_")) %>%
gather(key = Chain, value = Value, 2:ncol(.)) %>%
filter(!is.na(`User Type`)) %>%
ggplot(aes(x = Value, fill = Chain)) +
geom_histogram(colour = "black") +
facet_grid(Chain~`User Type`, scales = "free_y") +
scale_fill_brewer(palette = "Set1") +
scale_x_log10(labels = scales::comma, breaks = 10^(0:6)) +
scale_y_continuous(labels = scales::comma) +
theme(legend.position = "off") +
labs(
title = "Distribution of Number of Call Types",
subtitle = "For AAVE, Split by User Type",
x = "Number of Calls",
y = "Number of Wallet Addresses"
)
p22
ggsave(p22, filename = "images/p22.png", dpi = 300, width = 12, height = 12)
aave %>%
select(`User Type`, starts_with("E_")) %>%
gather(key = Chain, value = Value, 2:ncol(.)) %>%
filter(!is.na(`User Type`)) %>%
summary(Value)
# V Histograms
p23 <- aave %>%
select(`User Type`, starts_with("V_")) %>%
gather(key = Chain, value = Value, 2:ncol(.)) %>%
filter(!is.na(`User Type`)) %>%
ggplot(aes(x = Value, fill = Chain)) +
geom_histogram(colour = "black") +
facet_grid(Chain~`User Type`, scales = "free_y") +
scale_fill_brewer(palette = "Set2") +
scale_x_log10(labels = scales::comma, breaks = 10^(0:6)) +
scale_y_continuous(labels = scales::comma) +
theme(legend.position = "off") +
labs(
title = "Distribution of Number of Version Calls",
subtitle = "For AAVE, Split by User Type",
x = "Number of Calls",
y = "Number of Wallet Addresses"
)
ggsave(p23, filename = "images/p23.png", dpi = 300, width = 12, height = 12)
# Table
aave %>%
select(`User Type`, starts_with("C_"), starts_with("E_"), starts_with("V_")) %>%
gather(key = Variable, value = Value, 2:ncol(.)) %>%
group_by(`User Type`, Variable) %>%
summarise(`Mean Count` = mean(Value, na.rm = TRUE),
`Median Count` = median(Value, na.rm = TRUE),
`SD Count` = sd(Value, na.rm = TRUE)) %>%
filter(!is.na(`User Type`)) %>%
kable()
###
# Part Three: Analysis
###
# CE Histograms
p31 <- aave %>%
filter(`User Type` == "Single Wallets") %>%
select(starts_with("CE_ethereum_"), one_of(dem_vars)) %>%
mutate(across(everything(), as.numeric)) %>%
gather(key = Variable, value = Value) %>%
mutate(Group = ifelse(str_starts(Variable, "CE_ethereum_"), "blue", "gold")) %>%
ggplot(aes(x = Value, fill = Group)) +
geom_histogram(colour = "black") +
facet_wrap(~Variable, scales = "free") +
scale_fill_manual(values = c("blue", "gold")) +
scale_x_continuous(trans=scales::pseudo_log_trans(base = 10)) +
scale_y_continuous(labels = scales::comma) +
theme(legend.position = "off") +
labs(
title = "Distribution Plots of the Feature Set",
subtitle = "For AAVE, for Single Wallets with Debank Data",
x = "Amounts, Values or Scores",
y = "Number of Wallet Addresses"
)
p31
ggsave(p31, filename = "images/p31.png", dpi = 300, width = 12, height = 12)
aave %>%
filter(`User Type` == "Single Wallets") %>%
select(starts_with("CE_ethereum_"), one_of(dem_vars)) %>%
mutate(across(everything(), as.numeric)) %>%
gather(key = Variable, value = Value) %>%
summary(Value)
p32 <- aave %>%
filter(`User Type` == "Single Wallets") %>%
select(starts_with("CE_ethereum_"), one_of(dem_vars)) %>%
mutate(across(everything(), as.numeric)) %>%
ggpairs(cardinality_threshold = 50)
ggsave(p32, filename = "images/p32.png", dpi = 300, width = 30, height = 30)
###
# Part Four: Debank Only
###
aave_final <- aave %>%
filter(if_debank_data, `User Type` == "Single Wallets")
p41 <- aave_final %>%
select(starts_with("CE_ethereum_"), one_of(dem_vars)) %>%
mutate(across(everything(), as.numeric)) %>%
gather(key = Variable, value = Value) %>%
mutate(Group = ifelse(str_starts(Variable, "CE_ethereum_"), "blue", "gold")) %>%
ggplot(aes(x = Value, fill = Group)) +
geom_histogram(colour = "black") +
facet_wrap(~Variable, scales = "free") +
scale_fill_manual(values = c("blue", "gold")) +
scale_x_continuous(trans=scales::pseudo_log_trans(base = 10)) +
scale_y_continuous("Count", labels = scales::comma) +
theme(legend.position = "off") +
labs(
title = "Distribution of Various Variables",
subtitle = "For AAVE, for Single Wallets with Debank Data"
)
ggsave(p41, filename = "images/p41.png", dpi = 300, width = 12, height = 12)
p42 <- aave_final %>%
select(starts_with("CE_ethereum_"), one_of(dem_vars)) %>%
mutate(across(everything(), as.numeric)) %>%
ggpairs(cardinality_threshold = 50)
ggsave(p42, filename = "images/p42.png", dpi = 300, width = 30, height = 30)
aave_dist <- aave_final %>%
select(starts_with("CE_ethereum_"), one_of(dem_vars)) %>%
mutate(across(everything(), as.numeric)) %>%
select(1:10)
aave_maha <- mahalanobis(aave_dist, colMeans(aave_dist), cov(aave_dist))
aave_final %>%
mutate(ID = 1:nrow(.)) %>%
select(ID) %>%
cbind(Distance = aave_maha) %>%
arrange(desc(Distance)) %>%
slice(1:1000) %>%
mutate(ID = factor(ID, levels = ID)) %>%
ggplot(aes(x = ID, y = Distance, group = 1)) +
geom_point() +
geom_line() +
scale_y_log10(breaks = c(50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000)) +
scale_x_discrete(breaks = as.character(c(seq(1, 1000, by = 100)))) +
labs(
title = "Mahalanobis Distance for each observation",
subtitle = "For the top 1000 addresses"
)
###
# Part Five: PCA
###
aave_pca <- aave_final %>%
select(starts_with("CE_ethereum_"), one_of(dem_vars)) %>%
mutate(across(everything(), as.numeric))
aave_pca[is.na(aave_pca)] <- 0
my_pca <- prcomp(aave_pca)
ggpairs(my_pca$x[,1:6] %>% as_tibble)
my_tsne <- tsne(my_pca$x[,1:6] %>% as_tibble %>% slice(1:2000))
names(my_tsne) <- c("dim1", "dim2")
ggplot(my_tsne %>% as_tibble, aes(x = V1, y = V2)) +
geom_point()