generated from jtr13/cctemplate
-
Notifications
You must be signed in to change notification settings - Fork 139
/
nbastatr_tutorial.Rmd
204 lines (111 loc) · 5.67 KB
/
nbastatr_tutorial.Rmd
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
# Get NBA dataset in R
Yanbing Chen
## Motivation
My final project for this course is analysis on professional basketball, more specifically, the transformation of game style of professional basketball. Having a great dataset is a prerequisite for the project but the official dataset is only viewable on NBA.com but not available for downloading as csv file. Fortunately, there is a useful package in R called 'nbastatR'. Hence, while I am trying to explore the package in R, it is also great to complete this tutorial to share the information and help others who are also interested in NBA or basketball analysis in R.
The thing needed to be noticed that the package might not satisfy your all needs for the project. There are other ways to obtain the data, such as scraping data from NBA official website using python, which I am also investing on.
Since there are a lot of functions in the package to use, I will mainly focus on the functions related to my topic. For more information, please refer to https://www.rdocumentation.org/packages/nbastatR/versions/0.1.110202031 and the package maintainer Alex Bresler.
## installation
```{r eval=FALSE}
devtools::install_github("abresler/nbastatR")
library(nbastatR)
```
## Functions
agents_players() Players Agents
all_nba_teams() All NBA Teams
all_star_games() NBA All Star Games
assign_bref_data() Assign nested BREF data to environment
assign_nba_players() Assign NBA player dictionary to environment
assign_nba_teams() Assign NBA teams to environment
beyond_the_numbers() NBA.com Beyond The Numbers Articles
box_scores() NBA box scores
bref_awards() Basketball reference awards
bref_awards_votes() Basketball Reference award votes
bref_bios() Basketball Reference players bios
bref_injuries() Active injuries
bref_players_stats() Basketball Reference Player Season Tables
bref_teams_stats() Basketball Reference teams seasons data
coaching_staffs() NBA active coaching staffs
current_schedule() NBA current season schedule
current_standings() Current standings
days_scores() Get NBA Dates' NBA Scores
dictionary_bref_awards() Basketball Reference Awards
dictionary_bref_coaches() Basketball Reference coach dictionary
dictionary_bref_players() Basketball Reference player dictionary
dictionary_bref_teams() Basketball Reference team dictionary
dictionary_nba_names() Dictionary of NBA Headers and nbastatR names
dictionary_player_photos() Cached player photo dictionary
draft_combines() NBA draft combine data
drafts() NBA drafts
fanduel_summary() Games fanduel summary
franchise_leaders() Franchise leaders
game_logs() NBA game logs for specified parameters
hoops_hype_salary_summary() HoopsHype NBA teams summary salaries
hoopshype_salaries() Hoopshype teams players salaries
metrics_leaders() League leaders by season
nba_franchise_history() Get NBA franchise history
nba_insider_salaries() NBA team salaries
nba_player_ids() Players' NBA player ids
nba_players() NBA player dictionary
nba_stats_api_items() NBA stats API parameters, teams and items
nba_teams() NBA team dictionary
nba_teams_ids() NBA team ids
nba_teams_seasons() NBA teams seasons
nbadraftnet_mock_drafts() NBADraft.net mock drafts
nbastats_api_parameters() NBA Stats API Parameters
play_by_play() NBA games play-by play
play_by_play_v2() NBA games play-by-play v2
player_profiles() NBA.com player profiles
players_agents() Get NBA Players Agents
players_awards() NBA players awards
players_bios() NBA.com bios
players_careers() Player career stats
players_rotowire() Players RotoWire news
players_tables() NBA players table data
playoff_pictures() NBA seasons playoff picture
pst_transaction() ProSports NBA transactions
scale_per_minute() Summarise data per minute
seasons_players() Seasons players
seasons_rosters() NBA teams seasons rosters
seasons_schedule() NBA seasons schedules
sl_players() Summer League Players
sl_teams() Summer League Teams
spread_data() Spread gathered data frame
standings() Get seasons standing data
summarise_per_minute() Summarize data per minute
synergy() Get Synergy data for specified season
team_season_roster() Team roster
teams_annual_stats() NBA teams yearly performance
teams_coaches() Seasons coaching staffs
teams_details() NBA teams details
teams_players_stats() NBA teams and player statistics
teams_rankings() NBA teams rankings
teams_rosters() Teams seasons rosters
teams_rotowire() Teams Rotowire news
teams_seasons_info() NBA teams seasons information
teams_shots() Get teams seasons shot charts
teams_tables() NBA Team table data by season
transactions() NBA transactions since 2012
validate_nba_player_photos() Validate NBA Player photos
widen_bref_data() Widens basketball reference table data
win_probability() NBA games win probabilities
## Guides to Functions
Here are several examples for me to approach the goal of my analysis by using the package.
1. By looking at players drafted in each year, we could figure out what kind of players teams wanted in the past and nowadays.
```{r eval=FALSE}
drafts(draft_years = 2000:2010)
```
2. By looking at total point leader in each season, we could discover how the games are changing, maybe from dominating by centers to guards.
```{r eval=FALSE}
metrics_leaders(seasons = 2000:2010,
metric = "pts",
season_types = "Regular Season",
modes = "PerGame")
```
3. By examining the shot chart, we could find some trends about shooting such as longer shot distance.
```{r eval=FALSE}
teams_shots(teams = "Brooklyn Nets", seasons = 2000:2010)
```
4. By summarizing the total points each season, we might see some changes to the speed of plays in a game.
```{r eval=FALSE}
teams_annual_stats(teams = "New York Knicks",modes = c("Totals"))
```