{"id":247,"date":"2018-03-28T12:36:16","date_gmt":"2018-03-28T19:36:16","guid":{"rendered":"http:\/\/www.ootp.cavebutter.net\/blog\/?p=247"},"modified":"2018-03-28T12:36:16","modified_gmt":"2018-03-28T19:36:16","slug":"pitching-stats-4-xfip","status":"publish","type":"post","link":"http:\/\/www.ootp.cavebutter.net\/blog\/archives\/247","title":{"rendered":"Pitching Stats 4: xFIP"},"content":{"rendered":"<p>xFIP is almost the same thing as FIP, just with something &#8216;xtra&#8217;. \u00a0The idea is that while pitchers are responsible for the 3 True Outcomes (HR, BB\/HP, and K), home runs can also be subject to luck. \u00a0For example, a fence-scraper over the short right porch in Fenway might not be a home run through the marine layer at Dodger Stadium. \u00a0What does this tell us about the pitcher&#8217;s expected performance?<\/p>\n<p>Well, to account for the vagaries of chance, xFIP takes all of a pitchers fly balls and multiplies them by the league average HR\/FB rate. \u00a0Basically, it assumes a number of HR a pitcher\u00a0<em>would have given up<\/em> based on the number of fly balls their opponents hit rather than the number of HR they\u00a0<em>actually did give up.<\/em><\/p>\n<p>It feels like splitting hairs to me, but hey. \u00a0That&#8217;s baseball. \u00a0The formula for xFIP is just like FIP with that one change:<br \/>\n<code>xFIP = ((13*(Fly balls * lgHR\/FB%))+(3*(BB+HBP))-(2*K))\/IP + constant<\/code><\/p>\n<p>The constant is the same FIPConstant we calculated for FIP. \u00a0So, this one is pretty straight-forward, except that we need the HR\/FB% for the league. \u00a0We&#8217;ll go back to our FIPConstant table and add it there for each league year. \u00a0Our FIPConstant table now looks like this:<\/p>\n<pre class=\"line-numbers\" data-line=\"7\"><code class=\"language-sql\">DROP TABLE IF EXISTS FIPConstant;\r\nCREATE TABLE IF NOT EXISTS FIPConstant AS\r\n\r\nSELECT\r\n      year\r\n    , league_id\r\n    , hra_totals\/fb_totals AS hr_fb_pct\r\n    , @HRAdj := 13*hra_totals AS Adjusted_HR\r\n    , @BBAdj := 3*bb_totals AS Adjusted_BB\r\n    , @HPAdj := 3*hp_totals AS Adjusted_HP\r\n    , @KAdj  := 2*k_totals AS Adjusted_K\r\n    , @InnPitch := ((ip_totals*3)+ipf_totals)\/3 AS InnPitch\r\n    , @lgERA := round((er_totals\/@InnPitch)*9,2) AS lgERA\r\n    , round(@lgERA - ((@HRAdj+@BBAdj+@HPAdj-@KAdj)\/@InnPitch),2) AS FIPConstant\r\nFROM (\r\n         SELECT year\r\n                , league_id\r\n                , sum(hra) as hra_totals\r\n                , sum(bb) as bb_totals\r\n                , sum(hp) as hp_totals\r\n                , sum(k) as k_totals\r\n                , sum(er) as er_totals\r\n                , sum(ip) as ip_totals\r\n                , sum(ipf) as ipf_totals\r\n                , sum(fb) as fb_totals\r\n          FROM players_career_pitching_stats\r\n          GROUP BY year, league_id\r\n      ) AS x;<\/code><\/pre>\n<p>I added the formula above to the CalcPitching table and we&#8217;re done. \u00a0OOTP doesn&#8217;t track xFIP (at least in v18), so there&#8217;s nothing to compare it to. \u00a0This one&#8217;s done.<\/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)*9,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    , round(((13*(i.fb*f.hr_fb_pct))+(3*(i.bb+i.hp))-(2*i.k))\/@InnPitch+f.FIPConstant,2) AS xFIP\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 AND i.league_id&lt;&gt;0;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>xFIP is almost the same thing as FIP, just with something &#8216;xtra&#8217;. \u00a0The idea is that while pitchers are responsible for the 3 True Outcomes (HR, BB\/HP, and K), home runs can also be subject to luck. \u00a0For example, a fence-scraper over the short right porch in Fenway might not be a home run through&hellip; <a class=\"more-link\" href=\"http:\/\/www.ootp.cavebutter.net\/blog\/archives\/247\">Continue reading <span class=\"screen-reader-text\">Pitching Stats 4: xFIP<\/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":[29],"tags":[7,4,15],"class_list":["post-247","post","type-post","status-publish","format-standard","hentry","category-pitching","tag-mysql","tag-ootp","tag-pitching"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9cxb5-3Z","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts\/247","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=247"}],"version-history":[{"count":2,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts\/247\/revisions"}],"predecessor-version":[{"id":249,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts\/247\/revisions\/249"}],"wp:attachment":[{"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/media?parent=247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/categories?post=247"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/tags?post=247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}