Description Usage Arguments Details Value Examples
View source: R/linearWeights.R
Retrieves a linear weights model object
1 |
type |
A string representing either 'xr', 'woba' |
Retrieves any of several linear weights formulae as lm
objects
A lm
object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ds = getData()
event = data.frame(event = ds$event)
woba = getLinearWeightsModel(type = 'woba')
xr = getLinearWeightsModel(type = 'xr')
ds$woba = predict(woba, newdata=event)
ds$xr = predict(xr, newdata=event)
braa = getLinearWeightsModelfromData(ds, type = 'bp')
bp.events = levels(as.factor(braa$model$event))
event[which(!(event %in% bp.events))] <- NA
ds$braa = predict(braa, newdata=event)
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))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.