getModels: getModels

Description Usage Arguments Details Value Examples

View source: R/getModels.R

Description

Retrieve various models trained on GameDayPlays data

Usage

1

Arguments

data

a GameDayPlays dataset

type

the type of model to be built.

drop.incomplete

a LOGICAL indicating whether incomplete innings (e.g. walk-off innings) should be excluded

Details

This function will build various models based on the MLBAM data set and the openWAR framework.

Value

A model object with a predict() method

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
data(MLBAM2013)
re.mod = getModel(MLBAM2013, type = 'run-expectancy')

# Generate the Run Expectancy Matrix
states = expand.grid(startCode = 0:7, startOuts = 0:2)
matrix(predict(re.mod, newdata=states), ncol=3)

begin.states = MLBAM2013[,c('startCode', 'startOuts')]
ds = transform(MLBAM2013, startEx = predict(re.mod, newdata=begin.states))
end.states = MLBAM2013[,c('endCode', 'endOuts')]
end.states$endOuts = with(end.states, ifelse(endOuts == 3, NA, endOuts))
names(end.states) = names(begin.states)
ds = transform(ds, endEx = predict(re.mod, newdata=end.states))
ds$endEx = with(ds, ifelse(is.na(endEx), 0, endEx))

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