Here are some explanations of what wOBA is
I aggregated this at the TEAM level rather than at the player level. Please correct us if you have any concerns about doing this at the team level.
Note: Credit where credit is due. Pulled this query down from Matt Dennewitz's github
Modified it slightly to group it by year/team/Home&Road/1st&2nd half of the season
This assumes you have loaded/imported the event files from retrosheet into your own database (ie, MySQL).
Feel free to use this
-----------------------
# Replace these parameters with what you want to use.
SET @fromYear = '2004';
SET @thruYear = '2019';
SET @startInning = 7; # Start from the 7th inning
SET @secondHalfStartMonth = 7; # July
select
s.Team,
s.ind,
round((
(
(.689 * s.bb)
+ (.722 * s.hbp)
+ (.892 * s._1b)
+ (1.283 * s._2b)
+ (1.635 * s._3b)
+ (2.135 * s.hr)
) / (s.ab + s.bb + s.sf + s.hbp)
), 3) * 1000 as woba
from (
select
case
when e.home_team_id = 'FLO' then 'MIA'
when e.home_team_id = 'MON' then 'WAS'
else e.home_team_id
end
as Team
,'H1' as ind
, sum(case when (pa_new_fl = 'T' and pa_trunc_fl = 'F') then 1 else 0 end) as pa
, sum(case when ab_fl = 'T' then 1 else 0 end) ab
, sum(case when event_cd = '14' then 1 else 0 end) as bb
, sum(case when event_cd = '15' then 1 else 0 end) as ibb
, sum(case when event_cd = '16' then 1 else 0 end) as hbp
, sum(case when event_cd = '20' then 1 else 0 end) as _1b
, sum(case when event_cd = '21' then 1 else 0 end) as _2b
, sum(case when event_cd = '22' then 1 else 0 end) as _3b
, sum(case when event_cd = '23' then 1 else 0 end) as hr
, sum(case when sf_fl = 'T' then 1 else 0 end) as sf
, sum(case when bat_safe_err_fl = 'T' then 1 else 0 end) as rboe
from
events e
, games g
where
e.game_id = g.game_id
and e.inn_ct >= @startInning
and e.year_id >= @fromYear and e.year_id <= @thruYear
and EXTRACT(MONTH FROM g.game_dt) < @secondHalfStartMonth
and e.BAT_HOME_ID = 1
group by
Team, 2
) s
union
select
s.Team,
s.ind,
round((
(
(.689 * s.bb)
+ (.722 * s.hbp)
+ (.892 * s._1b)
+ (1.283 * s._2b)
+ (1.635 * s._3b)
+ (2.135 * s.hr)
) / (s.ab + s.bb + s.sf + s.hbp)
), 3) * 1000 as woba
from (
select
case
when e.away_team_id = 'FLO' then 'MIA'
when e.away_team_id = 'MON' then 'WAS'
else e.away_team_id
end
as Team
, 'R1' as ind
, sum(case when (pa_new_fl = 'T' and pa_trunc_fl = 'F') then 1 else 0 end) as pa
, sum(case when ab_fl = 'T' then 1 else 0 end) ab
, sum(case when event_cd = '14' then 1 else 0 end) as bb
, sum(case when event_cd = '15' then 1 else 0 end) as ibb
, sum(case when event_cd = '16' then 1 else 0 end) as hbp
, sum(case when event_cd = '20' then 1 else 0 end) as _1b
, sum(case when event_cd = '21' then 1 else 0 end) as _2b
, sum(case when event_cd = '22' then 1 else 0 end) as _3b
, sum(case when event_cd = '23' then 1 else 0 end) as hr
, sum(case when sf_fl = 'T' then 1 else 0 end) as sf
, sum(case when bat_safe_err_fl = 'T' then 1 else 0 end) as rboe
from
events e
, games g
where
e.game_id = g.game_id
and e.inn_ct >= @startInning
and e.year_id >= @fromYear and e.year_id <= @thruYear
and EXTRACT(MONTH FROM g.game_dt) < @secondHalfStartMonth
and e.BAT_HOME_ID = 0
group by
Team, 2
) s
#
# 2nd half of the season
#
union
select
s.Team,
s.ind,
round((
(
(.689 * s.bb)
+ (.722 * s.hbp)
+ (.892 * s._1b)
+ (1.283 * s._2b)
+ (1.635 * s._3b)
+ (2.135 * s.hr)
) / (s.ab + s.bb + s.sf + s.hbp)
), 3) * 1000 as woba
from (
select
case
when e.home_team_id = 'FLO' then 'MIA'
when e.home_team_id = 'MON' then 'WAS'
else e.home_team_id
end
as Team
,'H2' as ind
, sum(case when (pa_new_fl = 'T' and pa_trunc_fl = 'F') then 1 else 0 end) as pa
, sum(case when ab_fl = 'T' then 1 else 0 end) ab
, sum(case when event_cd = '14' then 1 else 0 end) as bb
, sum(case when event_cd = '15' then 1 else 0 end) as ibb
, sum(case when event_cd = '16' then 1 else 0 end) as hbp
, sum(case when event_cd = '20' then 1 else 0 end) as _1b
, sum(case when event_cd = '21' then 1 else 0 end) as _2b
, sum(case when event_cd = '22' then 1 else 0 end) as _3b
, sum(case when event_cd = '23' then 1 else 0 end) as hr
, sum(case when sf_fl = 'T' then 1 else 0 end) as sf
, sum(case when bat_safe_err_fl = 'T' then 1 else 0 end) as rboe
from
events e
, games g
where
e.game_id = g.game_id
and e.inn_ct >= @startInning
and e.year_id >= @fromYear and e.year_id <= @thruYear
and EXTRACT(MONTH FROM g.game_dt) >= @secondHalfStartMonth
and e.BAT_HOME_ID = 1
group by
Team, 2
) s
union
select
s.Team,
s.ind,
round((
(
(.689 * s.bb)
+ (.722 * s.hbp)
+ (.892 * s._1b)
+ (1.283 * s._2b)
+ (1.635 * s._3b)
+ (2.135 * s.hr)
) / (s.ab + s.bb + s.sf + s.hbp)
), 3) * 1000 as woba
from (
select
case
when e.away_team_id = 'FLO' then 'MIA'
when e.away_team_id = 'MON' then 'WAS'
else e.away_team_id
end
as Team
, 'R2' as ind
, sum(case when (pa_new_fl = 'T' and pa_trunc_fl = 'F') then 1 else 0 end) as pa
, sum(case when ab_fl = 'T' then 1 else 0 end) ab
, sum(case when event_cd = '14' then 1 else 0 end) as bb
, sum(case when event_cd = '15' then 1 else 0 end) as ibb
, sum(case when event_cd = '16' then 1 else 0 end) as hbp
, sum(case when event_cd = '20' then 1 else 0 end) as _1b
, sum(case when event_cd = '21' then 1 else 0 end) as _2b
, sum(case when event_cd = '22' then 1 else 0 end) as _3b
, sum(case when event_cd = '23' then 1 else 0 end) as hr
, sum(case when sf_fl = 'T' then 1 else 0 end) as sf
, sum(case when bat_safe_err_fl = 'T' then 1 else 0 end) as rboe
from
events e
, games g
where
e.game_id = g.game_id
and e.inn_ct >= @startInning
and e.year_id >= @fromYear and e.year_id <= @thruYear
and EXTRACT(MONTH FROM g.game_dt) >= @secondHalfStartMonth
and e.BAT_HOME_ID = 0
group by
Team, 2
) s
where
s.ab > 0
order by
1, 2
;
You can use a tool like MySQL workbench to run it. Then you can export it into a spreadsheet and graph it with Python and/or R or your favorite analysis language.
Comentarios