linearWeights: linearWeights

Description Usage Arguments Details Value Examples

Description

Apply a linear weights formula to an MLBAM data set

Usage

1

Arguments

data

An MLBAM data set

type

A string representing either "xr27", "woba"

Details

Applies any of several linear weights formulae to an MLBAM data set

Value

A numeric vector of linear weights values

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
ds = getData()
ds$woba = linearWeights(ds, type = "woba")
ds$xr = linearWeights(ds, type = "xr")
leaders = ddply(ds, ~batterId, summarise, Name = batterName[1], PA = sum(isPA)
, WOBA = sum(woba) / sum(isPA == TRUE), XR27 = sum(xr) * 25.5 / sum(isPA & !isHit))
# The top 20
head(leaders[order(leaders$WOBA, decreasing = TRUE),], 20)
# meeting a plate appearance minimum
qualified = subset(leaders, PA > length(unique(ds$gameId)) * 3.1 / 15)
# WOBA leaders
head(qualified[order(qualified$WOBA, decreasing = TRUE),], 20)
# XR27 leaders
head(qualified[order(qualified$XR27, decreasing = TRUE),], 20)
# Compare the two metrics
xyplot(XR27 ~ WOBA, data = qualified)
with(qualified, cor(WOBA, XR27))

frogman141/openWAR documentation built on Dec. 20, 2021, 8:52 a.m.