# NFL Markov: 5 of n (nflMarkov, the Python code)

In part 4, I described modeling the yards-gained distribution, including the probabilities to kick versus run a play. Here I will describe how these are controlled in the Markov chain computer program.

The program reads a parameter file which has a generic form of
``` parameter-name down ytg-min ytg-max yfog param-value ```

For a given down and distance range (yards-to-go, or ytg), the parameter values are stored as a function of yards-from-own-goal. Then, during run time, the parameter value is set using linear interpolation over yfog. This gives a very flexible input scheme. As a concrete example, here are example parameter values for “going for it on 4th”,

``` 4thGoForItProb 4 1 1 0 0 4thGoForItProb 4 1 1 20 0 4thGoForItProb 4 1 1 50 0.24 4thGoForItProb 4 1 1 60 0.78 4thGoForItProb 4 1 1 70 0.75 4thGoForItProb 4 1 1 85 0.42 4thGoForItProb 4 1 1 100 0.50```

``` ```

```4thGoForItProb 4 2 4 0 0 4thGoForItProb 4 2 4 20 0 4thGoForItProb 4 2 4 40 0.07 4thGoForItProb 4 2 4 50 0.10 4thGoForItProb 4 2 4 60 0.45 4thGoForItProb 4 2 4 80 0.14 4thGoForItProb 4 2 4 100 0.14 ```

This says that, when its 4th and between 1 and 1 to go (in other words precisely 1), if yfog is between 0 and 20, then interpolate between 0 and 0. In other words the probability to go for it is 0. If yfog is between 20 and 50, interpolate between 0 and 0.24. So for example, half way in between, when yfog=35, the probability would be 0.12. On the other hand, if yards-to-go is between 2 and 4 (inclusive), then the probability at yfog=35 will be the slope, $(0.07-0.00)/(40-20)$, times $35-20 = 15$, plus the initial value at yfog = 20, which is 0. That is, $0 + 0.07/20*15 = 0.0525$, which is a long-winded way of saying that the value is determined through linear interpolation between the points (20, 0) and (40, 0.07). If down is set to 0, it means the parameters hold for downs 1-4. The parameters that are controllable are,

``` intProb: interception probability fumProb: fumble probability incompleteProb: incompletion probability yardsDistParsRush: parameters of the Bazin-Gauss function for rushes (G identically 0) yardsDistParsPass: parameters of the Bazin-Gauss function for passes 4thGoForItProb: probability to go for it on 4th 4thFgProb: probability to go for a field goal on 4th FgMakeProb: probability to make a field goal passProb: given that you run a play, the probability to pass ```

The code has two modes, empirical and user-defined. If the empirical model is chosen, the parameters controlling the yards-gained distributions are ignored and the distributions are instead read in empirically.
The final input is a model name, which determines the output data file name, where the transition matrix and the expectation value vector (among other things) are stored for later reference or ease of comparison to a different model.