<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/part-2-optimism-corrected-bootstrapping-is-definitely-bias-further-evidence/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://intobioinformatics.wordpress.com/2018/12/26/part-2-optimism-corrected-bootstrapping-is-definitely-bias-further-evidence/"> R – intobioinformatics</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Some people are very fond of the technique known as ‘optimism corrected bootstrapping’, however, this method is bias and this becomes apparent as we increase the number of noise features to high numbers (as shown very clearly <a rel="nofollow" href="https://intobioinformatics.wordpress.com/2018/12/25/optimism-corrected-bootstrapping-a-problematic-method/" target="_blank">in my previous blog post</a>). This needs exposing, I don’t have the time to do a publication on this nor the interest so hence this article. Now, I have reproduced the bias with my own code.</p>
<p>Let’s first just show the plot from last time again to recap, so as features increase (that are just noise), this method gives a strong positive AUC compared with cross validation. The response variable is random, the explanatory variables are random, so we should <strong>not</strong> get a positive result. Now, we are going to implement the method from scratch, instead of using Caret, and show the same thing.</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" 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>Perhaps in lower dimensions the method is not so bad, but I suggest avoiding it in all cases. I consider it something of a hack to get statistical power. Regardless of where it is published and by whom. Why? Because I have tested it myself, I am sure we could find some simulations that support its use somewhere, but LOOCV and K-fold cross validation do not have this problem. This method is infecting peoples work with a positive results bias in high dimensions, possibly lower dimensions as well.</p>
<p>After reading the last post Frank Harrell indirectly accused the makers of the Caret software as being somehow incorrect in their code implementation, so my results he decided were ‘erroneous’. I doubted this was the case, so now we have more evidence to expose the truth. This simple statistical method is described in this text book and a blog post (below), for those who are interested:</p>
<p>Steyerberg, Ewout W. <i>Clinical prediction models: a practical approach to development, validation, and updating</i>. Springer Science &amp; Business Media, 2008.</p>
<p><a rel="nofollow" href="http://thestatsgeek.com/2014/10/04/adjusting-for-optimismoverfitting-in-measures-of-predictive-ability-using-bootstrapping/" target="_blank">http://thestatsgeek.com/2014/10/04/adjusting-for-optimismoverfitting-in-measures-of-predictive-ability-using-bootstrapping/</a></p>
<p>The steps of this method, briefly, are as follows:</p>
<ol>
<li>Fit a model M to entire data S and estimate predictive ability C.</li>
<li>Iterate from b=1…B:
<ol>
<li>Take a resample from the original data, let this be S*</li>
<li>Fit the bootstrap model M* to S* and get predictive ability, C_boot</li>
<li>Use the bootstrap model M* to get predictive ability on S, C_orig</li>
</ol>
</li>
<li>Optimism O is calculated as mean(C_boot – C_orig)</li>
<li>Calculate optimism corrected performance as C-O.</li>
</ol>
<p>This is a general procedure (Steyerberg, 2008) and so I can use glmnet to fit the model and AUC as my measure of predictive performance. Glmnet is basically logistic regression with feature selection, so if this method for estimating ‘optimism’ is a good one, we should be able to estimate the optimism of overfitting this model using the above method, then correct for it.</p>
<p>Let’s re-run the analysis with my implementation of this method and compare with Caret (which is great software). Caret agrees with my implementation as shown below in fully reproducible code.</p>
<p>This code should be fine to copy and paste into R. The data is random noise, yet, optimism corrected bootstrapping gives a strong positive result AUC of 0.86, way way above what we would expect of 0.5.</p>
<p>In contrast, below I give code for Caret cross validation which gives the correct result, just test it for yourself instead of believing statistical dogma.</p>
<pre><span>> </span><span>corrected
</span><span>[1] 0.858264</span></pre>
<pre>

##
library(glmnet)
library(pROC)
library(caret)

## set up test data
test &lt;- matrix(rnorm(100*1000, mean = 0, sd = 1),
nrow = 100, ncol = 1000, byrow = TRUE)
labelsa &lt;- as.factor(c(rep('A',50),rep('B',50)))
colnames(test) &lt;- paste('Y',seq(1,1000),sep='')
row.names(test) &lt;- paste('Z',seq(1,100),sep='')

### my own implementation of optimism corrected bootstrapping

## 1. fit model to entire test data (i.e. overfit it)

orig &lt;- glmnet(test,y=labelsa,alpha=1,family = &quot;binomial&quot;)
preds &lt;- predict(orig,newx=test,type='response',s=0.01)
auc &lt;- roc(labelsa,as.vector(preds))
original_auc &lt;- as.numeric(auc$auc)

