adjust_year_effects: Adjust for Changes in Run-Scoring Environment

Description Usage Arguments Details Value Examples

View source: R/clean-data.R

Description

Uses year multipliers to adjust statistics to account for changes in run scoring environment. This is particularly useful because a 0.300 OBP in 2006 is much different from a 0.300 OBP in 2014.

Usage

1
adjust_year_effects(stats, yfs, type = c("bat", "pit"))

Arguments

stats

data.frame of player statistics. Obtained from adjust_park_factors.

yfs

data.frame of multipliers for year effects. Must be in proper form.

type

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

Details

stats are left joined with yfs. If any year factors are missing, they are set to average (which is 100). The statistics are turned into long format using gather from the tidyr package. Statistics are then adjusted using the formula:

adjusted = Count * 100 / YF

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

Value

tbl_df of statistics that have been adjusted for year effects.

Examples

1
2
3
4
5
6
curr_wd <- getwd()
setwd("N:/Apps/simScoresApp/data")
stats <- read.csv("2-park-adjusted/bat-pf-adjust.csv", header = T, stringsAsFactors = F)
yfs <- read.csv("manual-info/Year-Factors.csv", header = T, stringsAsFactors = F)
x <- adjust_year_effects(stats, yfs, type = "bat")
setwd(curr_wd)

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