{"id":225,"date":"2018-03-28T09:56:59","date_gmt":"2018-03-28T16:56:59","guid":{"rendered":"http:\/\/www.ootp.cavebutter.net\/blog\/?p=225"},"modified":"2018-03-28T10:32:57","modified_gmt":"2018-03-28T17:32:57","slug":"pitching-stats-2-fip","status":"publish","type":"post","link":"http:\/\/www.ootp.cavebutter.net\/blog\/archives\/225","title":{"rendered":"Pitching Stats 2: FIP &#8211; The False Start"},"content":{"rendered":"<p>FIP, or Fielding Independent Pitching, is based on the idea that pitchers are only in control of the &#8220;3 true outcomes&#8221; of a plate appearance: Strikeouts, Home Runs, and Free Passes (HBP and BB&#8217;s). \u00a0Everything else relies on defense which is largely beyond the pitcher&#8217;s control. \u00a0FIP is scaled, through the use of a constant, to a league&#8217;s ERA.<\/p>\n<p>The formula to derive FIP is:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">FIP = ((13*HR)+(3*(BB+HBP))-(2*K))\/IP + constant<\/code><\/pre>\n<p>and the formula for the deriving the constant is similar:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">FIP Constant = lgERA \u2013 (((13*lgHR)+(3*(lgBB+lgHBP))-(2*lgK))\/lgIP)<\/code><\/pre>\n<p>We&#8217;re going to make a quick table to calculate the FIPConstant for each league year that we&#8217;ll reference when calculating FIP for each player stint. \u00a0Happily, the game gives us league ERA in the league_history_pitching_stats table, so we&#8217;ve been spared a step. \u00a0Because I am, apparently, not very good with the order of operations and parentheses, I have spent the last hour pulling my hair out trying to get a FIP Constant that looks reasonable. \u00a0In an attempt to save some of my last remaining hairs, I made a very inelegant table. \u00a0Behold my genius:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-sql\">DROP TABLE IF EXISTS FIPConstant;\r\nCREATE TABLE IF NOT EXISTS FIPConstant AS\r\n\r\nSELECT\r\n    lhps_id\r\n    , year\r\n    , league_id\r\n    , level_id\r\n    , hra\r\n    , bb\r\n    , hp\r\n    , k\r\n    , @HRAdj := 13*hra AS Adjusted_HR\r\n    , @BBAdj := 3*bb AS Adjusted_BB\r\n    , @HPAdj := 3*hp AS Adjusted_HP\r\n    , @KAdj  := 2*k AS Adjusted_K\r\n    , @InnPitch := ((ip*3)+ipf)\/3 AS InnPitch\r\n    , era\r\n    , era - ((@HRAdj+@BBAdj+@HPAdj-@KAdj)\/@InnPitch) AS FIPConstant\r\nFROM league_history_pitching_stats;<\/code><\/pre>\n<p>On the CalcPitching table, we&#8217;re adding FIP and disregarding left\/right splits for the moment. \u00a0Our table script now looks like this:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-sql\">DROP TABLE IF EXISTS CalcPitching;\r\nCREATE TABLE IF NOT EXISTS CalcPitching AS\r\n\r\nSELECT\r\n    i.player_id\r\n    , i.year\r\n    , i.stint\r\n    , i.team_id\r\n    , i.league_id\r\n    , split_id\r\n    , i.ip\r\n    , i.ab\r\n    , i.tb\r\n    , i.ha\r\n    , i.k\r\n    , i.bf\r\n    , i.rs\r\n    , i.bb\r\n    , i.r\r\n    , i.er\r\n    , i.gb\r\n    , i.fb\r\n    , i.pi\r\n    , i.ipf\r\n    , i.g\r\n    , i.gs\r\n    , i.w\r\n    , i.l\r\n    , i.s\r\n    , i.sa\r\n    , i.da\r\n    , i.sh\r\n    , i.sf\r\n    , i.ta\r\n    , i.hra\r\n    , i.bk\r\n    , i.ci\r\n    , i.iw\r\n    , i.wp\r\n    , i.hp\r\n    , i.gf\r\n    , i.dp\r\n    , i.qs\r\n    , i.svo\r\n    , i.bs\r\n    , i.ra\r\n    , i.cg\r\n    , i.sho\r\n    , i.sb\r\n    , i.cs\r\n    , i.hld\r\n    , i.ir\r\n    , i.irs\r\n    , i.wpa\r\n    , i.li\r\n    , i.outs\r\n    , i.war\r\n    , @InnPitch := ((3*ip)+ipf)\/3 AS InnPitch\r\n    , round((9*i.k)\/@InnPitch,1) AS 'k9'\r\n    , round((9*i.bb)\/@InnPitch,1) AS 'bb9'\r\n    , round((9*i.hra)\/@InnPitch,1) AS 'HR9'\r\n    , round((i.bb+i.ha)\/@InnPitch,2) AS WHIP\r\n    , round(i.k\/i.bb,2) AS 'K\/BB'\r\n    , i.gb\/i.fb AS 'gb\/fb'\r\n    , round((i.ha-i.hra)\/(i.ab-i.k-i.hra-i.sh+i.sf),3) AS BABIP\r\n    , round(i.er\/@InnPitch,2) AS ERA\r\n    , round(((13*i.hra)+(3*(i.bb+i.hp))-(2*i.k))\/@InnPitch+f.FIPConstant,2) AS fip\r\n    \r\n    \r\nFROM players_career_pitching_stats AS i\r\n    INNER JOIN FIPConstant AS f ON i.year=f.year AND i.league_id=f.league_id\r\nWHERE i.split_id=1;<\/code><\/pre>\n<p>So, how did it go? \u00a0Not great. \u00a0I took a random sample from my database and compared it to the game&#8217;s generated stats. \u00a0I wanted my FIP calculations to be within .05 of the game&#8217;s.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.ootp.cavebutter.net\/blog\/wp-content\/uploads\/2018\/03\/FIP-v1.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"237\" data-permalink=\"http:\/\/www.ootp.cavebutter.net\/blog\/archives\/225\/fip-v1\" data-orig-file=\"https:\/\/i0.wp.com\/www.ootp.cavebutter.net\/blog\/wp-content\/uploads\/2018\/03\/FIP-v1.jpg?fit=490%2C565\" data-orig-size=\"490,565\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"FIP v1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.ootp.cavebutter.net\/blog\/wp-content\/uploads\/2018\/03\/FIP-v1.jpg?fit=490%2C565\" class=\"aligncenter size-full wp-image-237\" src=\"https:\/\/i0.wp.com\/www.ootp.cavebutter.net\/blog\/wp-content\/uploads\/2018\/03\/FIP-v1.jpg?resize=490%2C565\" alt=\"\" width=\"490\" height=\"565\" srcset=\"https:\/\/i0.wp.com\/www.ootp.cavebutter.net\/blog\/wp-content\/uploads\/2018\/03\/FIP-v1.jpg?w=490 490w, https:\/\/i0.wp.com\/www.ootp.cavebutter.net\/blog\/wp-content\/uploads\/2018\/03\/FIP-v1.jpg?resize=260%2C300 260w\" sizes=\"auto, (max-width: 490px) 100vw, 490px\" \/><\/a>While most were in the medium range, it seems that there&#8217;s something different in the way the game calculates FIP. \u00a0Our numbers are close enough that it can&#8217;t be a major difference. \u00a0I&#8217;m going to follow a hunch and guess that it&#8217;s Hit By Pitch. \u00a0I will remove HBP as a factor in both the FIPConstant and FIP calculations and see what that does to our results.<\/p>\n<p>I got about a third of the way through the revised calcs when I noticed a problem with the FIPConstant table. \u00a0This table pulls data from the league_history_pitching_stats table. \u00a0The problem is there. \u00a0You see, as I mentioned in the table setup posts and then promptly forgot about, there are a couple of columns in the league_history tables that attempt to distinguish between subleagues but do not give any indication of which is which. (They are the team_id and game_id columns.) \u00a0What this does create two records for each league (one for each subleague) with different totals but no way to identify the subleague being referenced. \u00a0This is no good.<\/p>\n<p>My new hunch is that HBP is not the issue. \u00a0The formula is probably fine, I will just have to change the FIPConstant table to sum data from players_career_pitching_stats. \u00a0I&#8217;m going to publish this post as a testament to my naivet\u00e9 and get to work on the revised table.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>FIP, or Fielding Independent Pitching, is based on the idea that pitchers are only in control of the &#8220;3 true outcomes&#8221; of a plate appearance: Strikeouts, Home Runs, and Free Passes (HBP and BB&#8217;s). \u00a0Everything else relies on defense which is largely beyond the pitcher&#8217;s control. \u00a0FIP is scaled, through the use of a constant,&hellip; <a class=\"more-link\" href=\"http:\/\/www.ootp.cavebutter.net\/blog\/archives\/225\">Continue reading <span class=\"screen-reader-text\">Pitching Stats 2: FIP &#8211; The False Start<\/span> <span class=\"meta-nav\" aria-hidden=\"true\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[7,4,15,6,13],"class_list":["post-225","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-mysql","tag-ootp","tag-pitching","tag-tables","tag-unresolved-issue"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9cxb5-3D","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts\/225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/comments?post=225"}],"version-history":[{"count":7,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts\/225\/revisions"}],"predecessor-version":[{"id":240,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts\/225\/revisions\/240"}],"wp:attachment":[{"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/media?parent=225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/categories?post=225"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/tags?post=225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}