calc_MLEs: Calculates Major League Equivalencies (MLEs) for specified...

Description Usage Arguments Details Value Examples

View source: R/clean-data.R

Description

Takes statistics returned from adjust_park_factors() and turns them into MLEs

Usage

1
calc_MLEs(stats, mles, type = c("bat", "pit"))

Arguments

stats

data.frame of player statistics. Obtained from adjust_park_factors()

mles

data.frame of multipliers for MLEs. Must be in proper form.

type

character. Whether these are batting or pitching data. Defaults to batting

Details

stats are left joined with mles. If any MLEs are missing, they are set to average (which is 1). The statistics are turned into long format using gather from the tidyr package.

For batters statistics are adjusted by multiplying by the multiplier

adjusted = Count * MLE

. For pitchers, statistics are divided by the multiplier

adjusted = Count / MLE

. Extraneous columns are discarded then the data are returned to a wide format using spread from the tidyr package.

Since the same multiplier is used for batters and pitchers, it is assumed that the transition from one level to the next is the same for batters and pitchers. That is, this assumes that strikeouts increase for batters and decrease for pitchers at the same rate when changing level. Additional research could be done to see if this assumption is valid.

Value

tbl_df of statistics that have been adjusted for level effects.

Examples

1
2
3
4
5
6
curr_sd <- getwd()
setwd("N:/Apps/simScoresApp/data")
stats <- read.csv("3-year-adjusted/bat-yf-adjust.csv", header = T, stringsAsFactors = F)
mults <- read.csv("manual-info/Level_Multipliers.csv", header = T, stringsAsFactors = F)
x <- calc_MLEs(stats, mults, type = "bat")
setwd(curr_wd)

guytuori/simScores documentation built on May 17, 2019, 9:29 a.m.