## 2. take resample of data and try to estimate optimism

test2 &lt;- cbind(test,labelsa)
B &lt;- 50
results &lt;- matrix(ncol=2,nrow=B)
for (b in seq(1,B)){
## get the bootstrapped resampled data
boot &lt;- test2[sample(row.names(test2),50),]
labelsb &lt;- boot[,ncol(boot)]
boot &lt;- boot[,-ncol(boot)]
## use the bootstrapped model to predict its own labels
bootf &lt;- glmnet(boot,y=labelsb,alpha=1,family = &quot;binomial&quot;)
preds &lt;- predict(bootf,newx=boot,type='response',s=0.01)
auc &lt;- roc(labelsb,as.vector(preds))
boot_auc &lt;- as.numeric(auc$auc)
## use bootstrap model to predict original labels
preds &lt;- predict(bootf,newx=test,type='response',s=0.01)
auc &lt;- roc(labelsa,as.vector(preds))
boot_original_auc &lt;- as.numeric(auc$auc)
## add the data to results
results[b,1] &lt;- boot_auc
results[b,2] &lt;- boot_original_auc
}
## calculate the optimism
O &lt;- mean(results[,1]-results[,2])
## calculate optimism corrected measure of prediction (AUC)
corrected &lt;- original_auc-O

### caret implementation of optimism corrected bootstrapping

test3 &lt;- data.frame(test2)
test3$labelsa &lt;- as.factor(test3$labelsa)
test3$labelsa &lt;- make.names(test3$labelsa)

ctrl &lt;- trainControl(method = 'optimism_boot',
summaryFunction=twoClassSummary,
classProbs=T,
savePredictions = T,
verboseIter = T)
fit1 &lt;- train(as.formula( paste( 'labelsa', '~', '.' ) ), data=test3,
method=&quot;glmnet&quot;, # preProc=c(&quot;center&quot;, &quot;scale&quot;)
trControl=ctrl, metric = &quot;ROC&quot;)

### sanity check, using cv

ctrl &lt;- trainControl(method = 'cv',
summaryFunction=twoClassSummary,
classProbs=T,
savePredictions = T,
verboseIter = T)
fit2 &lt;- train(as.formula( paste( 'labelsa', '~', '.' ) ), data=test3,
method=&quot;glmnet&quot;, # preProc=c(&quot;center&quot;, &quot;scale&quot;)
trControl=ctrl, metric = &quot;ROC&quot;)
</pre>
<p>Here is a plot repeating the Caret results I did with a simple loop to iteratively add noise only features and getting the corrected AUC for each iteration, but this is with my own implementation instead of Caret. You can try this out by sticking a FOR loop outside the code above to calculate the 'corrected' AUC. You can see the same misleading trend as we saw in the last post.</p>
<p><img data-orig-file="https://intobioinformatics.files.wordpress.com/2018/12/bias_in_optimism_corrected_bootstrapping2.png?w=456" data-orig-size="9566,5314" data-medium-file="https://intobioinformatics.files.wordpress.com/2018/12/bias_in_optimism_corrected_bootstrapping2.png?w=456?w=300" data-attachment-id="148" data-image-meta="{" data-image-description="" src="https://intobioinformatics.files.wordpress.com/2018/12/bias_in_optimism_corrected_bootstrapping2.png?w=456" data-permalink="https://intobioinformatics.wordpress.com/2018/12/26/part-2-optimism-corrected-bootstrapping-is-definitely-bias-further-evidence/bias_in_optimism_corrected_bootstrapping2/" data-large-file="https://intobioinformatics.files.wordpress.com/2018/12/bias_in_optimism_corrected_bootstrapping2.png?w=456?w=620" alt="bias_in_optimism_corrected_bootstrapping2.png" data-image-title="bias_in_optimism_corrected_bootstrapping2" sizes="(max-width: 620px) 100vw, 620px" data-comments-opened="1" class="wp-image-148" data-recalc-dims="1"></p>
<p>(X axis = number of noise only features added to random labels)<br>
(Y axis = ‘optimism corrected bootstrap AUC’)</p>
<p>People are currently using this method because it is published and they some how think published methods do not have fundamental problems, which is a widespread misconception.</p>
<p>R machine learning practitioners, do not trust methods just because some statistican says they are good in some paper or a forum, do not pick pet methods you love and so can never see the flaws in, test different methods and run <strong>your own</strong> positive and negative controls. Try and be objective.</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/26/part-2-optimism-corrected-bootstrapping-is-definitely-bias-further-evidence/"> 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/VxLr-Qyc9MM" height="1"></a></div>