{"id":208,"date":"2018-03-16T15:20:03","date_gmt":"2018-03-16T22:20:03","guid":{"rendered":"http:\/\/www.ootp.cavebutter.net\/blog\/?p=208"},"modified":"2018-03-16T15:20:03","modified_gmt":"2018-03-16T22:20:03","slug":"batting-stats-10-wrc","status":"publish","type":"post","link":"http:\/\/www.ootp.cavebutter.net\/blog\/archives\/208","title":{"rendered":"Batting Stats 10: wRC+"},"content":{"rendered":"<p>I will be writing this as I work through it, so this may be a little disjointed and have some false starts, but what the heck.<\/p>\n<p><a href=\"https:\/\/www.fangraphs.com\/library\/offense\/wrc\/\">wRC+<\/a> is similar to wRC and wRAA in that it measures runs created by a batter in a particular league-year context. \u00a0The most significant differences are that wRC+ is a rate statistic rather than a counting stat- scaling to a 100 scale for easy interpretation. \u00a0The second biggest difference is that this stat is league and park adjusted. \u00a0This allows us to compare players across years and leagues.<\/p>\n<p>The park and league adjustments present some challenges, though. \u00a0First, I was warned not to use the park factors from the park tables. \u00a0This is a huge bummer because it would have saved me a ton of difficult work. \u00a0In fact, I am going to try using the park factors from that table as a starting point, just to be sure it won&#8217;t work. \u00a0I am really not looking forward to doing those calcs myself.<\/p>\n<p>The league adjustments won&#8217;t be as big of an issue. I can use the team_affiliations table to determine subleague (i.e. AL vs NL) for each player &#8211; or I can ignore it altogether. \u00a0I am thinking of disregarding subleagues because I haven&#8217;t noticed much difference between my leagues in game play. \u00a0I never use the DH, so offense isn&#8217;t skewed by that. \u00a0I will try it and see how easy it is.<\/p>\n<p>The formula, per Fangraphs, is:<br \/>\n<code>((wRAA\/PA + League Runs Per PA) + (League Runs Per PA - (Park Factor*League Runs Per PA) \/ (Subleague wRC\/PA)) ALL x 100\u00a0<\/code><\/p>\n<p>Let&#8217;s break this down bit by bit.<\/p>\n<ul>\n<li><strong>Step 1: (Player wRAA \/ PA +<\/strong>\n<ul>\n<li>Will have to decide whether to elaborate the wRAA formula or use a variable in its definition, but very easy aside from that. \u00a0I will try it as a variable first.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Step 2: League Runs Per PA) +<\/strong>\n<ul>\n<li>Knowing that this would end up as part of the wRC+ calculation, I added it to the League Runs Per Out view I created in the Run Environment section. \u00a0And since we already referenced that view for wRAA, we can simply reference it here as RperPA<\/li>\n<\/ul>\n<\/li>\n<li><strong>Step 3: (League Runs Per PA &#8211;<\/strong>\n<ul>\n<li>Same as Step 2<\/li>\n<\/ul>\n<\/li>\n<li><strong>Step 4: (Park Factor * League Runs Per PA) \/\u00a0<\/strong>\n<ul>\n<li>If the park factor from the parks table can be used as a reasonable substitute &#8211; and I&#8217;m really hoping it can &#8211; then this is pretty straightforward. \u00a0I would join to parks on team_id and return the park factor (avg). \u00a0If can&#8217;t be used, then I&#8217;m off down a rabbit hole to calculate those park factors.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Step 5: (Subleague wRC\/Subleague PA)<\/strong>\n<ul>\n<li>Here&#8217;s a weird thing: Subleague wRC. \u00a0Just like a league wOBA is really just OBP, wouldn&#8217;t league wRC just be runs? \u00a0Let&#8217;s look at the wRC formula again as it would apply to the league:\n<ul>\n<li><em>League_wRC = (((League_wOBA-League_wOBA)\/wOBA Scale)+(League_R\/League_PA))*League_PA<\/em>\n<ul>\n<li>League_wOBA &#8211; League_wOBA = 0. \u00a0And 0 divided by anything is 0. \u00a0So, we evaluate to: 0 +\u00a0<em>(League_R\/League_PA))*League_PA<\/em><\/li>\n<li>League Runs Per Plate Appearance times Plate Appearances = League Runs.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>So that leaves us with Subleague_Runs divided by Subleague_PA &#8211; the same RperPA stat that we&#8217;ve used above, just at the subleague level.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Step 6: x 100<\/strong>\n<ul>\n<li>Self explanatory, really.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>I have to do something about identifying subleagues and summing their data before I start coding this formula. \u00a0At this point, I only need runs and PA. \u00a0Since I am eager to keep moving, those are the only stats I&#8217;ll create. \u00a0I created a quick table with those summed stats, joining on the team relations table:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-sql\">DROP TABLE IF EXISTS sub_league_history_batting;\r\nCREATE TABLE IF NOT EXISTS sub_league_history_batting AS\r\n   (SELECT b.year\r\n      , b.league_id\r\n      , t.sub_league_id\r\n      , sum(b.PA) as slg_PA\r\n      , sum(b.r) as slg_r\r\n    FROM CalcBatting b\r\n      INNER JOIN team_relations t ON b.team_id=t.team_id AND b.league_id=t.league_id\r\n      INNER JOIN players p ON b.player_id=p.player_id\r\n    WHERE p.position&lt;&gt;1\r\n    GROUP BY b.year, b.league_id, t.sub_league_id\r\n   );<\/code><\/pre>\n<p>OK, before the results, let&#8217;s set some initial expectations. \u00a0<a href=\"https:\/\/www.fangraphs.com\/library\/offense\/wrc\/\">Fangraphs<\/a>&#8216; rule of thumb chart is below. \u00a0It suggests, I think, that if I get within 10 points, I can trust that I&#8217;m in the right ballpark. \u00a0It won&#8217;t be super accurate for precise comparisons between players, but I can probably trust it for general analysis.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.ootp.cavebutter.net\/blog\/wp-content\/uploads\/2018\/03\/fangraphs_wrc.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"214\" data-permalink=\"http:\/\/www.ootp.cavebutter.net\/blog\/archives\/208\/fangraphs_wrc\" data-orig-file=\"https:\/\/i0.wp.com\/www.ootp.cavebutter.net\/blog\/wp-content\/uploads\/2018\/03\/fangraphs_wrc.jpg?fit=604%2C151\" data-orig-size=\"604,151\" 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=\"fangraphs_wrc\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.ootp.cavebutter.net\/blog\/wp-content\/uploads\/2018\/03\/fangraphs_wrc.jpg?fit=604%2C151\" class=\"aligncenter size-full wp-image-214\" src=\"https:\/\/i0.wp.com\/www.ootp.cavebutter.net\/blog\/wp-content\/uploads\/2018\/03\/fangraphs_wrc.jpg?resize=604%2C151\" alt=\"\" width=\"604\" height=\"151\" srcset=\"https:\/\/i0.wp.com\/www.ootp.cavebutter.net\/blog\/wp-content\/uploads\/2018\/03\/fangraphs_wrc.jpg?w=604 604w, https:\/\/i0.wp.com\/www.ootp.cavebutter.net\/blog\/wp-content\/uploads\/2018\/03\/fangraphs_wrc.jpg?resize=300%2C75 300w\" sizes=\"auto, (max-width: 604px) 100vw, 604px\" \/><\/a><\/p>\n<p>And here are the results &#8211; randomly selected player years.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.ootp.cavebutter.net\/blog\/wp-content\/uploads\/2018\/03\/wrcplus.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"213\" data-permalink=\"http:\/\/www.ootp.cavebutter.net\/blog\/archives\/208\/wrcplus\" data-orig-file=\"https:\/\/i0.wp.com\/www.ootp.cavebutter.net\/blog\/wp-content\/uploads\/2018\/03\/wrcplus.jpg?fit=526%2C466\" data-orig-size=\"526,466\" 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=\"wrcplus\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.ootp.cavebutter.net\/blog\/wp-content\/uploads\/2018\/03\/wrcplus.jpg?fit=526%2C466\" class=\"aligncenter size-full wp-image-213\" src=\"https:\/\/i0.wp.com\/www.ootp.cavebutter.net\/blog\/wp-content\/uploads\/2018\/03\/wrcplus.jpg?resize=526%2C466\" alt=\"\" width=\"526\" height=\"466\" srcset=\"https:\/\/i0.wp.com\/www.ootp.cavebutter.net\/blog\/wp-content\/uploads\/2018\/03\/wrcplus.jpg?w=526 526w, https:\/\/i0.wp.com\/www.ootp.cavebutter.net\/blog\/wp-content\/uploads\/2018\/03\/wrcplus.jpg?resize=300%2C266 300w\" sizes=\"auto, (max-width: 526px) 100vw, 526px\" \/><\/a>Pretty ugly, actually. \u00a019 of 30 are in the happy zone. \u00a0Of course, the happy zone is really much bigger than I would like it to be. \u00a08 are borderline, and the remaining 3 are just awful. \u00a0Some are high; some are low.<\/p>\n<p>At this point, I am not comfortable using this stat as a basis for any decision-making. \u00a0I&#8217;m also not ready to dive in and determine the park factors. \u00a0So, at least for the time being, I am going to leave this here and move on to pitching stats.<\/p>\n<p>Here&#8217;s the script:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-sql\">#Calculated batting stats for OOTP\r\n    DROP TABLE IF EXISTS CalcBatting;\r\n    CREATE TABLE IF NOT EXISTS CalcBatting AS\r\n\r\n    SELECT b.year\r\n    , b.league_id\r\n    , b.player_id\r\n    , b.stint #We can eventually move this down the list\r\n    , b.split_id #We can eventually remove\r\n    , b.team_id #We can eventually move this down the list\r\n    , l.abbr as Lg\r\n    , t.abbr as Team\r\n    , b.g\r\n    , b.ab\r\n    , @PA := b.ab+b.bb+b.sh+b.sf+b.hp AS PA\r\n    , b.r \r\n    , b.h\r\n    , b.d\r\n    , b.t\r\n    , b.hr\r\n    , b.rbi\r\n    , b.sb\r\n    , b.cs\r\n    , b.bb\r\n    , b.k\r\n    , b.ibb\r\n    , b.hp\r\n    , b.sh\r\n    , b.sf\r\n    , b.gdp\r\n    , b.ci\r\n    , @BA := round(b.h\/b.ab,3) AS ba\r\n    , round(b.k\/@PA,3) as krate\r\n    , round((b.bb)\/@PA,3) as bbrate\r\n    , @OBP := round((b.h + b.bb + b.hp)\/(@PA-b.sh-b.ci),3) AS obp\r\n    , round(100*(@OBP\/r.woba),0) as OBPplus\r\n    , @SLG := round((b.h+b.d+2*b.t+3*b.hr)\/b.ab,3) as slg\r\n    , round(@OBP+@SLG,3) as ops\r\n    , round(@SLG-@BA,3) as iso\r\n    , round((b.h-b.hr)\/(b.ab-b.k-b.hr+b.sf),3) as babip\r\n    , @woba := round((r.wobaBB*(b.bb-b.ibb) + r.wobaHB*b.hp + r.woba1B*(b.h-b.d-b.t-b.hr) +\r\n       r.woba2B*b.d + r.woba3B*b.t + r.wobaHR*b.hr)\r\n       \/(b.ab+b.bb-b.ibb+b.sf+b.hp),3) as woba\r\n    , @wRAA := round(((@woba-r.woba)\/r.wOBAscale)*@PA,1) as wRAA\r\n    , round((((@woba-r.woba)\/r.wOBAscale)+(lro.totr\/lro.totpa))*@PA,1) as wRC\r\n    , ROUND((((@wRAA\/@PA + lro.RperPA) + (lro.RperPA - p.avg*lro.RperPA))\/(slg.slg_r\/slg.slg_pa))*100,0) as 'wRC+'\r\n    FROM \r\n      players_career_batting_stats b \r\n      INNER JOIN leagues l ON b.league_id=l.league_id \r\n      INNER JOIN teams t ON b.team_id=t.team_id\r\n      INNER JOIN tblRunValues2 r ON b.year=r.year AND b.league_id=r.league_id\r\n      INNER JOIN vLeagueRunsPerOut lro ON b.year=lro.year AND b.league_id=lro.league_id\r\n      INNER JOIN parks p ON t.park_id=p.park_id\r\n      INNER JOIN sub_league_history_batting slg ON t.sub_league_id=slg.sub_league_id AND b.league_id=slg.league_id\r\n    WHERE b.ab&lt;&gt;0 AND b.split_id=1\r\n    ORDER BY b.player_id, b.year<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I will be writing this as I work through it, so this may be a little disjointed and have some false starts, but what the heck. wRC+ is similar to wRC and wRAA in that it measures runs created by a batter in a particular league-year context. \u00a0The most significant differences are that wRC+ is&hellip; <a class=\"more-link\" href=\"http:\/\/www.ootp.cavebutter.net\/blog\/archives\/208\">Continue reading <span class=\"screen-reader-text\">Batting Stats 10: wRC+<\/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":[25],"tags":[],"class_list":["post-208","post","type-post","status-publish","format-standard","hentry","category-batting"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9cxb5-3m","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts\/208","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=208"}],"version-history":[{"count":5,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts\/208\/revisions"}],"predecessor-version":[{"id":216,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/posts\/208\/revisions\/216"}],"wp:attachment":[{"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/media?parent=208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/categories?post=208"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ootp.cavebutter.net\/blog\/wp-json\/wp\/v2\/tags?post=208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}