library(AdvancedBasketballStats) knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
Advanced basketball statistics is an R package that allows you to perform different statistics calculations that are used in the world of basketball. In the package we can perform different calculations for the following types of statistics:
To create our data set we can do it in two different ways:
After deciding how to create our data set we must know what analysis we want to perform, since depending on this we will need different types of data sets:
We can use the functions that allow the transformation of a simple data set, that is, without the calculations performed by the data_adjustment() functions. The functions that the transformation allows are the following:
We can use Data frames with the format corresponding to the data_adjustment() functions.
Once the two ways of creating the data have been commented, the examples of the data sets for subsequent use are shown:
If we want to perform the analysis of individual statistics, we must have the following data sets:
Data set created the individuals_data_adjustment function: ```r individual_stats <- data.frame("Name" = c("James","Team"), "G" = c(67,0), "GS" = c(62,0),"MP" = c(2316,1), "FG" = c(643,0), "FGA" = c(1303,0), "3P " = c(148,0),"3PA" = c(425,0),"2P" = c(495,0), "2PA" = c(878,0), "FT" = c(264,0),"FTA" = c(381,0),"ORB" = c(66,0), "DRB" = c(459,0), "AST" = c(684,0),"STL" = c(78,0), "BLK" = c(36,0),"TOV" = c(261,0), "PF" = c(118,0),"PTS" = c(1698,0), "+/-" = c(0,0))
individual_stats <- individuals_data_adjustment(individual_stats)
individual_stats
+ Data set created with the same structure as the one generated by the individuals_data_adjustment function
r
individual <- data.frame("name" = c("LeBron James","Team"),"G" = c(67,0),
"GS" = c(62,0),"MP" = c(2316,0),"FG" = c(643,0), "FGA" = c(1303,0),
"Percentage FG" = c(0.493,0),"3P" = c(148,0),"3PA" = c(425,0),
"Percentage 3P" = c(0.348,0),"2P" = c(495,0),"2PA" = c(878,0),
"Percentage 2P" = c(0.564,0),"FT" = c(264,0),"FTA FG" = c(381,0),
"Percentage FT" = c(0.693,0), "ORB" = c(66,0),"DRB" = c(459,0),
"TRB" = c(525,0),"AST" = c(684,0),"STL" = c(78,0),"BLK" = c(36,0),
"TOV" = c(261,0), "PF" = c(118,0),"PTS" = c(1698,0),"+/-" = c(0,0))
individual
* Data set representing individual defensive statistics.
+ Data set created with the individuals_data_adjustment function:
r
defensive_stats <- data.frame("Name" = c("Witherspoon ","Team"),
"MP" = c(14,200),"DREB" = c(1,0),"FM" = c(4,0), "BLK" = c(0,0),
"FTO" = c(0,0),"STL" = c(1,1), "FFTA" = c(0,0), "DFGM" = c(1,0),
"DFTM" = c(0,0))
defensive_stats <- individuals_data_adjustment(defensive_stats)
defensive_stats
+ Data set created with the same structure as the one generated by the individuals_data_adjustment function
r
defensive <- data.frame("Name" = c("Witherspoon ","Team"),
"MP" = c(14,200),"DREB" = c(1,0), "FM" = c(4,0),
"BLK" = c(0,0),"TOTAL FM" = c(4,0),"FTO" = c(0,0),
"STL" = c(1,1), "TOTAL FTO " = c(1,0), "FFTA" = c(0,0),
"DFGM" = c(1,0), "DFTM" = c(0,0))
defensive ```
Data set that represents team statistics.
r
tm_stats <- team_stats(individual_stats)
tm_stats
indi_team_stats
* Data set that represents the statistics of the rival team.
+ Data set created with the same structure as the one generated by the team_stats function
r
indi_rival_stats <- data.frame("G" = c(71), "MP" = c(17090),
"FG" = c(2773), "FGA" = c(6187),"Percentage FG" = c(0.448),
"3P" = c(827),"3PA" = c(2373),"Percentage 3P" = c(0.349),
"2P" = c(1946), "2PA" = c(3814),"Percentage 2P" = c(0.510),
"FT" = c(1270),"FTA FG" = c(1626),"Percentage FT" = c(0.781),
"ORB" = c(668), "DRB" = c(2333),"TRB" = c(3001), "AST" = c(1662),
"STL" = c(585),"BLK" = c(263),"TOV" = c(1130),"PF" = c(1544),
"PTS" = c(7643), "+/-" = c(0))
indi_rival_stats ```
If we want to perform the analysis of lineup statistics, we must have the following data sets:
Data set that represents basic lineup statistics.
linp_basic <- lineups_data_adjustment(linp_basic)
linp_basic
+ Data set created with the same structure as the one generated by the lineups_data_adjustment function
r
lineup_basic <- data.frame("PG" = c("James","Rondo"),"SG" = c("Green","Caruso"),
"SF" = c("Caldwell","Kuzma"), "PF" = c("Davis","Davis"),
"C" = c("Howard ","Howard"),"MP" = c(7,1), "FG " = c(4,0),
"FGA " = c(7,0),"Percentage FG" = c(0.571,0),
"X3P " = c(0,0),"X3PA " = c(2,0),"Percentage 3P" = c(0,0),
"X2P " = c(4,0), "X2PA " = c(5,0), "Percentage 2P" = c(0.8,0),
"FT " = c(1,0), "FTA " = c(3,0), "Percentage FT" = c(0.333,0),
"ORB " = c(2,0), "DRB " = c(5,0),"TRB " = c(7,0), "AST " = c(2,0),
"STL " = c(1,0), "BLK " = c(0,0),"TOV " = c(7,2), "PF" = c(1,0),
"PLUS" = c(9,0),"MINUS" = c(17,3),"P/M" = c(-8,-3))
lineup_basic
* Data set that represents extended lineup statistics.
+ Data set created with the lineups_data_adjustment function
r
linp_extended <- data.frame("PG" = c("James","Rondo"),"SG"= c("Green","Caruso"),
"SF" = c("Caldwell","Kuzma"), "PF" = c("Davis","Davis"),
"C" = c("Howard ","Howard"),"MP" = c(7,1), "FG " = c(6,0),
"OppFG " = c(6,0), "FGA " = c(10,0),"OppFGA " = c(9,0),
"X3P " = c(2,0),"Opp3P " = c(1,0),"X3PA " = c(4,0),
"Opp3PA " = c(3,0),"X2P" = c(4,0),"Opp2P" = c(5,0),"X2PA " = c(6,0),
"Opp2PA" = c(8,0) , "FT " = c(0,0),"OppFT " = c(1,0), "FTA " = c(0,0),
"OppFTA" = c(1,0),"OppRB" = c(2,0),"OppOppRB" = c(1,0),"DRB" = c(4,0),
"OppDRB" = c(1,0),"AST " = c(5,0),"OppAST " = c(4,0),"STL" = c(1,0),
"OppSTL" = c(3,0),"BLK" = c(0,0),"OppBLK" = c(1,0),"TOppV" = c(5,2),
"OppTOppV" = c(3,2),"PF" = c(1,0),"OppPF" = c(3,0),"PLUS" = c(15,0),
"MINUS" = c(14,3))
linp_extended <- lineups_data_adjustment(linp_extended)
linp_extended
+ Data set created with the same structure as the one generated by the lineups_data_adjustment function
r
lineup_extended <- data.frame("PG" = c("James","Rondo"),"SG" = c("Green","Caruso"),
"SF" = c("Caldwell","Kuzma"), "PF" = c("Davis","Davis"),
"C" = c("Howard ","Howard"),"MP" = c(7,1), "FG " = c(6,0),
"OppFG " = c(6,0), "FGA " = c(10,0),"OppFGA " = c(9,0),
"X3P " = c(2,0),"Opp3P" = c(1,0),"X3PA" = c(4,0),"Opp3PA" = c(3,0),
"X2P" = c(4,0),"Opp2P " = c(5,0), "X2PA " = c(6,0),"Opp2PA " = c(8,0) ,
"FT " = c(0,0),"OppFT " = c(1,0), "FTA " = c(0,0),"OppFTA " = c(1,0),
"OppRB " = c(2,0),"OppOppRB " = c(1,0), "DRB" = c(4,0),"OppDRB" = c(1,0),
"TRB" = c(6,0),"OppTRB" = c(2,0), "AST " = c(5,0),"OppAST " = c(4,0),
"STL " = c(1,0),"OppSTL " = c(3,0), "BLK " = c(0,0), "OppBLK " = c(1,0),
"TOppV " = c(5,2), "OppTOppV " = c(3,2),"PF" = c(1,0),"OppPF" = c(3,0),
"PLUS" = c(15,0),"MINUS" = c(14,3),"P/M" = c(1,-3))
lineup_extended ```
Data set that represents team statistics.
r
tm_stats <- team_stats(individual_stats)
tm_stats
lineup_team_stats
* Data set that represents the statistics of the rival team.
r
lineup_rival_stats <- data.frame("G" = c(71), "MP" = c(17090),
"FG" = c(2773), "FGA" = c(6187),"Percentage FG" = c(0.448),
"3P" = c(827),"3PA" = c(2373),"Percentage 3P" = c(0.349),
"2P" = c(1946), "2PA" = c(3814),"Percentage 2P" = c(0.510),
"FT" = c(1270),"FTA FG" = c(1626), "Percentage FT" = c(0.781),
"ORB" = c(668), "DRB" = c(2333),"TRB" = c(3001), "AST" = c(1662),
"STL" = c(585),"BLK" = c(263),"TOV" = c(1130),"PF" = c(1544),
"PTS" = c(7643), "+/-" = c(0))
lineup_rival_stats ```
If we want to perform the analysis of play statistics, we must have the following data sets:
Data set that represents play statistics.
play_stats <- play_data_adjustment(play_stats)
play_stats
+ Data set created with the same structure as the one generated by the play_data_adjustment function
r
play <- data.frame("Name" = c("Sabonis ","Team"),
"GP" = c(62,71),"PTS" = c(387,0), "FG" = c(155,1),
"FGA" = c(281,1),"3P" = c(6,1),"3PA" = c(18,1),
"FT" = c(39,1), "FTA" = c(53,1),"ANDONE" = c(12,1),
"AST" = c(0,1), "TOV" = c(27,1))
play
* Data set that represents team statistics.
+ Data set created with the team_stats function:
r
tm_stats <- team_stats(individual_stats)
tm_stats
+ Data set created with the same structure as the one generated by the team_stats function
r
play_team_stats <- data.frame("G" = c(71), "MP" = c(17090),
"FG" = c(3006), "FGA" = c(6269),"Percentage FG" = c(0.48),
"3P" = c(782),"3PA" = c(2242), "Percentage 3P" = c(0.349),
"2P" = c(2224), "2PA" = c(4027), "Percentage 2P" = c(0.552),
"FT" = c(1260),"FTA FG" = c(1728), "Percentage FT" = c(0.729),
"ORB" = c(757),"DRB" = c(2490),"TRB" = c(3247),"AST" = c(1803),
"STL" = c(612), "BLK" = c(468),"TOV" = c(1077),"PF" = c(1471),
"PTS" = c(8054), "+/-" = c(0))
play_team_stats
+ Data set that represents the statistics of the rival team.
r
play_rival_stats <- data.frame("G" = c(71), "MP" = c(17090),
"FG" = c(2773), "FGA" = c(6187),"Percentage FG" = c(0.448),
"3P" = c(827),"3PA" = c(2373),"Percentage 3P" = c(0.349),
"2P" = c(1946), "2PA" = c(3814),"Percentage 2P" = c(0.510),
"FT" = c(1270),"FTA FG" = c(1626),"Percentage FT" = c(0.781),
"ORB" = c(668),"DRB" = c(2333),"TRB" = c(3001),"AST" = c(1662),
"STL" = c(585),"BLK" = c(263),"TOV" = c(1130),"PF" = c(1544),
"PTS" = c(7643), "+/-" = c(0))
play_rival_stats ```
If we want to perform the analysis of team statistics, we must have the following data sets:
Data set that represents the statistics of the team.
r
tm_stats <- team_stats(individual_stats)
tm_stats
team_stats
* Data set that represents the statistics of the rival team.
r
rival_stats <- data.frame("G" = c(71), "MP" = c(17090),
"FG" = c(2773), "FGA" = c(6187),"Percentage FG" = c(0.448),
"3P" = c(827),"3PA" = c(2373),"Percentage 3P" = c(0.349),
"2P" = c(1946), "2PA" = c(3814),"Percentage 2P" = c(0.510),
"FT" = c(1270),"FTA FG" = c(1626),"Percentage FT" = c(0.781),
"ORB" = c(668),"DRB" = c(2333),"TRB" = c(3001),"AST" = c(1662),
"STL" = c(585),"BLK" = c(263),"TOV" = c(1130),"PF" = c(1544),
"PTS" = c(7643), "+/-" = c(0))
rival_stats ```
Once the data sets have been created, we must choose which function or functions we want to use. Below are the different functions that the package has:
For individual statistics there are the following functions:
Below is an example of how each function works and what the input parameters should be for these:
For this function we will have to enter individual statistics, team statistics and rival team statistics:
advanced_stats <- individuals_advance_stats(individual,indi_team_stats,indi_rival_stats) advanced_stats
For this function we will have to enter defensive individual statistics, team statistics and rival team statistics:
defensive_actual_stats <- individuals_defensive_actual_floor_stats(defensive,indi_team_stats,indi_rival_stats) defensive_actual_stats
For this function we will have to enter individual statistics, team statistics and rival team statistics:
defensive_estimated_stats <- individuals_defensive_estimated_floor_stats(individual,indi_team_stats,indi_rival_stats) defensive_estimated_stats
For this function we will have to enter the two individual statistics previously calculated which we want to add the statistics:
games_adder <- individuals_games_adder(individual,individual) games_adder
For this function we will have to enter individual statistics, team statistics and rival team statistics:
ofensive_stats <- individuals_ofensive_floor_stats(individual,indi_team_stats,indi_rival_stats) ofensive_stats
For this function we will have to enter individual statistics:
per_game_stats <- individuals_stats_per_game(individual) per_game_stats
For this function we will have to enter the individual statistics and the number of minutes to which we want to project the statistics:
per_minutes_stats <- individuals_stats_per_minutes(individual,36) per_minutes_stats
For this function we will have to enter the individual statistics, the team statistics, the rival team statistics, the number of minutes that a single game lasts and the number of possessions to which we want to project the statistics:
per_poss_stats <- individuals_stats_per_possesion(individual,indi_team_stats,indi_rival_stats,100,48) per_poss_stats
For individual statistics there are the following functions:
Below is an example of how each function works and what the input parameters should be for these:
For this function we will have to enter extended lineup statistics and the number of minutes that a single game lasts:
lnp_advanced_stats <- lineups_advance_stats(lineup_extended,48) lnp_advanced_stats
For this function we will have to enter basic lineup statistics or extended lineup statistics:
lnp_bs_backcourt <- lineups_backcourt(lineup_basic) lnp_bs_backcourt
lnp_ex_backcourt <- lineups_backcourt(lineup_extended) lnp_ex_backcourt
For this function we will have to enter extended lineup statistics:
lnp_comparator <- lineups_comparator_stats(lineup_extended,48) lnp_comparator
For this function we will have to enter basic lineup statistics or extended lineup statistics:
lnp_games_adder <- lineups_games_adder(lineup_basic,lineup_basic) lnp_games_adder
For this function we will have to enter basic lineup statistics or extended lineup statistics:
lnp_bc_paint <- lineups_paint(lineup_basic) lnp_bc_paint
lnp_ex_paint <- lineups_paint(lineup_extended) lnp_ex_paint
For this function we will have to enter basic lineup statistics or extended lineup statistics and the number of position that we want to find:
lnp_bc_players <- lineups_players(lineup_basic,5) lnp_bc_players
lnp_ex_players <- lineups_players(lineup_extended,5) lnp_ex_players
For this function we will have to enter basic lineup statistics or extended lineup statistics, the name of the players that we want to find and the number of players that we want to find:
lnp_bc_searcher <- lineups_searcher(lineup_basic,1,"James","","","") lnp_bc_searcher
lnp_ex_searcher <- lineups_searcher(lineup_extended,1,"James","","","") lnp_ex_searcher
For this function we will have to enter extended lineup statistics and the indicator of what type of separation we want to make:
lnp_ex_sep_one <- lineups_separator(lineup_extended,1) lnp_ex_sep_one
lnp_ex_sep_two <- lineups_separator(lineup_extended,2) lnp_ex_sep_two
For this function we will have to enter basic lineup statistics, team statistics, rival team statistics, the number of minutes that a single game lasts and the number of possessions to which we want to project the statistics:
lnp_per_poss_stats <- lineups_stats_per_possesion(lineup_basic,lineup_team_stats,lineup_rival_stats,100,48) lnp_per_poss_stats
For individual statistics there are the following functions:
Below is an example of how each function works and what the input parameters should be for these:
For this function we will have to enter play statistics:
play_adv_stats <- play_advance_stats(play_stats) play_adv_stats
For this function we will have to enter play statistics:
pl_game_adder <- play_games_adder(play_stats,play_stats) pl_game_adder
For this function we will have to enter play statistics:
play_per_game_stat <- play_stats_per_game(play_stats) play_per_game_stat
For this function we will have to enter the play statistics, the team statistics, the rival team statistics, the number of minutes that a single game lasts and the number of possessions to which we want to project the statistics:
play_per_poss_stats <- play_stats_per_possesion(play_stats,play_team_stats,play_rival_stats,100,48) play_per_poss_stats
For this function we will have to enter play statistics:
play_team_stats <- play_team_stats(play_stats) play_team_stats
For individual statistics there are the following functions:
Below is an example of how each function works and what the input parameters should be for these:
For this function we will have to enter the team statistics and the rival team statistics:
team_adv_stats <- team_advanced_stats(team_stats,rival_stats,48) team_adv_stats
For this function we will have to enter the team statistics:
team_per_game_stat <- team_stats_per_game(team_stats) team_per_game_stat
For this function we will have to enter the team statistics and the number of minutes to which we want to project the statistics:
team_per_minutes_stat <- team_stats_per_minutes(team_stats,36) team_per_minutes_stat
For this function we will have to enter the team statistics, the rival team statistics and the number of possessions to which we want to project the statistics::
team_per_poss_stat <- team_stats_per_possesion(team_stats,rival_stats,100) team_per_poss_stat
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.