A Perl version of Tango’s Markov ModelSeptember 28, 2010
Posted by Sobchak in Markov models,Perl
This is just a basic adaptation – I have not added any new features, though I hope to in the future (at the very least I would like to make a Perl version of Bill Skelton’s modification of Tango’s original).
To use my version, first download the zip file (markov.zip), extract the Perl script (markov.pl) and the example input file (input.csv), and place them in the same directory. Change the values in the input.csv file to alter the batting line and the chances of taking an extra base (but make sure not to alter the formatting of the file). Then just run the Perl script, which will produce a file named output.txt that is tab-delimited. If you open that in Excel you should be able to view all the results in table form. For simplicity’s sake I didn’t include any command line arguments to specify the names of the input or output files, so if you want to run the script multiple times and save your results you’ll either have to rename/copy the output file or alter the Perl script (note that the output file does include the input values inside it).
For those unfamiliar with Markov models of baseball, there are a lot of great resources on the web. Outside of Tango’s site, I recommend work by Mark Pankin, Joel Sokol (includes Matlab code), Bruce Bukiet (scroll down for “A Markov Chain Approach to Baseball”), Carl Morris, John Beamer (includes Excel spreadsheet with purchase), Tom Ruane, and Berselius (includes Matlab code, though link appears to be down).