-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
407 lines (326 loc) · 14.9 KB
/
index.html
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
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<title>Sharing session #22:</title>
<meta charset="utf-8" />
<meta name="author" content="Arif P. Sulistiono" />
<script src="AnalysingFPLv00_files/header-attrs/header-attrs.js"></script>
<link href="AnalysingFPLv00_files/remark-css/default.css" rel="stylesheet" />
<link href="AnalysingFPLv00_files/remark-css/metropolis.css" rel="stylesheet" />
<link href="AnalysingFPLv00_files/remark-css/metropolis-fonts.css" rel="stylesheet" />
<script src="AnalysingFPLv00_files/clipboard/clipboard.min.js"></script>
<link href="AnalysingFPLv00_files/xaringanExtra-clipboard/xaringanExtra-clipboard.css" rel="stylesheet" />
<script src="AnalysingFPLv00_files/xaringanExtra-clipboard/xaringanExtra-clipboard.js"></script>
<script>window.xaringanExtraClipboard(null, {"button":"<i class=\"fa fa-clipboard\"><\/i>","success":"<i class=\"fa fa-check\" style=\"color: #90BE6D\"><\/i>","error":"<i class=\"fa fa-times-circle\" style=\"color: #F94144\"><\/i>"})</script>
<link href="AnalysingFPLv00_files/font-awesome/css/all.css" rel="stylesheet" />
<link href="AnalysingFPLv00_files/font-awesome/css/v4-shims.css" rel="stylesheet" />
<link href="AnalysingFPLv00_files/panelset/panelset.css" rel="stylesheet" />
<script src="AnalysingFPLv00_files/panelset/panelset.js"></script>
<script src="AnalysingFPLv00_files/freezeframe/freezeframe.min.js"></script>
<script src="AnalysingFPLv00_files/xaringanExtra-freezeframe/freezeframe-init.js"></script>
<script id="xaringanExtra-freezeframe-options" type="application/json">{"selector":"img[src$=\"gif\"]","trigger":"click","overlay":false,"responsive":true,"warnings":true}</script>
<link href="AnalysingFPLv00_files/xaringanExtra-extra-styles/xaringanExtra-extra-styles.css" rel="stylesheet" />
<script src="AnalysingFPLv00_files/xaringanExtra-progressBar/progress-bar.js"></script>
<link rel="stylesheet" href="custom.css" type="text/css" />
</head>
<body>
<textarea id="source">
class: center, middle, inverse, title-slide
.title[
# Sharing session #22:
]
.subtitle[
## Analysing Fantasy Premier League data in R
]
.author[
### Arif P. Sulistiono
]
.date[
### <br>Tuesday, 4 August 2022<br> <a href="https://www.instagram.com/mof.dac"> <i class="fa fa-instagram fa-fw"></i>mof.dac</a>
]
---
<style>.xe__progress-bar__container {
top:0;
opacity: 1;
position:absolute;
right:0;
left: 0;
}
.xe__progress-bar {
height: 0.25em;
background-color: orange;
width: calc(var(--slide-current) / var(--slide-total) * 100%);
}
.remark-visible .xe__progress-bar {
animation: xe__progress-bar__wipe 200ms forwards;
animation-timing-function: cubic-bezier(.86,0,.07,1);
}
@keyframes xe__progress-bar__wipe {
0% { width: calc(var(--slide-previous) / var(--slide-total) * 100%); }
100% { width: calc(var(--slide-current) / var(--slide-total) * 100%); }
}</style>
# About me
.center[
![:scale 50%](https://media.giphy.com/media/1334O1WETb3sIM/giphy.gif)
An employee of the Republic of Indonesia’s Ministry of Finance. Funded by the Indonesia Endowment Fund for Education ("Lembaga Pengelola Dana Pendidikan"), at the moment, on study leave to join a PhD program in the <a href="https://www.nottingham.ac.uk/economics/people/arif.sulistiono">School of Economics, the University of Nottingham</a> with research interests in Indonesia's government bonds market and their bondholders' behaviour. Also a research assistant at <a href="https://www.tracktheeconomy.ac.uk/arif-sulistiono">tracktheeconomy.ac.uk</a>. <br> <br>
<a href="mailto:[email protected]"><i class="fa fa-envelope fa-fw"></i></a></a> <a href="https://www.facebook.com/arifpras"> <i class="fa fa-facebook fa-fw"></i></a> <a href="https://github.com/arifpras"><i class="fa fa-github fa-fw"></i></a> <a href="https://www.instagram.com/arifpras"> <i class="fa fa-instagram fa-fw"></i></a> <a href="https://arifpras.medium.com/"> <i class="fa fa-medium fa-fw"></i></a> <a href="https://twitter.com/arifpras"> <i class="fa fa-twitter fa-fw"></i></a> <a href="https://arifpras.com"> <i class="fa fa-wordpress fa-fw"></i></a>
]
---
# Limitations
.panelset[
.panel[.panel-name[1: Data availability]
* Historical statistics from previous seasons: 2020/2021 and 2021/2022
* Not included:
+ Pre-season matches
+ New players (i.e., Erling Haaland, Ivan Perišić, Kalidou Koulibaly, etc.)
+ New teams (i.e., Fulham, Bournemouth, Nottingham Forest)
]
.panel[.panel-name[2: Specifications]
* Software: RStudio 2022.07.1+554 "Spotted Wakerobin" Release for macOS
+ Alternative: Atom 1.60.0 x64
* Hardware: MBP 2020, chip M1, memory 16 GB.
+ Alternative: Cloud Computing Services - Amazon Web Services (AWS)
+ Multiple choices, depends on the price.
]
]
.left[.footnote[.small[Source: https://www.rstudio.com/products/rstudio/download/; https://ec2instances.github.io/]]]
---
# Today's session
* Web scrapping
+ library: dplyr, jsonlite, rvest
+ functions: read_csv(), fromJSON(), read_html()
* Data wrangling
+ library: dplyr
+ functions: mutate(), left_join(), right_join(), rename(), group_by() and ungroup(), select(), bind_rows(), etc.
* Data visualisation
+ library: ggplot2, tidyr, viridis, ggrepel, ggsoccer
+ functions: geom_col(), reorder_within(), scale_fill_manual(), scale_fill_viridis, etc.
* Basic statistics
+ library: dplyr, corrr
+ library: mean(), sum(), correlate(), combn(), choose(), etc.
---
# Previous lessons: Data Wrangling and Visualisation
<iframe src="https://arifpras.github.io/WranglingViz/" width="100%" height="400px" data-external="1"></iframe>
.left[.footnote[.small[Source: https://arifpras.github.io/WranglingViz/]]]
---
# Previous lessons: Basic Modelling
<iframe src="https://arifpras.github.io/BasicModelling/" width="100%" height="400px" data-external="1"></iframe>
.left[.footnote[.small[Source: https://arifpras.github.io/BasicModelling/]]]
---
# General rules
* Budget constraints = £100.0 for 15 players
+ 2 goalkeepers
+ 5 defenders
+ 5 midfielders
+ 3 forwards
* Chips
+ Bench boost: once a season, bench players' points included in the total points.
+ Free hit: once a season, unlimited transfers for a single Gameweek.
+ Triple captain: once a season, tripled the captain's points instead of doubled.
+ Wild card: twice a season, Gameweek 1 to 16 and Gameweek 17 to 38.
* Gameweek 1 deadline: Friday, 5 Aug 18:30 BST
* Total managers (as of 3 August 2022): 5,592,326 managers
---
# Initial budgeting plan and data sources
## Allocating the budget
* Goalkeepers: £9.0 for 2 players.
* Outfield players: £91.0 for 13 players.
+ Defenders: £35.0 for 5 players.
+ Midfielders: £35.0 for 5 players.
+ Forwards: £21.0 for 3 players.
* Left £0.00 in the bank (less flexibility)
## Data sources:
* vaastav's Github: https://github.com/vaastav/Fantasy-Premier-League/
* FPL data set: https://fantasy.premierleague.com/api/bootstrap-static/
* Fixtures: https://fixturedownload.com/results/epl-2022
---
# Another consideration
<iframe src="https://pbs.twimg.com/media/FZHCGpIWQAE2DeV?format=jpg" width="100%" height="400px" data-external="1"></iframe>
.left[.footnote[.small[Source: https://twitter.com/HollyShand/status/1554523674140495872]]]
---
class: center, inverse, middle
.center[
![:scale 50%](https://media.giphy.com/media/RDKPVBPMfNA7m/giphy.gif)
]
.large[<span style="color:orange"> Let's practice! </span>]
<br>
.small[open "BelutListik.qmd" in RStudio]
---
# Disclaimers
* Based on the previous seasons' statistics.
+ Re-run the codes after several matches in the next season.
+ The data set needs to be updated frequently (i.e., every two Gameweeks).
* The Summer 2022 Transfer Window for Premier League clubs will close at 23:00 BST on 1 September 2022.
+ A possible move of Mark Cucurella (BHA, £5.0) to Chelsea.
* Limitations in the computer memory make the analysis could not cover all possible choices: Use a higher specifications (memory >60 GB).
* World Cup 2022: Including players involved in the competition or not?
* Belut Listrik's statistics in the last season:
+ Overall points: 2,414
+ Overall rank: 272,435 of 9,167,407 teams
---
class: center, inverse, middle
.large[
<span style="color:orange"> **Invite me to your mini league, maybe?** </span>
]
**or you could join**
@standupindo_kemenkeu X @ajikpurnomoputro: <span style="color:white">**hwf84k**</span>
---
class: center, middle, clear
.center[
![:scale 50%](https://media.giphy.com/media/dn07GR9ZYHqJUxaqzp/giphy.gif)
]
.large[
Thank you for listening.
]
.small[**All teaching materials will be available on https://github.com/arifpras/BelutListrik**]
.small[
Slides created via the R packages:
[**xaringan**](https://github.com/yihui/xaringan) and
[gadenbuie/xaringanthemer](https://github.com/gadenbuie/xaringanthemer). <br>
The chakra comes from [remark.js](https://remarkjs.com), [**knitr**](http://yihui.name/knitr), and [R Markdown](https://rmarkdown.rstudio.com).
]
---
# Acknowledgements
* Grolemund, G., & Wickham, H. (2017). R for Data Science. O’Reilly Media.
* R Core Team (2019). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. URL https://www.R-project.org/
* Wickham et al., (2019). Welcome to the tidyverse. Journal of Open Source Software, 4(43), 1686, https://doi.org/10.21105/joss.01686
* Claus O. Wilke: Data Visualization in R, https://wilkelab.org/SDS375/
* Cedric Scherer's personal blog: https://www.cedricscherer.com/
* ...and other sources i.e. stackoverflow.com, github.com, etc.
</textarea>
<style data-target="print-only">@media screen {.remark-slide-container{display:block;}.remark-slide-scaler{box-shadow:none;}}</style>
<script src="https://remarkjs.com/downloads/remark-latest.min.js"></script>
<script src="macros.js"></script>
<script src="https://platform.twitter.com/widgets.js"></script>
<script>var slideshow = remark.create({
"slideNumberFormat": "%current%",
"highlightStyle": "github",
"highlightLines": true,
"ratio": "16:9",
"countIncrementalSlides": true
});
if (window.HTMLWidgets) slideshow.on('afterShowSlide', function (slide) {
window.dispatchEvent(new Event('resize'));
});
(function(d) {
var s = d.createElement("style"), r = d.querySelector(".remark-slide-scaler");
if (!r) return;
s.type = "text/css"; s.innerHTML = "@page {size: " + r.style.width + " " + r.style.height +"; }";
d.head.appendChild(s);
})(document);
(function(d) {
var el = d.getElementsByClassName("remark-slides-area");
if (!el) return;
var slide, slides = slideshow.getSlides(), els = el[0].children;
for (var i = 1; i < slides.length; i++) {
slide = slides[i];
if (slide.properties.continued === "true" || slide.properties.count === "false") {
els[i - 1].className += ' has-continuation';
}
}
var s = d.createElement("style");
s.type = "text/css"; s.innerHTML = "@media print { .has-continuation { display: none; } }";
d.head.appendChild(s);
})(document);
// delete the temporary CSS (for displaying all slides initially) when the user
// starts to view slides
(function() {
var deleted = false;
slideshow.on('beforeShowSlide', function(slide) {
if (deleted) return;
var sheets = document.styleSheets, node;
for (var i = 0; i < sheets.length; i++) {
node = sheets[i].ownerNode;
if (node.dataset["target"] !== "print-only") continue;
node.parentNode.removeChild(node);
}
deleted = true;
});
})();
// add `data-at-shortcutkeys` attribute to <body> to resolve conflicts with JAWS
// screen reader (see PR #262)
(function(d) {
let res = {};
d.querySelectorAll('.remark-help-content table tr').forEach(tr => {
const t = tr.querySelector('td:nth-child(2)').innerText;
tr.querySelectorAll('td:first-child .key').forEach(key => {
const k = key.innerText;
if (/^[a-z]$/.test(k)) res[k] = t; // must be a single letter (key)
});
});
d.body.setAttribute('data-at-shortcutkeys', JSON.stringify(res));
})(document);
(function() {
"use strict"
// Replace <script> tags in slides area to make them executable
var scripts = document.querySelectorAll(
'.remark-slides-area .remark-slide-container script'
);
if (!scripts.length) return;
for (var i = 0; i < scripts.length; i++) {
var s = document.createElement('script');
var code = document.createTextNode(scripts[i].textContent);
s.appendChild(code);
var scriptAttrs = scripts[i].attributes;
for (var j = 0; j < scriptAttrs.length; j++) {
s.setAttribute(scriptAttrs[j].name, scriptAttrs[j].value);
}
scripts[i].parentElement.replaceChild(s, scripts[i]);
}
})();
(function() {
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
if (/^(https?:)?\/\//.test(links[i].getAttribute('href'))) {
links[i].target = '_blank';
}
}
})();
// adds .remark-code-has-line-highlighted class to <pre> parent elements
// of code chunks containing highlighted lines with class .remark-code-line-highlighted
(function(d) {
const hlines = d.querySelectorAll('.remark-code-line-highlighted');
const preParents = [];
const findPreParent = function(line, p = 0) {
if (p > 1) return null; // traverse up no further than grandparent
const el = line.parentElement;
return el.tagName === "PRE" ? el : findPreParent(el, ++p);
};
for (let line of hlines) {
let pre = findPreParent(line);
if (pre && !preParents.includes(pre)) preParents.push(pre);
}
preParents.forEach(p => p.classList.add("remark-code-has-line-highlighted"));
})(document);</script>
<script>
slideshow._releaseMath = function(el) {
var i, text, code, codes = el.getElementsByTagName('code');
for (i = 0; i < codes.length;) {
code = codes[i];
if (code.parentNode.tagName !== 'PRE' && code.childElementCount === 0) {
text = code.textContent;
if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) ||
/^\$\$(.|\s)+\$\$$/.test(text) ||
/^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
code.outerHTML = code.innerHTML; // remove <code></code>
continue;
}
}
i++;
}
};
slideshow._releaseMath(document);
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML';
if (location.protocol !== 'file:' && /^https?:/.test(script.src))
script.src = script.src.replace(/^https?:/, '');
document.getElementsByTagName('head')[0].appendChild(script);
})();
</script>
</body>
</html>