Baseball Sabermetrics

baseball sabermetricsPreviously I made a couple of Baseball Sabermetrics videos and it was a lot of fun. In this Sabermetrics tutorial I’ll cover a few of the Sabermetrics formulas I missed.

One question I received from a few of you was which team uses Sabermetrics most effectively. You’ll find that answer in the first query below named TTRC for Teams.

I also show how to perform many Sabermetric Pitching formulas below.

If you haven’t seen my past Sabermetrics tutorials they are here:

All of the formulas below are ready for you to copy and paste directly into MySQL. 
If you like tutorials like this, tell Google

Baseball Sabermetrics : Buying the Most Cheap Runs

BEST TOTAL BASES YEAR TEAMS
Needed to calculate TTRC for teams

CREATE VIEW TTOTBYR AS # We create a view to store a query
SELECT teamID, yearID,
(SUM(H)+(SUM(2B)*2)+(SUM(3B)*3)+(SUM(HR)*4)) AS TB 
FROM Batting
GROUP BY teamID, yearID;

# Testing my total bases view
SELECT teamID, yearID, TB 
FROM TTOTBYR 
WHERE yearID = 2011
ORDER BY TB DESC;

TTRC FOR TEAMS
Calculate which team gets the highest runs with the lowest cost per run

select t.yearID,  ((t.H+t.BB)+(2.4*(t.AB+t.BB)))*(tot.TB+(3*(t.AB+t.BB)))/(9*(t.AB+t.BB))-(.9*(t.AB+t.BB)) AS TTRC,
t.teamID AS Team,
SUM(s.salary) AS Salary,
s.salary/(((t.H+t.BB)+(2.4*(t.AB+t.BB)))*(tot.TB+(3*(t.AB+t.BB)))/(9*(t.AB+t.BB))-(.9*(t.AB+t.BB))) AS CPR
FROM Salaries s, Teams t, TTOTBYR as tot
WHERE t.yearID = tot.yearID AND s.teamID = t.teamID AND t.yearID = 2010
AND s.yearID = t.yearID AND s.teamID = tot.teamID
GROUP BY t.teamID
ORDER BY CPR ASC;

Baseball Sabermetrics Pitching Formulas

DEFENSE INDEPENDENT COMPONENT ERA DICE
A way of calculating ERA independent of the performance of that teams defense - Clay Dreslough

SELECT p.playerID, CONCAT(m.nameFirst, " ", m.nameLast) AS NAME, 
yearID, teamID, 
p.IPOuts/3 AS IP,
3.00+(((13*p.HR)+(3*(p.BB+p.HBP))-2*p.SO)/(p.IPOuts/3)) AS DICE
FROM pitching p, Master m
WHERE p.playerID = m.playerID AND p.yearID = 2010 AND (p.IPOuts/3) > 30.0
ORDER BY DICE ASC
LIMIT 50;

DEFENSE INDEPENDENT COMPONENT ERA DICE TEAMS
How to calculate DICE for a whole team of pitchers

SELECT yearID, teamID, 
t.IPOuts/3 AS IP,
3.00+(((13*t.HR)+(3*(t.BB+t.HBP))-2*t.SO)/(t.IPOuts/3)) AS DICE
FROM Teams t
WHERE t.yearID = 2010
GROUP BY teamID, yearID
ORDER BY DICE ASC;

FIELDING INDEPENDENT PITCHING FIP
Tom Tango created a formula very similar to DICE

SELECT p.playerID, CONCAT(m.nameFirst, " ", m.nameLast) AS NAME, 
yearID, teamID, 
p.IPOuts/3 AS IP,
(3.10+(((13*p.HR)+(3*(p.BB))-2*p.SO)/(p.IPOuts/3))) AS FIP
FROM pitching p, Master m
WHERE p.playerID = m.playerID AND p.yearID = 2010 AND (p.IPOuts/3) > 50.0
ORDER BY FIP ASC
LIMIT 50;

FIELDING INDEPENDENT PITCHING TEAMS
FIP using a whole team of pitchers

SELECT yearID, teamID, 
t.IPOuts/3 AS IP,
(3.10+(((13*t.HR)+(3*(t.BB))-2*t.SO)/(t.IPOuts/3))) AS FIP
FROM Teams t
WHERE t.yearID = 2010
GROUP BY teamID, yearID
ORDER BY FIP ASC;

PITCHER'S TOTAL BASES PTB
Total bases given up by a pitcher

CREATE VIEW PTB AS # We create a view to store a query
SELECT p.playerID, p.teamID, p.yearID,
(.89*(1.255*(p.H-p.HR)+(4*p.HR)))+(.56*(p.BB+p.HBP-p.IBB)) AS PTOTB
FROM Pitching p;

COMPONENT ERA ERC
Tries to forecast a pitchers ERA - Bill James

SELECT p.playerID, CONCAT(m.nameFirst, " ", m.nameLast) AS NAME, 
p.yearID, p.teamID, 
p.IPOuts/3 AS IP,
(((p.H+p.BB+p.HBP)*pt.PTOTB)/(p.BFP*(p.IPOuts/3)))*(9-.56) AS ERC
# If ERC is less than 2.24 replace .56 with .75 above
FROM pitching p, Master m, PTB pt
WHERE p.playerID = m.playerID AND p.yearID = 2011 AND (p.IPOuts/3) > 50.0
AND pt.playerID = p.playerID AND pt.yearID = p.yearID
ORDER BY cERA ASC
LIMIT 50;

I hope you liked this 4 part Sabermetrics tutorial. It was a lot of fun for me to make.

Till Next Time

4 Responses to “Baseball Sabermetrics”

  1. mr.roshik says:

    i want to know details about css reset, i read some article but its not clear to me yet. Please suggest me about this issue.

    • admin says:

      All css reset does is try to make components look the same in every browser. It does a pretty good job of eliminating cross browser problems as well. Thanks for the idea. I’ll see what I can do with it.

  2. mr.roshik says:

    You are always helpful to me though i cant do anything for u, but i like u and sent u an email including some avatar 🙂 i think those are cute.

    • admin says:

      Thank you and don’t feel like you have to do anything for me. All I ever ask is that if you like my stuff click the Google + button. It helps Google to recommend my articles and videos to others. Thanks for the avatars. They are neat 🙂

Leave a Reply

Your email address will not be published.

Google+