Home Page Icon
Home Page
Table of Contents for
6. Sabermetric Thinking
Close
6. Sabermetric Thinking
by Joseph Adler
Baseball Hacks
Baseball Hacks
A Note Regarding Supplemental Files
Credits
About the Author
Contributors
Acknowledgments
Preface
Why Baseball Hacks?
How to Use This Book
How This Book Is Organized
Conventions Used in This Book
Using Code Examples
How to Contact Us
Got a Hack?
Safari® Enabled
1. Basics of Baseball
Hacks 1–7: Introduction
Baseball 101
Score a Baseball Game
Traditional Scoring
Record starting players’ names.
Record plays during the game.
Record substitutions.
Record other information.
Hacking the Hack
See Also
Make a Box Score from a Score Sheet
The Official Rules for Scoring
Calculating a Box Score from a Score Sheet
Step 1: Draw columns for names, at bats, runs, hits, and anything else.
Step 2: Copy the batters’ names.
Step 3: Count statistics for each batter.
Step 4: Count statistics for each pitcher.
Step 5: Prove the box score.
Hacking the Hack
Keep Score, Project Scoresheet–Style
The Contents of a Play Code
Play code structure.
Fielding.
Type of play.
Description.
Base running.
Example play codes.
Pitch codes.
Follow Pitches During a Game
Following the Pitching Strategy
Set up a pitch outside.
Follow breaking balls with a fastball.
Follow fastballs with a breaking ball.
Always throw the same impossible-to-hit pitch.
Move the player off the plate.
Identifying Pitches
Step 1: Watch the umpire for location.
Step 2: Watch the catcher for location.
Step 3: Look at pitch speeds to determine pitch type.
Step 4: Watch what the ball does at the plate.
Step 5: Watch the pitcher react to the catcher’s signals.
Step 6: Watch the catcher’s signals.
Follow the Game Online
Player Statistics
Independent Commentary (Including Blogs)
Hacking the Hack
Add Baseball Searches to Firefox
Adding Search Engines to Firefox
Running the Hack
Hacking the Hack
Find Images of Stadiums
Better Pictures and Distances with Google Earth
2. Baseball Games from Past Years
Hacks 8–23: Introduction
Get and Install MySQL
Installation on Windows
Step 0: Buy and install a software or hardware firewall.
Step 1: Download and unpack the installer.
Step 2: Run the Installation wizard.
Step 3: Run the Configuration wizard.
Testing the Installation
Hacking the Hack
See Also
Get an Access Database of Player and Team Statistics
A Player and Team Statistics Database for Microsoft Access
Step 1: Download the file.
Step 2: Decompress and save the file.
Step 3: Open the database file.
Step 4: Test the database.
The Contents of the Database
Get a MySQL Database of Player and Team Statistics
Step 1: Download the File
Step 2: Decompress the File
Step 3: Create the Database
Step 4: Import the Database
Step 5: Check That Everything Is There
The Contents of the Database
Hacking the Hack
Annual updates.
Getting baseball statistics as text files.
Make Your Own Stats Book
Write the Queries
Step 1: Create “batters who played in 2004” query.
Step 2: Create “fielding by games” query.
Step 3: Create “fielding by most frequent position” query.
Step 4: Create “team names” query.
Step 5: Create “batting plus” query.
Build the Report
Hacking the Hack
Get Perl
Getting and Installing Perl
Install the Perl Modules Required in This Book
Hacking the Hack
Step 1: Download the Cygwin installer.
Step 2: Run the Cygwin installer.
Step 3: Configure Cygwin.
Learn Perl
The Basics
Statements.
Variables.
Datatypes.
Control structures.
Comments.
An Example Program
Some Not-so-Basic Basics
Pattern matching through regular expressions.
Subroutines.
Modules and packages.
Editors
Hacking the Hack
Get Historical Play-by-Play Data
Retrosheet Event Files
The Code
Running the Hack
See Also
Make Box Scores or Database Tables from Play-by-Play Data with Retrosheet Tools
Running the Tools
Preprocessing event files with BEVENT.
Chadwick
See Also
Use SQL to Explore Game Data
Talking to Your Database
Tables
Queries
Joins.
Aggregates.
Subqueries.
Saving results in tables.
Deleting tables.
Running Scripts
Getting More Information and Help
Use Microsoft Access to Run SQL Queries
SQL Queries in Access
Changing SQL Queries to Graphical Queries
Subqueries in Access
Get a GUI for MySQL
Other Tools
MySQL Administrator.
Tora and Toad.
Aqua Data Studio.
Move Data from a Database to Excel
Select the Right Data for a Spreadsheet
Running the Hack
Moving data from Access to Excel.
Moving data from MySQL Query Browser to Excel.
Moving data from MySQL to Excel.
Hacking the Hack
Load Baseball Data into MySQL
The Code
Running the Hack
Hacking the Hack
See Also
Load Retrosheet Game Logs
The Code
Make a Historical Play-by-Play Database
The Code
Fetching the data.
Transforming the data.
Creating a database import statement.
Creating a play-by-play database and tables.
Use Regular Expressions to Identify Events
Hacking the Hack
See Also
3. Stats from the Current Season
Hacks 24–29: Introduction
Use Microsoft Excel Web Queries to Get Stats
Web Queries
Web Query Example: Up-to-Date Park Factors
Step 1: Find the data.
Step 2: Running the queries.
Step 3: Name stuff.
Step 4: Create a results table.
Hacking the Hack
Spider Baseball Sites for Data
The Code
Running the Hack
Hacking the Hack
See Also
Discover How Live Score Applications Work
Use Your Router’s Content Filtering Feature
Use a Proxy Server
Packet Filters
Keep Your Stats Database Up-to-Date
The Code
Create the box score database.
The update script.
The bootstrapping script.
The helping code.
Running the Hack
Hacking the Hack
Get Recent Play-by-Play Data
The Code
The spider script.
The parser script.
Running the Hack
Hacking the Hack
See Also
Find Data on Hit Locations
The Code
Running the Hack
Hacking the Hack
4. Visualize Baseball Statistics
Hacks 30–39: Introduction
Plot Histograms in Excel
The Code
Hacking the Hack
Get R and R Packages
Analyze Baseball with R
Calculations in R
Assignment in R
Arrays
Data Frames
Comments
Functions
Graphics in R
Hacking the Hack
See Also
Access Databases Directly from Excel or R
Use ODBC in R
Use ODBC in Excel
Hacking the Hack
Load Text Files into R
The Code
See Also
Compare Teams and Players with Lattices
The Code
Running the Hack
Compare Teams Using Chernoff Faces
The Code
Run the Hack
Hacking the Hack
Plot Spray Charts
Step 1: Load the file into a data frame.
Step 1: Load the file into a data frame.
Step 2: Set up the axes and the diamond.
Step 3: Plot matchups.
Batter Spray Diagrams
Hexagonal Binning
Step 1: Get the hexbin package.
Step 2: Load the hexbin package.
Step 3: Plot the graph.
Hacking the Hack
Chart Team Stats in Real Time
The Code
Running the Hack
Hacking the Hack
Create a batch file to plow through several teams.
Still more automation.
Don’t export individual PNG images.
Slice and Dice Teams with Cubes
Prerequisites
The Code
Step 1: Define local cube contents.
Step 2: Create the local cube.
Step 3: Create a local web application to interact with the cube.
Running the Hack
Hacking the Hack
5. Formulas
Hacks 40–59: Introduction
How I Chose the Formulas
Summary Statistics for the Formulas
Using Formulas for Fantasy Baseball
Who Came Up with These Things?
Measure Batting with Batting Average
Sample Code
Batting average formula.
Running the Hack
Summary statistics.
Top 10.
Distribution.
Box plot.
Measure Batting with SLG
The Formula
Sample Code
Running the Hack
Summary statistics.
Top 10.
Distribution and box plot.
Measure Batting with OPS
Running the Hack
Summary statistics.
Top 10.
Distribution and box plot.
Measure Power with ISO
Sample Code
Summary statistics.
Top 10.
Distribution and box plot.
Measure Batting with Runs Created
The Formula
Sample Code
Summary statistics.
Top 10.
Histogram and box plot.
Measure Pitching with ERA
The Code
Running the Hack
Summary statistics.
Top 10.
Distribution and box plot.
Measure Pitching with WHIP
Running the Hack
Summary statistics.
Top 10.
Distribution and box plot.
Measure Pitching with Linear Weights
Sample Code
Running the Hack
Summary statistics.
Top 10.
Distribution and box plot.
Measure Defense with Defensive Efficiency
The Formula
Sample Code
Summary statistics.
Distribution in last 10 years (1994–2003).
Distribution and box plot.
Measure Pitching with DIPS
The Formula
Sample Code
Last year (2003).
Last 10 years (1994–2003).
Last 50 years (1955–2003).
Lucky and Unlucky Players
Measure Base Running Through EqBR
Equivalent Batter Runs
The Code
Summary statistics.
Top 10.
Histogram.
Hacking the Hack
Measure Fielding with Fielding Percentage
The Formula
Sample Code
Measure Fielding with Linear Weights
The Formula
Calculating Fielding Runs
Step 1: Calculate league totals.
Step 2: Calculate team totals.
Step 3: Calculate expected values for each player.
Step 4: Calculate fielding runs for each player.
Sample Code
Summary statistics.
Descriptive statistics.
Top 10.
Distribution and box plot.
See Also
Measure Park Effects
Approaches
Requirements for a good park factor.
Methodology
Sample Code
Using Park Factors
Park factors for run-based measurements.
Park factors for other statistics.
Hacking the Hack
Enhancements.
Compare individual offensive stats (singles, doubles, triples, home runs, etc.).
Fancy statistical approaches.
See Also
Calculate Fan Save Value
Saves
Saves are subjective.
Fan Save Value
How does a fan save value compare to the standard save value?
Sample Code
Using the Fan Save Value Formula
Calculate Save Value
The Formula
Using the Save Value
Sample Code
Using the Save Value Formula
6. Sabermetric Thinking
Hacks 60–71: Introduction
Thinking About Baseball
Calculate Expected Runs
The Code
Running the Hack
Hacking the Hack
What actually happened when teams bunted?
Is bunting ever a good strategy?
See Also
Calculate an Expected Hits Matrix
The Code
Running the Hack
Hacking the Hack
Strikeouts and the count.
Extra base hits and the count.
Balls in play and the count.
Look for Evidence of Platoon Effects
Average Platoon Effects
Switch Hitters
Hacking the Hack
Significant Number of At Bats
Find the Distribution of At Bats
Statistical Significance
OBP, AVG, and accuracy.
Testing the hypothesis.
Find “Clutch” Players
Identify Clutch Players
Measure Player Performance in Clutch Situations
Compare Players
Understanding the Results
The Code
Top players in clutch situations.
Significant clutch performances.
Calculate Expected Number of Wins
The Pythagorean Wins Formula
The code.
The Pythagenport Formula
The Back-of-the-Envelope Method
Measure Hits by Pitch Count
The Code
Running the Hack
Hacking the Hack
OBP, SLG, and Scoring Runs
The Data and the Code
The Results
Measure Skill Versus Luck
The Code
Odds of the Best Team Winning the World Series
Top 10 Bargain Outfielders
The Code
Prerequisites.
Define SQL query for getting raw data.
Import data into R.
Running the Hack
Identify common attributes.
Look at correlations.
Identify possible explanations for correlations.
Assign attribute scores.
Group players based on similarity.
Attach group membership to data set.
Transform salary variable.
Create linear regression model.
Compare predicted versus actual salaries.
Identify most-underpaid players.
Identify most-overpaid players.
Hacking the Hack
Vary the numbers of factors and/or number of clusters.
Look at different positions.
Look at different years.
Include more variables.
Fitting Game Scores to a Strength Model
The Data and the Code
Strength of Schedule
Conclusion
7. The Bullpen
Hacks 72–75: Introduction
Start or Join a Fantasy League
The Basics
Methods of ranking teams.
Methods of picking teams.
Find or form a fantasy league.
See Also
Draft Your Fantasy Team
The Basics
Pick a closer.
Pick an RBI man.
Focus on AVG, not OBP.
Draft Tips from an Expert
Be patient with your money.
Perform the “mustard toss”.
Find a bargain.
Target your favorites.
Know thine enemy.
Make a Scoreboard Widget
The Code
Running the Hack
Hacking the Hack
See Also
Analyze Other Sports
Possessions
Clock Strategy
See Also
A. Where to Learn More Stuff
Baseball Books
Baseball Web Sites
Statistics and Data Mining Books
Databases and Computer Languages
B. Abbreviations
Index
About the Author
Colophon
Copyright
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Calculate Holds and Decent Holds for Relief Pitchers
Next
Next Chapter
Hacks 60–71: Introduction
Chapter 6. Sabermetric Thinking
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset