-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04-nba-analytics.html
More file actions
1405 lines (1374 loc) · 72.6 KB
/
Copy path04-nba-analytics.html
File metadata and controls
1405 lines (1374 loc) · 72.6 KB
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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.8.27">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="author" content="Shannon Joyce">
<title>Assignment 4 - NBA Analytics</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
/* CSS for syntax highlighting */
html { -webkit-text-size-adjust: 100%; }
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
}
pre.numberSource { margin-left: 3em; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>
<script src="04-nba-analytics_files/libs/clipboard/clipboard.min.js"></script>
<script src="04-nba-analytics_files/libs/quarto-html/quarto.js" type="module"></script>
<script src="04-nba-analytics_files/libs/quarto-html/tabsets/tabsets.js" type="module"></script>
<script src="04-nba-analytics_files/libs/quarto-html/axe/axe-check.js" type="module"></script>
<script src="04-nba-analytics_files/libs/quarto-html/popper.min.js"></script>
<script src="04-nba-analytics_files/libs/quarto-html/tippy.umd.min.js"></script>
<script src="04-nba-analytics_files/libs/quarto-html/anchor.min.js"></script>
<link href="04-nba-analytics_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="04-nba-analytics_files/libs/quarto-html/quarto-syntax-highlighting-ed96de9b727972fe78a7b5d16c58bf87.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="04-nba-analytics_files/libs/bootstrap/bootstrap.min.js"></script>
<link href="04-nba-analytics_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="04-nba-analytics_files/libs/bootstrap/bootstrap-d6a003b94517c951b2d65075d42fb01b.min.css" rel="stylesheet" append-hash="true" id="quarto-bootstrap" data-mode="light">
</head>
<body class="fullcontent quarto-light">
<div id="quarto-content" class="page-columns page-rows-contents page-layout-article">
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title">Assignment 4 - NBA Analytics</h1>
</div>
<div class="quarto-title-meta">
<div>
<div class="quarto-title-meta-heading">Author</div>
<div class="quarto-title-meta-contents">
<p>Shannon Joyce </p>
</div>
</div>
</div>
</header>
<section id="introduction" class="level2">
<h2 class="anchored" data-anchor-id="introduction">Introduction</h2>
<p>The NBA season is about to begin, and I have just been hired as a Data Analyst for the National Basketball Association. Commissioner Adam Silver is asking me for insights into last year’s team performances — specifically, how offensive and defensive metrics relate to one another, and whether teams from the Eastern and Western Conferences differ in their overall performance.</p>
<p>Using real-style NBA data from all 30 teams, my job is to build a reproducible analysis in RMarkdown that loads, cleans, visualizes, and analyzes the data to uncover meaningful patterns.</p>
</section>
<section id="step-1-loading-preparing-the-data" class="level2">
<h2 class="anchored" data-anchor-id="step-1-loading-preparing-the-data">Step 1: Loading & Preparing the Data</h2>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(tidyverse)</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ggplot2)</span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(Hmisc)</span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(readxl)</span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(skimr)</span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ggcorrplot)</span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(GGally)</span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ppcor)</span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(knitr)</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>bball_function <span class="ot"><-</span> <span class="cf">function</span>(x){</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> basketball<span class="ot"><-</span> <span class="fu">read_xlsx</span>(<span class="st">"NBA Team Total Data 2024-2025.xlsx"</span>, <span class="at">sheet =</span> x)</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> basketball<span class="sc">$</span>Team <span class="ot"><-</span> x</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> basketball<span class="sc">$</span>Won_award<span class="ot"><-</span> <span class="fu">ifelse</span>(<span class="fu">is.na</span>(basketball<span class="sc">$</span>Awards),<span class="st">"No"</span>,<span class="st">"Yes"</span>)</span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> basketball<span class="sc">$</span>PRA<span class="ot"><-</span> basketball<span class="sc">$</span>PTS <span class="sc">+</span> basketball<span class="sc">$</span>TRB <span class="sc">+</span> basketball<span class="sc">$</span>AST</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> basketball<span class="sc">$</span>STOCKS<span class="ot"><-</span> basketball<span class="sc">$</span>STL<span class="sc">+</span> basketball<span class="sc">$</span>BLK</span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(basketball)</span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a>team_names<span class="ot"><-</span> <span class="fu">excel_sheets</span>(<span class="st">"NBA Team Total Data 2024-2025.xlsx"</span>)</span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a>all_data<span class="ot"><-</span> <span class="fu">lapply</span>(team_names, bball_function) <span class="sc">%>%</span> <span class="fu">bind_rows</span>()</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>all_data <span class="sc">%>%</span> <span class="fu">head</span>(<span class="at">n=</span><span class="dv">5</span>) <span class="sc">%>%</span> <span class="fu">kable</span>()</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
<div id="tbl-nba-team-data" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-nba-team-data-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table 1: NBA Team Data 2024-2025, first 5 rows.
</figcaption>
<div aria-describedby="tbl-nba-team-data-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output-display">
<table class="do-not-create-environment cell caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 1%">
<col style="width: 8%">
<col style="width: 2%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 3%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 3%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 3%">
<col style="width: 3%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 3%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 4%">
<col style="width: 3%">
<col style="width: 2%">
<col style="width: 5%">
<col style="width: 2%">
<col style="width: 3%">
<col style="width: 2%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: right;">Rk</th>
<th style="text-align: left;">Player</th>
<th style="text-align: right;">Age</th>
<th style="text-align: right;">G</th>
<th style="text-align: right;">GS</th>
<th style="text-align: right;">MP</th>
<th style="text-align: right;">FG</th>
<th style="text-align: right;">FGA</th>
<th style="text-align: right;">FG%</th>
<th style="text-align: right;">3P</th>
<th style="text-align: right;">3PA</th>
<th style="text-align: right;">3P%</th>
<th style="text-align: right;">2P</th>
<th style="text-align: right;">2PA</th>
<th style="text-align: right;">2P%</th>
<th style="text-align: right;">eFG%</th>
<th style="text-align: right;">FT</th>
<th style="text-align: right;">FTA</th>
<th style="text-align: right;">FT%</th>
<th style="text-align: right;">ORB</th>
<th style="text-align: right;">DRB</th>
<th style="text-align: right;">TRB</th>
<th style="text-align: right;">AST</th>
<th style="text-align: right;">STL</th>
<th style="text-align: right;">BLK</th>
<th style="text-align: right;">TOV</th>
<th style="text-align: right;">PF</th>
<th style="text-align: right;">PTS</th>
<th style="text-align: right;">Trp-Dbl</th>
<th style="text-align: left;">Awards</th>
<th style="text-align: left;">Team</th>
<th style="text-align: left;">Won_award</th>
<th style="text-align: right;">PRA</th>
<th style="text-align: right;">STOCKS</th>
<th style="text-align: left;">Pos</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">1</td>
<td style="text-align: left;">Jalen Wilson</td>
<td style="text-align: right;">24</td>
<td style="text-align: right;">79</td>
<td style="text-align: right;">22</td>
<td style="text-align: right;">2031</td>
<td style="text-align: right;">246</td>
<td style="text-align: right;">620</td>
<td style="text-align: right;">0.397</td>
<td style="text-align: right;">122</td>
<td style="text-align: right;">362</td>
<td style="text-align: right;">0.337</td>
<td style="text-align: right;">124</td>
<td style="text-align: right;">258</td>
<td style="text-align: right;">0.481</td>
<td style="text-align: right;">0.495</td>
<td style="text-align: right;">135</td>
<td style="text-align: right;">165</td>
<td style="text-align: right;">0.818</td>
<td style="text-align: right;">75</td>
<td style="text-align: right;">195</td>
<td style="text-align: right;">270</td>
<td style="text-align: right;">145</td>
<td style="text-align: right;">40</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">79</td>
<td style="text-align: right;">164</td>
<td style="text-align: right;">749</td>
<td style="text-align: right;">0</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Nets</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">1164</td>
<td style="text-align: right;">45</td>
<td style="text-align: left;">NA</td>
</tr>
<tr class="even">
<td style="text-align: right;">2</td>
<td style="text-align: left;">Keon Johnson</td>
<td style="text-align: right;">22</td>
<td style="text-align: right;">79</td>
<td style="text-align: right;">56</td>
<td style="text-align: right;">1925</td>
<td style="text-align: right;">303</td>
<td style="text-align: right;">779</td>
<td style="text-align: right;">0.389</td>
<td style="text-align: right;">126</td>
<td style="text-align: right;">401</td>
<td style="text-align: right;">0.314</td>
<td style="text-align: right;">177</td>
<td style="text-align: right;">378</td>
<td style="text-align: right;">0.468</td>
<td style="text-align: right;">0.470</td>
<td style="text-align: right;">107</td>
<td style="text-align: right;">139</td>
<td style="text-align: right;">0.770</td>
<td style="text-align: right;">63</td>
<td style="text-align: right;">234</td>
<td style="text-align: right;">297</td>
<td style="text-align: right;">175</td>
<td style="text-align: right;">82</td>
<td style="text-align: right;">30</td>
<td style="text-align: right;">116</td>
<td style="text-align: right;">209</td>
<td style="text-align: right;">839</td>
<td style="text-align: right;">0</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Nets</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">1311</td>
<td style="text-align: right;">112</td>
<td style="text-align: left;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: right;">3</td>
<td style="text-align: left;">Nic Claxton</td>
<td style="text-align: right;">25</td>
<td style="text-align: right;">70</td>
<td style="text-align: right;">62</td>
<td style="text-align: right;">1882</td>
<td style="text-align: right;">320</td>
<td style="text-align: right;">568</td>
<td style="text-align: right;">0.563</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">21</td>
<td style="text-align: right;">0.238</td>
<td style="text-align: right;">315</td>
<td style="text-align: right;">547</td>
<td style="text-align: right;">0.576</td>
<td style="text-align: right;">0.568</td>
<td style="text-align: right;">79</td>
<td style="text-align: right;">154</td>
<td style="text-align: right;">0.513</td>
<td style="text-align: right;">157</td>
<td style="text-align: right;">358</td>
<td style="text-align: right;">515</td>
<td style="text-align: right;">157</td>
<td style="text-align: right;">62</td>
<td style="text-align: right;">100</td>
<td style="text-align: right;">87</td>
<td style="text-align: right;">150</td>
<td style="text-align: right;">724</td>
<td style="text-align: right;">0</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Nets</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">1396</td>
<td style="text-align: right;">162</td>
<td style="text-align: left;">NA</td>
</tr>
<tr class="even">
<td style="text-align: right;">4</td>
<td style="text-align: left;">Cameron Johnson</td>
<td style="text-align: right;">28</td>
<td style="text-align: right;">57</td>
<td style="text-align: right;">57</td>
<td style="text-align: right;">1800</td>
<td style="text-align: right;">355</td>
<td style="text-align: right;">747</td>
<td style="text-align: right;">0.475</td>
<td style="text-align: right;">159</td>
<td style="text-align: right;">408</td>
<td style="text-align: right;">0.390</td>
<td style="text-align: right;">196</td>
<td style="text-align: right;">339</td>
<td style="text-align: right;">0.578</td>
<td style="text-align: right;">0.582</td>
<td style="text-align: right;">201</td>
<td style="text-align: right;">225</td>
<td style="text-align: right;">0.893</td>
<td style="text-align: right;">54</td>
<td style="text-align: right;">193</td>
<td style="text-align: right;">247</td>
<td style="text-align: right;">194</td>
<td style="text-align: right;">53</td>
<td style="text-align: right;">25</td>
<td style="text-align: right;">99</td>
<td style="text-align: right;">104</td>
<td style="text-align: right;">1070</td>
<td style="text-align: right;">0</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Nets</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">1511</td>
<td style="text-align: right;">78</td>
<td style="text-align: left;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: right;">5</td>
<td style="text-align: left;">Ziaire Williams</td>
<td style="text-align: right;">23</td>
<td style="text-align: right;">63</td>
<td style="text-align: right;">45</td>
<td style="text-align: right;">1541</td>
<td style="text-align: right;">214</td>
<td style="text-align: right;">520</td>
<td style="text-align: right;">0.412</td>
<td style="text-align: right;">103</td>
<td style="text-align: right;">302</td>
<td style="text-align: right;">0.341</td>
<td style="text-align: right;">111</td>
<td style="text-align: right;">218</td>
<td style="text-align: right;">0.509</td>
<td style="text-align: right;">0.511</td>
<td style="text-align: right;">101</td>
<td style="text-align: right;">123</td>
<td style="text-align: right;">0.821</td>
<td style="text-align: right;">61</td>
<td style="text-align: right;">226</td>
<td style="text-align: right;">287</td>
<td style="text-align: right;">84</td>
<td style="text-align: right;">62</td>
<td style="text-align: right;">28</td>
<td style="text-align: right;">67</td>
<td style="text-align: right;">149</td>
<td style="text-align: right;">632</td>
<td style="text-align: right;">0</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Nets</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">1003</td>
<td style="text-align: right;">90</td>
<td style="text-align: left;">NA</td>
</tr>
</tbody>
</table>
</div>
</div>
</figure>
</div>
</div>
<p>In this chunk, I created a function (bball_function) that loaded data from all 30 teams (one from each sheet) from the NBA 2024-2025 dataset, created a variable showing if the player received an award (0=No, 1=Yes), and created 2 more variables of the players’ PRA (points, rebounds & assists) and their STOCKS (steals & blocks). Phew!</p>
<div class="callout callout-style-default callout-important callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Important</span>Uploading Multiple Datasets
</div>
</div>
<div class="callout-body-container callout-body">
<p>Here is where I created a function and used lapply() to upload multiple sheets of data at once and create datasets from them in RStudio.</p>
</div>
</div>
<p>In order to actually load those 30 sheets, I created an object called ‘team_names’ that read each sheet individually, and used lapply() to assign the team_names object to the bball_function. Finally, I binded all the rows together to make one large dataset of all 30 teams called ‘all_data’.</p>
</section>
<section id="step-2-adding-conference-information" class="level2">
<h2 class="anchored" data-anchor-id="step-2-adding-conference-information">Step 2: Adding Conference Information</h2>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>conference_data<span class="ot"><-</span> <span class="fu">read_xlsx</span>(<span class="st">"Team Conferences.xlsx"</span>)</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a>all_data<span class="ot"><-</span> <span class="fu">merge</span>(all_data, conference_data, <span class="at">by=</span><span class="st">"Team"</span>)</span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a>all_data<span class="ot"><-</span> all_data <span class="sc">%>%</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">Conference =</span> dplyr<span class="sc">::</span><span class="fu">recode</span>(Conference, <span class="st">"East"</span> <span class="ot">=</span> <span class="dv">1</span>, <span class="st">"West"</span> <span class="ot">=</span> <span class="dv">0</span>))</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>all_data <span class="sc">%>%</span> <span class="fu">head</span>(<span class="at">n=</span><span class="dv">5</span>) <span class="sc">%>%</span> <span class="fu">kable</span>()</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
<div id="tbl-nba-conference-info" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-nba-conference-info-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table 2: Updated NBA Team Data 2024-2025, first 5 rows.
</figcaption>
<div aria-describedby="tbl-nba-conference-info-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output-display">
<table class="do-not-create-environment cell caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 2%">
<col style="width: 1%">
<col style="width: 10%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 2%">
<col style="width: 1%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 2%">
<col style="width: 1%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 2%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 2%">
<col style="width: 3%">
<col style="width: 9%">
<col style="width: 4%">
<col style="width: 2%">
<col style="width: 3%">
<col style="width: 1%">
<col style="width: 5%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Team</th>
<th style="text-align: right;">Rk</th>
<th style="text-align: left;">Player</th>
<th style="text-align: right;">Age</th>
<th style="text-align: right;">G</th>
<th style="text-align: right;">GS</th>
<th style="text-align: right;">MP</th>
<th style="text-align: right;">FG</th>
<th style="text-align: right;">FGA</th>
<th style="text-align: right;">FG%</th>
<th style="text-align: right;">3P</th>
<th style="text-align: right;">3PA</th>
<th style="text-align: right;">3P%</th>
<th style="text-align: right;">2P</th>
<th style="text-align: right;">2PA</th>
<th style="text-align: right;">2P%</th>
<th style="text-align: right;">eFG%</th>
<th style="text-align: right;">FT</th>
<th style="text-align: right;">FTA</th>
<th style="text-align: right;">FT%</th>
<th style="text-align: right;">ORB</th>
<th style="text-align: right;">DRB</th>
<th style="text-align: right;">TRB</th>
<th style="text-align: right;">AST</th>
<th style="text-align: right;">STL</th>
<th style="text-align: right;">BLK</th>
<th style="text-align: right;">TOV</th>
<th style="text-align: right;">PF</th>
<th style="text-align: right;">PTS</th>
<th style="text-align: right;">Trp-Dbl</th>
<th style="text-align: left;">Awards</th>
<th style="text-align: left;">Won_award</th>
<th style="text-align: right;">PRA</th>
<th style="text-align: right;">STOCKS</th>
<th style="text-align: left;">Pos</th>
<th style="text-align: right;">Conference</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Bucks</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">Brook Lopez</td>
<td style="text-align: right;">36</td>
<td style="text-align: right;">80</td>
<td style="text-align: right;">80</td>
<td style="text-align: right;">2546</td>
<td style="text-align: right;">394</td>
<td style="text-align: right;">774</td>
<td style="text-align: right;">0.509</td>
<td style="text-align: right;">139</td>
<td style="text-align: right;">373</td>
<td style="text-align: right;">0.373</td>
<td style="text-align: right;">255</td>
<td style="text-align: right;">401</td>
<td style="text-align: right;">0.636</td>
<td style="text-align: right;">0.599</td>
<td style="text-align: right;">114</td>
<td style="text-align: right;">138</td>
<td style="text-align: right;">0.826</td>
<td style="text-align: right;">113</td>
<td style="text-align: right;">288</td>
<td style="text-align: right;">401</td>
<td style="text-align: right;">143</td>
<td style="text-align: right;">50</td>
<td style="text-align: right;">148</td>
<td style="text-align: right;">84</td>
<td style="text-align: right;">171</td>
<td style="text-align: right;">1041</td>
<td style="text-align: right;">0</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">1585</td>
<td style="text-align: right;">198</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td style="text-align: left;">Bucks</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">Giannis Antetokounmpo</td>
<td style="text-align: right;">30</td>
<td style="text-align: right;">67</td>
<td style="text-align: right;">67</td>
<td style="text-align: right;">2289</td>
<td style="text-align: right;">793</td>
<td style="text-align: right;">1319</td>
<td style="text-align: right;">0.601</td>
<td style="text-align: right;">14</td>
<td style="text-align: right;">63</td>
<td style="text-align: right;">0.222</td>
<td style="text-align: right;">779</td>
<td style="text-align: right;">1256</td>
<td style="text-align: right;">0.620</td>
<td style="text-align: right;">0.607</td>
<td style="text-align: right;">436</td>
<td style="text-align: right;">707</td>
<td style="text-align: right;">0.617</td>
<td style="text-align: right;">147</td>
<td style="text-align: right;">651</td>
<td style="text-align: right;">798</td>
<td style="text-align: right;">433</td>
<td style="text-align: right;">58</td>
<td style="text-align: right;">78</td>
<td style="text-align: right;">206</td>
<td style="text-align: right;">155</td>
<td style="text-align: right;">2036</td>
<td style="text-align: right;">11</td>
<td style="text-align: left;">MVP-3,DPOY-8,AS,NBA1</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">3267</td>
<td style="text-align: right;">136</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Bucks</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">Taurean Prince</td>
<td style="text-align: right;">30</td>
<td style="text-align: right;">80</td>
<td style="text-align: right;">73</td>
<td style="text-align: right;">2166</td>
<td style="text-align: right;">235</td>
<td style="text-align: right;">514</td>
<td style="text-align: right;">0.457</td>
<td style="text-align: right;">147</td>
<td style="text-align: right;">335</td>
<td style="text-align: right;">0.439</td>
<td style="text-align: right;">88</td>
<td style="text-align: right;">179</td>
<td style="text-align: right;">0.492</td>
<td style="text-align: right;">0.600</td>
<td style="text-align: right;">39</td>
<td style="text-align: right;">48</td>
<td style="text-align: right;">0.813</td>
<td style="text-align: right;">34</td>
<td style="text-align: right;">253</td>
<td style="text-align: right;">287</td>
<td style="text-align: right;">155</td>
<td style="text-align: right;">76</td>
<td style="text-align: right;">15</td>
<td style="text-align: right;">82</td>
<td style="text-align: right;">165</td>
<td style="text-align: right;">656</td>
<td style="text-align: right;">0</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">1098</td>
<td style="text-align: right;">91</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td style="text-align: left;">Bucks</td>
<td style="text-align: right;">4</td>
<td style="text-align: left;">Damian Lillard</td>
<td style="text-align: right;">34</td>
<td style="text-align: right;">58</td>
<td style="text-align: right;">58</td>
<td style="text-align: right;">2093</td>
<td style="text-align: right;">444</td>
<td style="text-align: right;">992</td>
<td style="text-align: right;">0.448</td>
<td style="text-align: right;">197</td>
<td style="text-align: right;">524</td>
<td style="text-align: right;">0.376</td>
<td style="text-align: right;">247</td>
<td style="text-align: right;">468</td>
<td style="text-align: right;">0.528</td>
<td style="text-align: right;">0.547</td>
<td style="text-align: right;">362</td>
<td style="text-align: right;">393</td>
<td style="text-align: right;">0.921</td>
<td style="text-align: right;">29</td>
<td style="text-align: right;">243</td>
<td style="text-align: right;">272</td>
<td style="text-align: right;">410</td>
<td style="text-align: right;">70</td>
<td style="text-align: right;">10</td>
<td style="text-align: right;">162</td>
<td style="text-align: right;">97</td>
<td style="text-align: right;">1447</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">AS</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">2129</td>
<td style="text-align: right;">80</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Bucks</td>
<td style="text-align: right;">5</td>
<td style="text-align: left;">Gary Trent Jr.</td>
<td style="text-align: right;">26</td>
<td style="text-align: right;">74</td>
<td style="text-align: right;">9</td>
<td style="text-align: right;">1893</td>
<td style="text-align: right;">283</td>
<td style="text-align: right;">657</td>
<td style="text-align: right;">0.431</td>
<td style="text-align: right;">180</td>
<td style="text-align: right;">433</td>
<td style="text-align: right;">0.416</td>
<td style="text-align: right;">103</td>
<td style="text-align: right;">224</td>
<td style="text-align: right;">0.460</td>
<td style="text-align: right;">0.568</td>
<td style="text-align: right;">78</td>
<td style="text-align: right;">92</td>
<td style="text-align: right;">0.848</td>
<td style="text-align: right;">20</td>
<td style="text-align: right;">148</td>
<td style="text-align: right;">168</td>
<td style="text-align: right;">87</td>
<td style="text-align: right;">72</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">42</td>
<td style="text-align: right;">124</td>
<td style="text-align: right;">824</td>
<td style="text-align: right;">0</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">1079</td>
<td style="text-align: right;">76</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">1</td>
</tr>
</tbody>
</table>
</div>
</div>
</figure>
</div>
</div>
<p>I mean, it’s basically in the name. This chunk shows how I added a variable for the conference that each team belongs to (East or West) by uploading a dataset of teams and their conference and merging it with my all_data by the column named ‘Team’. And then, of course, making it a binary variable.</p>
</section>
<section id="step-3-visual-exploration" class="level2">
<h2 class="anchored" data-anchor-id="step-3-visual-exploration">Step 3: Visual Exploration</h2>
<section id="plot-1-pra-vs.-stocks" class="level3">
<h3 class="anchored" data-anchor-id="plot-1-pra-vs.-stocks">Plot 1: PRA vs. STOCKS</h3>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>p1<span class="ot"><-</span> <span class="fu">ggplot</span>(all_data, <span class="fu">aes</span>(<span class="at">x =</span> PRA, <span class="at">y =</span> STOCKS)) <span class="sc">+</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>(<span class="fu">aes</span>(<span class="at">color =</span> <span class="fu">factor</span>(Conference)), <span class="at">size =</span> <span class="dv">3</span>, <span class="at">alpha =</span> <span class="fl">0.8</span>) <span class="sc">+</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_smooth</span>(<span class="at">method =</span> <span class="st">"lm"</span>, <span class="at">se =</span> <span class="cn">FALSE</span>, <span class="at">color =</span> <span class="st">"darkgreen"</span>) <span class="sc">+</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_minimal</span>() <span class="sc">+</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">color =</span> <span class="st">"Conference"</span>,</span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a> <span class="at">title =</span> <span class="st">"PRA vs STOCKS"</span>,</span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a> <span class="at">subtitle =</span> <span class="st">"Are players' PRA and STOCKS related?"</span>,</span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> <span class="st">"PRA"</span>, <span class="at">y =</span> <span class="st">"STOCKS"</span>,) <span class="sc">+</span></span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_color_manual</span>(</span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a> <span class="at">name =</span> <span class="st">"Conference"</span>,</span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a> <span class="at">values =</span> <span class="fu">c</span>(<span class="st">"0"</span> <span class="ot">=</span> <span class="st">"orange"</span>, <span class="st">"1"</span> <span class="ot">=</span> <span class="st">"skyblue3"</span>),</span>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a> <span class="at">labels =</span> <span class="fu">c</span>(<span class="st">"0"</span> <span class="ot">=</span> <span class="st">"West"</span>, <span class="st">"1"</span> <span class="ot">=</span> <span class="st">"East"</span>)</span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true" tabindex="-1"></a> )</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>p1</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
<div class="cell-output-display">
<div id="fig-1" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="04-nba-analytics_files/figure-html/fig-1-1.png" class="img-fluid figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure 1: A scatterplot showing each players’ points, rebounds, and the relationship with their steals and blocks. Players in the West Coast conference are represented by an orange dot and players in the East Coast conference are represented by a blue dot.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Let’s take a look at the relationship between a player’s PRA and their STOCKS. What we see is that PRA and STOCKS are very closely related; as PRA goes up, so does STOCKS. However, this may be due to other factors, such as minutes played (i.e., the more time a player gets on the court, the more PRA and STOCKS they are likely to accumulate). These metrics seem to be pretty uniform for both conferences- one conference does not perform better than another.</p>
</section>
<section id="plot-2-minutes-played-vs.-age-by-conference" class="level3">
<h3 class="anchored" data-anchor-id="plot-2-minutes-played-vs.-age-by-conference">Plot 2: Minutes Played vs. Age (by Conference)</h3>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>p2<span class="ot"><-</span> <span class="fu">ggplot</span>(all_data, <span class="fu">aes</span>(<span class="at">x =</span> Age, <span class="at">y =</span> MP, <span class="at">color =</span> Conference)) <span class="sc">+</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>(<span class="fu">aes</span>(<span class="at">color =</span> <span class="fu">factor</span>(Conference)), <span class="at">size =</span> <span class="dv">3</span>, <span class="at">alpha =</span> <span class="fl">0.8</span>) <span class="sc">+</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_smooth</span>(<span class="at">method =</span> <span class="st">"lm"</span>, <span class="at">se =</span> <span class="cn">FALSE</span>) <span class="sc">+</span></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_minimal</span>() <span class="sc">+</span></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">title =</span> <span class="st">"Minutes Played vs. Age by Conference"</span>,</span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> <span class="st">"Age"</span>,</span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a> <span class="at">y =</span> <span class="st">"Minutes Played"</span>) <span class="sc">+</span></span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_color_manual</span>(</span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a> <span class="at">name =</span> <span class="st">"Conference"</span>,</span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true" tabindex="-1"></a> <span class="at">values =</span> <span class="fu">c</span>(<span class="st">"0"</span> <span class="ot">=</span> <span class="st">"orange"</span>, <span class="st">"1"</span> <span class="ot">=</span> <span class="st">"skyblue3"</span>),</span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true" tabindex="-1"></a> <span class="at">labels =</span> <span class="fu">c</span>(<span class="st">"0"</span> <span class="ot">=</span> <span class="st">"West"</span>, <span class="st">"1"</span> <span class="ot">=</span> <span class="st">"East"</span>)</span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true" tabindex="-1"></a> )</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>p2</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
<div class="cell-output-display">
<div id="fig-2" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="04-nba-analytics_files/figure-html/fig-2-1.png" class="img-fluid figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure 2: A scatterplot representing each players’ amount of minutes played over the season compared with their age. Players in the West Coast conference are represented by an orange dot and players in the East Coast conference are represented by a blue dot.
</figcaption>
</figure>
</div>
</div>
</div>
<p>For my second visualization, I chose to look at Minutes Played vs. Age (and grouped them by conference just to see what lies between groups). Here’s what we see: The older a player is, the more minutes they get to play, but there is a lot of variation in minutes played within the same ages. It also seems as though the older players in the West coast conference get more playing time than the older players in the East coast conference on average.</p>
</section>
</section>
<section id="step-4-correlation-analyses" class="level2">
<h2 class="anchored" data-anchor-id="step-4-correlation-analyses">Step 4: Correlation Analyses</h2>
<section id="is-conference-related-to-pra" class="level3">
<h3 class="anchored" data-anchor-id="is-conference-related-to-pra">Is Conference related to PRA?</h3>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cor.test</span>(all_data<span class="sc">$</span>Conference, all_data<span class="sc">$</span>PRA)</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
<div class="cell-output cell-output-stdout">
<pre><code>
Pearson's product-moment correlation
data: all_data$Conference and all_data$PRA
t = -1.8195, df = 650, p-value = 0.0693
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.147164250 0.005629906
sample estimates:
cor
-0.07118475 </code></pre>
</div>
</div>
<ul>
<li><p>Strength: very weak (-0.07)</p></li>
<li><p>Direction: negative</p></li>
<li><p>Significance: not significant (p>0.05)</p></li>
</ul>
<p>This correlation shows us that there may be a slight negative trend in conference predicting PRA, but the effect is so small and statistically insignificant that it virtually means nothing. There is no linear relationship between Conference and PRA.</p>
</section>
<section id="is-conference-related-to-stocks" class="level3">
<h3 class="anchored" data-anchor-id="is-conference-related-to-stocks">Is Conference related to STOCKS?</h3>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cor.test</span>(all_data<span class="sc">$</span>Conference, all_data<span class="sc">$</span>STOCKS)</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
<div class="cell-output cell-output-stdout">
<pre><code>
Pearson's product-moment correlation
data: all_data$Conference and all_data$STOCKS
t = -2.094, df = 650, p-value = 0.03665
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.157650363 -0.005105577
sample estimates:
cor
-0.08185737 </code></pre>
</div>
</div>
<ul>
<li><p>Strength: very weak (-0.08)</p></li>
<li><p>Direction: negative</p></li>
<li><p>Significance: significant (p<0.05)</p></li>
</ul>
<p>This means that there is a very small but statistically significant negative correlation between Conference and STOCKS, suggesting a specific Conference may negatively predict STOCKS. However, the effect is so small that it is most likely not practically meaningful.</p>
</section>
<section id="correlation-matrix-age-pra-stocks-awards-won" class="level3">
<h3 class="anchored" data-anchor-id="correlation-matrix-age-pra-stocks-awards-won">Correlation Matrix: Age, PRA, STOCKS, & Awards Won</h3>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a>all_data <span class="ot"><-</span> all_data <span class="sc">%>%</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">Won_award_N =</span> <span class="fu">case_when</span>(</span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a> Won_award <span class="sc">==</span> <span class="st">"No"</span> <span class="sc">~</span> <span class="dv">0</span>,</span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a> Won_award <span class="sc">==</span> <span class="st">"Yes"</span> <span class="sc">~</span> <span class="dv">1</span>)</span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a><span class="fu">rcorr</span>(<span class="fu">as.matrix</span>(all_data[, <span class="fu">c</span>(<span class="st">"PRA"</span>, <span class="st">"STOCKS"</span>, <span class="st">"Age"</span>, <span class="st">"Won_award_N"</span>)]))</span>
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-8"><a href="#cb14-8" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(all_data)</span>
<span id="cb14-9"><a href="#cb14-9" aria-hidden="true" tabindex="-1"></a>all_data_num<span class="ot"><-</span> all_data <span class="sc">%>%</span> dplyr<span class="sc">::</span><span class="fu">select</span>(<span class="dv">4</span>,<span class="dv">33</span>,<span class="dv">34</span>,<span class="dv">37</span>)</span>
<span id="cb14-10"><a href="#cb14-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-11"><a href="#cb14-11" aria-hidden="true" tabindex="-1"></a>corr_matrix <span class="ot"><-</span> <span class="fu">cor</span>(all_data_num, <span class="at">use =</span> <span class="st">"pairwise.complete.obs"</span>)</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</div>
<p>Before creating the matrix, I had to create a binary variable for Won_award, which I have created as Won_award_N, where 0 = ‘No’ and 1 = ‘Yes’.</p>
<div class="cell" data-tbl-cap-location="bottom">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a>corr_matrix <span class="sc">%>%</span> <span class="fu">kable</span>()</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
<div id="tbl-corr-matrix" class="cell quarto-float quarto-figure quarto-figure-center anchored" data-tbl-cap-location="bottom">
<figure class="quarto-float quarto-float-tbl figure">
<div aria-describedby="tbl-corr-matrix-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output-display">
<table class="do-not-create-environment cell caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th style="text-align: left;"></th>
<th style="text-align: right;">Age</th>
<th style="text-align: right;">PRA</th>
<th style="text-align: right;">STOCKS</th>
<th style="text-align: right;">Won_award_N</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Age</td>
<td style="text-align: right;">1.0000000</td>
<td style="text-align: right;">0.1238926</td>
<td style="text-align: right;">0.0773490</td>
<td style="text-align: right;">0.0564231</td>
</tr>
<tr class="even">
<td style="text-align: left;">PRA</td>
<td style="text-align: right;">0.1238926</td>
<td style="text-align: right;">1.0000000</td>
<td style="text-align: right;">0.8402180</td>
<td style="text-align: right;">0.5361470</td>
</tr>
<tr class="odd">
<td style="text-align: left;">STOCKS</td>
<td style="text-align: right;">0.0773490</td>
<td style="text-align: right;">0.8402180</td>
<td style="text-align: right;">1.0000000</td>
<td style="text-align: right;">0.4722913</td>
</tr>
<tr class="even">
<td style="text-align: left;">Won_award_N</td>
<td style="text-align: right;">0.0564231</td>
<td style="text-align: right;">0.5361470</td>
<td style="text-align: right;">0.4722913</td>
<td style="text-align: right;">1.0000000</td>
</tr>
</tbody>
</table>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-tbl" id="tbl-corr-matrix-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table 3: Table representing the correlations between PRA, STOCKS, Age, and Awards Won.
</figcaption>
</figure>
</div>
</div>
<p>Let’s visualize it:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ggcorrplot</span>(corr_matrix, <span class="at">lab =</span> <span class="cn">TRUE</span>, <span class="at">type =</span> <span class="st">"lower"</span>) <span class="sc">+</span></span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">title =</span> <span class="st">"Correlation Matrix: PRA, STOCKS, Age, Won_award_N"</span>)</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
<div class="cell-output-display">
<div id="fig-matrix-visualization" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-matrix-visualization-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="04-nba-analytics_files/figure-html/fig-matrix-visualization-1.png" class="img-fluid figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-matrix-visualization-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure 3: A correlation matrix exploring the relationships between PRAs (points, rebounds, and assists), STOCKS (steals and blocks), and number of awards won.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Consistent with the correlations previously run, PRA and STOCKS have the strongest relationship. As mentioned before, this is likely due to the fact that those who have a higher PRA likely have more playing time- which would make them more likely to have a higher number of STOCKS as well. After that, the next strongest relationships are that of Won_award_N with PRAs and with STOCKS. This makes sense, because I would assume that the players who have won an award have performed better either offensively or defensively than those who have not won any awards.</p>
</section>
<section id="partial-correlation" class="level3">
<h3 class="anchored" data-anchor-id="partial-correlation">Partial Correlation</h3>
<section id="pra-vs.-stocks-controlling-for-minutes-played" class="level4">
<h4 class="anchored" data-anchor-id="pra-vs.-stocks-controlling-for-minutes-played">PRA vs. STOCKS, Controlling for Minutes Played</h4>
<div class="cell" data-tbl-cap-location="bottom">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="fu">pcor.test</span>(all_data<span class="sc">$</span>PRA, all_data<span class="sc">$</span>STOCKS, all_data<span class="sc">$</span>MP) <span class="sc">%>%</span> <span class="fu">kable</span>()</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
<div id="tbl-partial-correlation" class="cell quarto-float quarto-figure quarto-figure-center anchored" data-tbl-cap-location="bottom">
<figure class="quarto-float quarto-float-tbl figure">
<div aria-describedby="tbl-partial-correlation-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output-display">
<table class="do-not-create-environment cell caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th style="text-align: right;">estimate</th>
<th style="text-align: right;">p.value</th>
<th style="text-align: right;">statistic</th>
<th style="text-align: right;">n</th>
<th style="text-align: right;">gp</th>
<th style="text-align: left;">Method</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">0.0791189</td>
<td style="text-align: right;">0.0435933</td>
<td style="text-align: right;">2.02193</td>
<td style="text-align: right;">652</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">pearson</td>
</tr>
</tbody>
</table>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-tbl" id="tbl-partial-correlation-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table 4: A table summarizing results of a partial correlation test between PRA and STOCKS, controlling for Minutes Played.
</figcaption>
</figure>
</div>
</div>
<p>PRA and STOCKS are closely related, but not when we control for Minutes Played. This just about confirmed my suspicions; PRA and STOCKS are both likely to be higher when a player has more time on the court- not necessarily because being good at one means being good at the other. So, PRA and STOCKS are not directly related to one another.</p>
</section>
</section>
</section>
<section id="step-5-communicating-my-findings" class="level2">
<h2 class="anchored" data-anchor-id="step-5-communicating-my-findings">Step 5: Communicating my Findings</h2>
<p>Dear Adam Silver,</p>
<p>Thank you for choosing me to run analytics on all of your teams’ performances! Unfortunately, we did not find anything too groundbreaking, but hopefully it provides you with some new insights you may not have had before. First, we looked at the relationship between PRA and STOCKS, and we determined that there is a positive linear relationship between the two variables. Upon further probing (partial correlation), we found that this relationship disappears when we control for Minutes Played, suggesting that having a higher PRA does not make you a better defensive player, but rather, more minutes on the court make you more likely to have accumulated higher PRA and STOCKS. Additionally, there seemed to be no difference in PRA and STOCKS between conferences. I then took a look at how Minutes Played varied by Age, and we saw that the older a player is, the more minutes they get to play on average. Overall, this finding was pretty consistent across conferences, but I noticed that the older players in the West coast conference tended to get more playing time than the older players in the East coast conference. Finally, we ran some correlations with the player’s performances, which revealed that there is no practical differences between conferences when it comes to PRA or STOCKS. You might be able to make the case for Conference negatively predicting STOCKS, but the relationship is so weak that it does not really mean much in the real world. Our final takeaway is that there was a strong positive correlation between performance and awards: those who performed better throughout the season (higher PRA and STOCKS) were much more likely to have received an award at the end of the season. So, were there differences between East coast and West coast conferences? Not particularly. At least, nothing to write home about. And as far as PRA and STOCKS moving together, they only do so when confounding variables are involved. A limitation from my analysis is that I only ran correlations for the most part; it would be interesting to see how teams within the same conferences varied. Anyway, I hope you choose me again (for some reason) to run analyses for your team performances next year, even though I know nothing about basketball!</p>
<p>Sincerely,</p>
<p>Shannon Joyce</p>
</section>
</main>
<!-- /main column -->
<script id="quarto-html-after-body" type="application/javascript">