#### Introduction

Here is a brief illustration of using the WinProbability package just created on my Github site.

Install the package from Github:

```
library(devtools)
install_github("bayesball/WinProbability")
```

Load the package:

`library(WinProbability)`

#### Setup

Iâ€™m in a folder where I have a raw Retrosheet play-by-play datafile. Note that the file must be of the form `allYEAR.csv`

where YEAR is the value input in the function.

`dir()`

`## [1] "all2018.csv" "roster2018.csv" "WinProbabilities.Rmd"`

#### Compute runs expectancies

The `compute.runs.expectancy`

function:

- Reads in the raw dataset
- Adds a header to the Retrosheet datafile
- Computes the run expectancies and adds these to the datafile

`d2018 <- compute.runs.expectancy(2018)`

#### Compute win probabilities

The `compute.win.probs`

function will

- Compute the win probabilities for all plays.
- The input is the Retrosheet play-by-play data frame with run expectancy values included

`d2018 <- compute.win.probs(d2018)`

#### Graph the win probabilities for a game

The `graph.game`

function will plot the win probabilities for all plays in a specific game.

`plays <- graph.game(d2018, "SLN201805190")`