11.12 Applying park factors

Let’s retrieve Andrés Galarraga’s 1996 plate appearances ending with a batted ball, and # defining a column was_hr is defined indicating whether the event was a home run.

# query <- '
# SELECT "away_team_id", LEFT("game_id", 3) AS "home_team_id", "event_cd"
# FROM "events"
# WHERE "year" = 1996
#   AND "event_cd" IN (2, 18, 19, 20, 21, 22, 23)
#   AND "bat_id" = \'galaa001\';
# '
# 
# andres <- dbGetQuery(con, query) |>
#      mutate(was_hr = ifelse(event_cd == 23, 1, 0))
andres <- read_rds('./data/andres.rds')

head(andres, 20)
##    away_team_id home_team_id event_cd was_hr
## 1           COL          ATL        2      0
## 2           COL          ATL        2      0
## 3           COL          ATL        2      0
## 4           COL          ATL       20      0
## 5           COL          ATL        2      0
## 6           COL          ATL        2      0
## 7           COL          ATL        2      0
## 8           COL          ATL       20      0
## 9           COL          ATL       18      0
## 10          COL          ATL        2      0
## 11          COL          ATL       20      0
## 12          COL          ATL       23      1
## 13          COL          ATL        2      0
## 14          COL          ATL        2      0
## 15          COL          ATL        2      0
## 16          COL          ATL       23      1
## 17          COL          ATL       21      0
## 18          COL          ATL        2      0
## 19          COL          ATL        2      0
## 20          COL          CHN       20      0

Now, let’s calculate the pakr factor for Galarraga.

andres_pf <- andres |>
     inner_join(ev_compare, by = c("home_team_id" = "team_id")) |>
     summarize(mean_pf = mean(pf))

andres_pf
##   mean_pf
## 1     129

The mean_pf indicates that Galarraga ad his home run frequency increased by an estimated 29% relative to a neutral environment.

sum(andres$was_hr) / (andres_pf / 100)
##   mean_pf
## 1    36.4

According to our estimates, Galarraga’s benefit from the ballparks he played in (particularly his home Coors Field) amounted to roughly 47 -36 = 11 home runs in the 1996 season.