Skip to contents

These functions allow a user to generate run expectancy and related measures and variables from Baseball Savant data. Measures and variables will be added to the data frame.

Usage

run_expectancy_code(df, level = "plate appearance")

Arguments

df

A data frame generated from Baseball Savant.

level

Whether you want run expectancy calculated at the plate appearance or pitch level. Defaults to plate appearance.

Value

Returns a tibble with the following columns:

col_nametypes
pitch_typecharacter
game_dateDate
release_speednumeric
release_pos_xnumeric
release_pos_znumeric
player_namecharacter
batternumeric
pitchernumeric
eventscharacter
descriptioncharacter
spin_dirlogical
spin_rate_deprecatedlogical
break_angle_deprecatedlogical
break_length_deprecatedlogical
zonenumeric
descharacter
game_typecharacter
standcharacter
p_throwscharacter
home_teamcharacter
away_teamcharacter
typecharacter
hit_locationinteger
bb_typecharacter
ballsinteger
strikesinteger
game_yearinteger
pfx_xnumeric
pfx_znumeric
plate_xnumeric
plate_znumeric
on_3bnumeric
on_2bnumeric
on_1bnumeric
outs_when_upinteger
inningnumeric
inning_topbotcharacter
hc_xnumeric
hc_ynumeric
tfs_deprecatedlogical
tfs_zulu_deprecatedlogical
fielder_2numeric
umpirelogical
sv_idcharacter
vx0numeric
vy0numeric
vz0numeric
axnumeric
aynumeric
aznumeric
sz_topnumeric
sz_botnumeric
hit_distance_scnumeric
launch_speednumeric
launch_anglenumeric
effective_speednumeric
release_spin_ratenumeric
release_extensionnumeric
game_pknumeric
pitcher_1numeric
fielder_2_1numeric
fielder_3numeric
fielder_4numeric
fielder_5numeric
fielder_6numeric
fielder_7numeric
fielder_8numeric
fielder_9numeric
release_pos_ynumeric
estimated_ba_using_speedanglenumeric
estimated_woba_using_speedanglenumeric
woba_valuenumeric
woba_denominteger
babip_valueinteger
iso_valueinteger
launch_speed_angleinteger
at_bat_numbernumeric
pitch_numbernumeric
pitch_namecharacter
home_scorenumeric
away_scorenumeric
bat_scorenumeric
fld_scorenumeric
post_away_scorenumeric
post_home_scorenumeric
post_bat_scorenumeric
post_fld_scorenumeric
if_fielding_alignmentcharacter
of_fielding_alignmentcharacter
spin_axisnumeric
delta_home_win_expnumeric
delta_run_expnumeric
final_pitch_gamenumeric
final_pitch_at_batnumeric
runs_scored_on_pitchnumeric
bat_score_afternumeric
final_pitch_inningnumeric
bat_score_start_inningnumeric
bat_score_end_inningnumeric
cum_runs_in_inningnumeric
runs_to_end_inningnumeric
count_base_out_statecharacter
avg_renumeric
next_count_base_out_statecharacter
next_avg_renumeric
change_renumeric
re24numeric

Examples

# \donttest{
 try({
   df <- statcast_search(start_date = "2016-04-06", end_date = "2016-04-15", 
                         playerid = 621043, player_type = 'batter') 
   run_expectancy_code(df, level = "plate appearances")
 })
#> # A tibble: 159 × 107
#>    pitch_type game_date  release_speed release_pos_x release_pos_z
#>    <chr>      <date>             <dbl>         <dbl>         <dbl>
#>  1 FF         2016-04-06          92.8         -2.25          6.89
#>  2 FF         2016-04-06          91.1         -2.32          6.83
#>  3 SL         2016-04-06          80.2         -2.46          6.94
#>  4 FF         2016-04-06          94.5         -2.37          6.74
#>  5 FF         2016-04-06          94           -1.98          6.77
#>  6 FC         2016-04-06          92.6         -2.35          6.62
#>  7 CH         2016-04-06          91.7         -2.25          6.64
#>  8 CH         2016-04-06          86.1         -2.07          6.93
#>  9 SI         2016-04-06          91.4         -1.89          6.71
#> 10 SI         2016-04-06          91.6         -1.73          6.8 
#> # ℹ 149 more rows
#> # ℹ 102 more variables: player_name <chr>, batter <dbl>, pitcher <dbl>,
#> #   events <chr>, description <chr>, spin_dir <lgl>,
#> #   spin_rate_deprecated <lgl>, break_angle_deprecated <lgl>,
#> #   break_length_deprecated <lgl>, zone <dbl>, des <chr>,
#> #   game_type <chr>, stand <chr>, p_throws <chr>, home_team <chr>,
#> #   away_team <chr>, type <chr>, hit_location <int>, bb_type <chr>, …
# }