The sabermetrician Bill James introduced the concept of Pythagorean Expectation to approximate baseball teams’ winning percentages. he found that if you took the square of the number of runs scored (RS) and divided by the sum of the squares of runs scored (RS) and runs allowed (RA), you get a pretty good estimate of a team’s actual win probability. James’ formula is: \[ \text{Win %} \approx \frac{\text{RS}^2}{\text{RS}^2 + \text{RA}^2} \] In this exercise, we will assess this formula using data from the 2016 Major League Baseball Season, which is tabulated below.
Be sure to save all of your code in an R script, which you can call ‘’ps1.R’’.
c()
function, create vectors called teams
, wins
, losses
, rs
and ra
that contain the tean names, number of wins, number of losses, number of runs scored, and number of runs allowed.wins
, losses
, rs
, and ra
according to the team.wp.actual
containing the actual win percentages.wp.pythag
containing the Pythagorean expectations. Which team has the smallest Pythagorean expectation? Is that the team with the smallest actual win percentage?wp.resid
containing the difference between each team’s actual winning percentage and the Pythagorean expectation. These differences are known as residuals. If a team has a positive residual, that means that their actual win percentage exceeded what Pythagorean expectation predicted. Which team most outperformed their expected win percentage?
TEAM | W | L | RS | RA |
---|---|---|---|---|
Chicago Cubs | 103 | 58 | 808 | 556 |
Texas Rangers | 95 | 67 | 765 | 757 |
Washington Nationals | 95 | 67 | 763 | 612 |
Cleveland Indians | 94 | 67 | 777 | 676 |
Boston Red Sox | 93 | 69 | 878 | 694 |
Los Angeles Dodgers | 91 | 71 | 725 | 638 |
Baltimore Orioles | 89 | 73 | 744 | 715 |
Toronto Blue Jays | 89 | 73 | 759 | 666 |
New York Mets | 87 | 75 | 671 | 617 |
San Francisco Giants | 87 | 75 | 715 | 631 |
Detroit Tigers | 86 | 75 | 750 | 721 |
St. Louis Cardinals | 86 | 76 | 779 | 712 |
Seattle Mariners | 86 | 76 | 768 | 707 |
New York Yankees | 84 | 78 | 680 | 702 |
Houston Astros | 84 | 78 | 724 | 701 |
Kansas City Royals | 81 | 81 | 675 | 712 |
Miami Marlins | 79 | 82 | 655 | 682 |
Pittsburgh Pirates | 78 | 83 | 729 | 758 |
Chicago White Sox | 78 | 84 | 686 | 715 |
Colorado Rockies | 75 | 87 | 845 | 860 |
Los Angeles Angels | 74 | 88 | 717 | 727 |
Milwaukee Brewers | 73 | 89 | 671 | 733 |
Philadelphia Phillies | 71 | 91 | 610 | 796 |
Arizona Diamondbacks | 69 | 93 | 752 | 890 |
Oakland Athletics | 69 | 93 | 653 | 761 |
Atlanta Braves | 68 | 93 | 649 | 779 |
Tampa Bay Rays | 68 | 94 | 672 | 713 |
San Diego Padres | 68 | 94 | 686 | 770 |
Cincinnati Reds | 68 | 94 | 716 | 854 |
Minnesota Twins | 59 | 103 | 722 | 889 |