9.5 Stochastic Processes

9.5.1 Multiple Transitions

after three plate appearances

P_matrix_3 <- P_matrix %*% P_matrix %*% P_matrix
After 3 Plate Appearances
starting with bases empty and zero outs
state new_state Prob
000 0 3 0.372
000 0 100 2 0.241
000 0 110 1 0.081
000 0 010 2 0.074
000 0 000 2 0.053
000 0 001 2 0.029
000 0 101 1 0.028
000 0 100 1 0.026
000 0 000 1 0.019
000 0 011 1 0.019
000 0 010 1 0.016
000 0 111 0 0.011
000 0 110 0 0.007
000 0 001 1 0.007
000 0 101 0 0.004
000 0 000 0 0.004
000 0 100 0 0.003
000 0 011 0 0.003
000 0 010 0 0.002
000 0 001 0 0.001
table code
P_matrix_3 |>
  as_tibble(rownames = "state") |>
  filter(state == "000 0") |>
  pivot_longer(
    cols = -state, 
    names_to = "new_state", 
    values_to = "Prob" 
  ) |>
  filter(Prob > 0) |>
  arrange(desc(Prob)) |>
  gt() |>
  cols_align(align = "center") |>
  data_color(columns = Prob,
             palette = "inferno") |>
  fmt_number(columns = Prob,
             decimals = 3) |>
  tab_header(title = "After 3 Plate Appearances",
             subtitle = "starting with bases empty and zero outs")

9.5.2 Fundamental Matrix

\[N = (I - Q)^{-1}\]

Q <- P_matrix[-25, -25] #without 3-out states
N <- solve(diag(rep(1, 24)) - Q) 
N_0000 <- round(N["000 0", ], 2)
head(N_0000, n = 6)
## 000 0 000 1 000 2 001 0 001 1 001 2 
##  1.05  0.75  0.60  0.01  0.03  0.05

Starting at the beginning of the inning (the “000 0” state)

  • the average number of times the inning will be in the “000 0” state is 1.05
  • the average number of times in the “000 1” state is 0.75
  • the average number of times in the “000 2” state is 0.6
  • etc.
sum(N_0000)
## [1] 4.27
  • the average number of plate appearances in a half-inning (before three outs) is 4.27.

9.5.3 Visit Frequency

the length of the remainder of the inning, on average, starting with each possible state

\[N\vec{1}\]

avg_num_plays <- N %*% rep(1, 24) |> t() |> round(2)
avg_num_plays[,1:8]
## 000 0 000 1 000 2 001 0 001 1 001 2 010 0 010 1 
##  4.27  2.87  1.46  4.33  2.99  1.53  4.34  2.93