<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/tidy-resampling-redux-with-agricultural-economics-data/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://appliedpredictivemodeling.com/blog/2018/3/12/2s3j82ctkrhxugq7hf3myoeeb49k8u"> Blog - Applied Predictive Modeling</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><img data-image-dimensions="500x666" data-image-focal-point="0.5,0.5" src="https://i0.wp.com/static1.squarespace.com/static/51156277e4b0b8b2ffe11c00/t/5aa6f8f38165f57aa2bfeb07/1520892187966/UNADJUSTEDNONRAW_thumb_265a.jpg?w=456&ssl=1" alt="UNADJUSTEDNONRAW_thumb_265a.jpg" data-load="false" data-type="image" data-image-id="5aa6f8f38165f57aa2bfeb07" data-recalc-dims="1" data-image="https://static1.squarespace.com/static/51156277e4b0b8b2ffe11c00/t/5aa6f8f38165f57aa2bfeb07/1520892187966/UNADJUSTEDNONRAW_thumb_265a.jpg"></p>
<p>(No statistical graphs in this one. This is what my dog Artemis looks like when she wants my attention during work hours.)</p>
<p>Mindy L. Mallory (<a rel="nofollow" href="https://twitter.com/ace_prof" target="_blank"><code>@ace_prof</code></a>) wrote a blog post on <a rel="nofollow" href="http://blog.mindymallory.com/2018/02/machine-learning-and-econometrics-model-selection-and-assessment-statistical-learning-style/" target="_blank"><em>Machine Learning and Econometrics: Model Selection and Assessment Statistical Learning Style</em></a> where she has a great description of the variance-bias tradeoff, resampling, and model complexity using some data from agricultural economics. I asked if I could take her code and make a more <a rel="nofollow" href="https://cran.r-project.org/web/packages/tidyverse/vignettes/manifesto.html" target="_blank">tidy</a> version of the resampling part. Here it is… </p>
<p>Here are the R packages that I’ll be using:</p>
<pre><code>library(tidyverse)
library(rlang)
library(rsample)
library(yardstick)
library(purrr)</code></pre>
<p>First, duplicate the process of reading in the data and adding two new columns:</p>
<pre><code>stocks  &lt;- read.csv('http://blog.mindymallory.com/wp-content/uploads/2018/02/stocks.csv') %>% 
  as_tibble() %>%
  mutate(
    USStockUse = USEndingStocks/USTotalUse, 
    WorldStockUse = ROWEndingStocks/WorldTotalUse
  )
stocks</code></pre>
<pre><code>## # A tibble: 43 x 8
##     Year USEndingStocks ROWEndingStocks USTotalUse
##    </code></pre>