Advanced basketball statistics in R"

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:

Data set

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:

  1. 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:

    • individuals_data_adjustment. Function that allows transformation of individual stats and defensive stats.
    • lineups_data_adjustment. Function that allows the transformation of lineups.
    • play_data_adjustment. Function that allows the transformation of plays.
    • team_stats. Function that allows you to perform team statistics.
  2. 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:

Individual Data Set

If we want to perform the analysis of individual statistics, we must have the following data sets:

Lineup Data Set

If we want to perform the analysis of lineup statistics, we must have the following data sets:

Play Data Set

If we want to perform the analysis of play statistics, we must have the following data sets:

Team Data Set

If we want to perform the analysis of team statistics, we must have the following data sets:

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:

Functions for individual statistics

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:

individuals_advance_stats

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

individuals_defensive_actual_floor_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

individuals_defensive_estimated_floor_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

individuals_games_adder.

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

individuals_ofensive_floor_stats.

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

individuals_stats_per_game

For this function we will have to enter individual statistics:

per_game_stats <- individuals_stats_per_game(individual)
per_game_stats

individuals_stats_per_minutes

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

individuals_stats_per_possesion

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

Functions for lineup statistics

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:

lineups_advance_stats

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

lineups_backcourt

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

lineups_comparator_stats

For this function we will have to enter extended lineup statistics:

lnp_comparator <- lineups_comparator_stats(lineup_extended,48)
lnp_comparator

lineups_games_adder

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

lineups_paint

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

lineups_players

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

lineups_searcher

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

lineups_separator

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

lineups_stats_per_possesion

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

Functions for play statistics

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:

play_advance_stats

For this function we will have to enter play statistics:

play_adv_stats <- play_advance_stats(play_stats)
play_adv_stats

play_games_adder

For this function we will have to enter play statistics:

pl_game_adder <- play_games_adder(play_stats,play_stats)
pl_game_adder

play_stats_per_game

For this function we will have to enter play statistics:

play_per_game_stat <- play_stats_per_game(play_stats)
play_per_game_stat

play_stats_per_possesion

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

play_team_stats

For this function we will have to enter play statistics:

play_team_stats <- play_team_stats(play_stats)
play_team_stats

Functions for team statistics

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:

team_advanced_stats

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

team_stats_per_game

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

team_stats_per_minutes

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

team_stats_per_possesion

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


Try the AdvancedBasketballStats package in your browser

Any scripts or data that you put into this service are public.

AdvancedBasketballStats documentation built on April 6, 2021, 5:06 p.m.