<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/optimism-corrected-bootstrapping-a-problematic-method/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://intobioinformatics.wordpress.com/2018/12/25/optimism-corrected-bootstrapping-a-problematic-method/"> R – intobioinformatics</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>There are lots of ways to assess how predictive a model is while correcting for overfitting. In Caret the main methods I use are leave one out cross validation, for when we have relatively few samples, and k fold cross validation when we have more. There also is another method called ‘optimism corrected bootstrapping’, that attempts to save statistical power, by first getting the overfitted result, then trying to correct this result by bootstrapping the data to estimate the degree of optimism. A few simple tests in Caret can demonstrate this method is bunk.</p>
<p>This is a very straightforward method, just add random variables from a normal distribution to the ground truth iris labels. We should find our AUC (area under ROC curve) is about 0.5. Yet for optimism corrected bootstrap it gives a positive result regardless of whether the predictors are just noise or not. Let’s just run that test:</p>
<p>This is called a sensitivity analysis for the uninitiated, I am just increasing number of random noise features (z) and binding them to the real labels in an iterative manner.</p>
<pre>
library(caret)
allresults &lt;- matrix(ncol=2,nrow=200)
i = 0
for (z in seq(10,2000,10)){

  i = i + 1

  # select only two species
  iris &lt;- subset(iris, iris$Species == 'versicolor' | iris$Species == 'virginica')
  iris$Species &lt;- droplevels(iris$Species)
  # generate random data
  test &lt;- matrix(rnorm(100*z, mean = 0, sd = 1),
                 nrow = 100, ncol = z, byrow = TRUE)
  # bind random data
  iris &lt;- cbind(iris,test)
  # remove real data
  iris &lt;- iris[,-1:-4]

  # cross validation
  ctrl &lt;- trainControl(method = 'cv',
                       summaryFunction=twoClassSummary,
                       classProbs=T,
                       savePredictions = T,
                       verboseIter = T)
  fit3 &lt;- train(as.formula( paste( 'Species', '~', '.' ) ), data=iris,
                method=&quot;glmnet&quot;, # preProc=c(&quot;center&quot;, &quot;scale&quot;)
                trControl=ctrl, metric = &quot;ROC&quot;) #
  allresults[i,1] &lt;- max(fit3$results$ROC)

  # optimism corrected bootstrapping
  ctrl &lt;- trainControl(method = 'optimism_boot',
                       summaryFunction=twoClassSummary,
                       classProbs=T,
                       savePredictions = T,
                       verboseIter = T)
  fit4 &lt;- train(as.formula( paste( 'Species', '~', '.' ) ), data=iris,
                method=&quot;glmnet&quot;, # preProc=c(&quot;center&quot;, &quot;scale&quot;)
                trControl=ctrl, metric = &quot;ROC&quot;) #
  allresults[i,2] &lt;- max(fit4$results$ROC)

  rm(iris)
}

df &lt;- data.frame(allresults)
colnames(df) &lt;- c('cross_validation','optimism_corrected_boot')
df2 &lt;- reshape2::melt(df)
df2$N &lt;- c(seq(10,2000,10),seq(10,2000,10))

# do the plot
p1 &lt;- ggplot(df2, aes(x=N, y=value, group=variable)) +
  geom_line(aes(colour=variable))
png('bias_in_optimism_corrected_bootstrapping.png', height = 15, width = 27, units = 'cm',
    res = 900, type = 'cairo')
print(p1)
dev.off()
</pre>
<p>So there we have it, a method that is being used in publications as we speak, but it is horribly bias. This is science for you, full of misinformation and lies. Be warned, there is a darkness out there R readers, not just in Washington.</p>
<p><img data-orig-file="https://intobioinformatics.files.wordpress.com/2018/12/bias_in_optimism_corrected_bootstrapping.png?w=456" data-orig-size="9566,5314" data-medium-file="https://intobioinformatics.files.wordpress.com/2018/12/bias_in_optimism_corrected_bootstrapping.png?w=456?w=300" data-attachment-id="137" data-image-meta="{" data-image-description="" src="https://intobioinformatics.files.wordpress.com/2018/12/bias_in_optimism_corrected_bootstrapping.png?w=456" data-permalink="https://intobioinformatics.wordpress.com/2018/12/25/optimism-corrected-bootstrapping-a-problematic-method/bias_in_optimism_corrected_bootstrapping/" data-large-file="https://intobioinformatics.files.wordpress.com/2018/12/bias_in_optimism_corrected_bootstrapping.png?w=456?w=620" alt="bias_in_optimism_corrected_bootstrapping.png" data-image-title="bias_in_optimism_corrected_bootstrapping" sizes="(max-width: 620px) 100vw, 620px" data-comments-opened="1" class="wp-image-137" data-recalc-dims="1"></p>
<p>N (x axis) refers to number of features here (that are just noise). AUC (y axis) is about 0.5 when we have no predictive power.</p>
<p>We can see cross validation performs as expected, it is a bit unstable though, better to use repeated cross validation I think.</p>
<p>My recommendations for Rbloggers readers who don’t know much about supervised machine learning, but want to use it on their data in R:</p>
<ul>
<li>Don’t start by implementing cross validation loops your self and calculate AUC etc, Caret makes life a lot easier and it is bug tested by thousands of people around the world like myself.</li>
<li>Stick with tried and tested mainstream approaches when in doubt. Like LOOCV or repeated k fold CV.</li>
<li>If implementing your own method or skeptical of the reliability of the method your using, use rnorm to perform a negative control to test your statistical method for bias. This is a good check to perform, as well as a positive control.</li>
<li>Make sure your data is in the correct order.</li>
</ul>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://intobioinformatics.wordpress.com/2018/12/25/optimism-corrected-bootstrapping-a-problematic-method/"> R – intobioinformatics</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/QButiANG1ik" height="1"></a></div>