<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-3-two-more-implementations-of-optimism-corrected-bootstrapping-show-shocking-bias/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://intobioinformatics.wordpress.com/2018/12/27/part-3-two-more-implementations-of-optimism-corrected-bootstrapping-show-shocking-bias/"> R – intobioinformatics</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Welcome to part III of debunking the optimism corrected bootstrap in high dimensions (quite high number of features) in the Christmas holidays. Previously <a rel="nofollow" href="https://intobioinformatics.wordpress.com/2018/12/26/part-2-optimism-corrected-bootstrapping-is-definitely-bias-further-evidence/" target="_blank">we saw with a reproducible code implementation</a> that this method is very bias when we have many features (50-100 or more). I suggest avoiding this method until at some point it has been reassessed thoroughly to find how bad this situation is with different numbers of dimensions. Yes, I know for some statisticians this is your favorite method and they tell people how their method is lacking in statistical power, but clearly this has much worse issues, at least on some data. People are currently using this method in genomic medicine, where we have high numbers of features low samples. Just re-run the code yourself and make up your own mind if in doubt. I have now 3 implementations (excluding Caret) confirming the bias. One written by me, two independent statisticians. Let’s run some more experiments.</p>
<p>This time I have used a different persons implementation using the ‘glm’ function, i.e. logistic regression to show the same misleading trend occurs, i.e. positive results on purely random data. The code has been directly taken from <a rel="nofollow" href="http://cainarchaeology.weebly.com/r-function-for-optimism-adjusted-auc.html" target="_blank">http://cainarchaeology.weebly.com/r-function-for-optimism-adjusted-auc.html</a>, here. The second implementation is from another unnamed statistician, there was a bug in their code so I had to correct it, there may be further errors in it so feel free to check.</p>
<p>If you disagree with these findings, please show your own implementation of the method in R (not using Caret) following the same experiment of increasing number of features that are purely noise very high with binary labels. Also, check the last two posts and re-run the code your self, before making your mind up and providing counter arguments. I am practically certain there is a serious problem with this method. Yet again, with situations like this, don’t rely on Mr X’s publication from 10 years ago, use null simulated data sets with different dimensions to investigate the behavior of the method in question your self.</p>
<p>There are no real predictors in this data, all of them are random data from a normal distribution. The bias is less bad using glm than with glmnet. This method is being used (with high numbers of features) as we speak by Mr Fudge and his friends so they can get into better journals. The system is corrupt.</p>
<p>You should be able to copy and paste this code directly into R to repeat the results. I can’t vouch for this code because I did not write it, but both implementations show the same result as in the <a rel="nofollow" href="https://intobioinformatics.wordpress.com/2018/12/26/part-2-optimism-corrected-bootstrapping-is-definitely-bias-further-evidence/" target="_blank">last blog post</a> with my code.</p>
<p>Implementation 1. A glm experiment.</p>
<pre>

### example of logistic regression optimism corrected bootstrapping
# source: http://cainarchaeology.weebly.com/r-function-for-optimism-adjusted-auc.html

auc.adjust &lt;- function(data, fit, B){
fit.model &lt;- fit
data$pred.prob &lt;- fitted(fit.model)
auc.app &lt;- roc(data[,1], data$pred.prob, data=data)$auc # require 'pROC'
auc.boot &lt;- vector (mode = &quot;numeric&quot;, length = B)
auc.orig &lt;- vector (mode = &quot;numeric&quot;, length = B)
o &lt;- vector (mode = &quot;numeric&quot;, length = B)
for(i in 1:B){
boot.sample &lt;- sample.rows(data, nrow(data), replace=TRUE) # require 'kimisc'
fit.boot &lt;- glm(formula(fit.model), data = boot.sample, family = &quot;binomial&quot;)
boot.sample$pred.prob &lt;- fitted(fit.boot)
auc.boot[i] &lt;- roc(boot.sample[,1], boot.sample$pred.prob, data=boot.sample)$auc
data$pred.prob.back &lt;- predict.glm(fit.boot, newdata=data, type=&quot;response&quot;)
auc.orig[i] &lt;- roc(data[,1], data$pred.prob.back, data=data)$auc
o[i] &lt;- auc.boot[i] - auc.orig[i]
}
auc.adj &lt;- auc.app - (sum(o)/B)
boxplot(auc.boot, auc.orig, names=c(&quot;auc.boot&quot;, &quot;auc.orig&quot;))
title(main=paste(&quot;Optimism-adjusted AUC&quot;, &quot;\nn of bootstrap resamples:&quot;, B), sub=paste(&quot;auc.app (blue line)=&quot;, round(auc.app, digits=4),&quot;\nadj.auc (red line)=&quot;, round(auc.adj, digits=4)), cex.sub=0.8)
abline(h=auc.app, col=&quot;blue&quot;, lty=2)
abline(h=auc.adj, col=&quot;red&quot;, lty=3)
}

## generate random data

xx.glmnet &lt;- matrix(nrow=53,ncol=1)
xx.glmnet &lt;- data.frame(xx.glmnet)
xx.glmnet[,1] &lt;- c(rep(0,25),rep(1,28))
test &lt;- matrix(rnorm(53*1000, mean = 0, sd = 1),
nrow = 53, ncol = 1000, byrow = TRUE)
xx.glmnet &lt;- cbind(xx.glmnet,test)
colnames(xx.glmnet) &lt;- c('outcome',paste('Y',seq(1,1000),sep=''))

## 1. make overfitted model

model &lt;- glm(outcome ~., data = xx.glmnet, family = &quot;binomial&quot;)

## 2. estimate optimism and correct

auc.adjust(xx.glmnet, model, B=200)

</pre>
<p>Let's have a look at the results, which agree nicely with our previous findings using a from scratch implementation of the method. So the red line is supposedly our corrected AUC, but the AUC should be 0.5 when running on random data. See previous <a rel="nofollow" href="https://intobioinformatics.wordpress.com/2018/12/25/optimism-corrected-bootstrapping-a-problematic-method/" target="_blank">part 1 post</a> and <a rel="nofollow" href="https://intobioinformatics.wordpress.com/2018/12/26/part-2-optimism-corrected-bootstrapping-is-definitely-bias-further-evidence/" target="_blank">part 2 post</a> for demonstration of cross validation results on random data which give the correct result.</p>
<p><img data-orig-file="https://intobioinformatics.files.wordpress.com/2018/12/Rplot.png?w=456" data-orig-size="584,399" data-medium-file="https://intobioinformatics.files.wordpress.com/2018/12/Rplot.png?w=456?w=300" data-attachment-id="153" data-image-meta="{" data-image-description="" src="https://intobioinformatics.files.wordpress.com/2018/12/Rplot.png?w=456" data-permalink="https://intobioinformatics.wordpress.com/2018/12/27/part-3-two-more-implementations-of-optimism-corrected-bootstrapping-show-shocking-bias/rplot/" data-large-file="https://intobioinformatics.files.wordpress.com/2018/12/Rplot.png?w=456?w=584" alt="Rplot" data-image-title="Rplot" sizes="(max-width: 584px) 100vw, 584px" data-comments-opened="1" class="wp-image-153" data-recalc-dims="1"></p>
<p>Implementation 2: Another glmnet experiment</p>
<pre>

### example of optimism corrected bootstrapping implementation
# source: an unnamed programmer

library(boot)
library(pROC)
library(glmnet)

#glmnet -all predictors penalised
compare_opt_glmnet&lt;- function(orig_data_glmnet, i){
# orig_data_glmnet = the whole data
train_data_glmnet&lt;- orig_data_glmnet[i, ] # get bootstrap
model_glmnet&lt;- model_process_glmnet(train_data_glmnet)
# return a summary optimism results
AUC_results_glmnet &lt;- c(
# boot against original
AUC_train1=roc(orig_data_glmnet$outcome,as.vector(predict(model_glmnet,type=&quot;response&quot;, newx = model.matrix (outcome~.,orig_data_glmnet )[,-1], s = 'lambda.min')))$auc,
# boot against boot
AUC_train2=roc(train_data_glmnet$outcome,as.vector(predict(model_glmnet,type=&quot;response&quot;, newx = model.matrix (outcome~.,train_data_glmnet )[,-1], s = 'lambda.min')))$auc,
AUC_diff=roc(train_data_glmnet$outcome,as.vector(predict(model_glmnet,type=&quot;response&quot;, newx = model.matrix (outcome~.,train_data_glmnet )[,-1], s = 'lambda.min')))$auc-
roc(orig_data_glmnet$outcome,as.vector(predict(model_glmnet,type=&quot;response&quot;, newx = model.matrix (outcome~.,orig_data_glmnet )[,-1], s = 'lambda.min')))$auc
)
return(AUC_results_glmnet)
}

model_process_glmnet&lt;- function(the_data_glmnet){
model_final_glmnet &lt;- cv.glmnet (model.matrix (outcome~.,the_data_glmnet )[,-1],the_data_glmnet$outcome,alpha=1,family = &quot;binomial&quot;)
return(model_final_glmnet)
}

# generate random data

test &lt;- matrix(rnorm(53*1000, mean = 0, sd = 1),
nrow = 53, ncol = 1000, byrow = TRUE)
test &lt;- data.frame(test)
labs &lt;- factor(c(0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,1,0,1,1,0,1,0,1,0,0,0,0,0,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))
labs &lt;- data.frame(as.matrix(labs))
colnames(labs)[1] &lt;- 'outcome'
xx.glmnet &lt;- cbind(labs,test)

## 1. make overfitted model

tempd &lt;- xx.glmnet[,2:ncol(xx.glmnet)]
labels &lt;- xx.glmnet[,1]
overfittedmodel &lt;- cv.glmnet(as.matrix(tempd),y=labels,alpha=1,family=&quot;binomial&quot;)
lasso.prob &lt;- predict(overfittedmodel,type=&quot;response&quot;,newx=as.matrix(tempd),s='lambda.min')
pred.cligen &lt;- prediction(lasso.prob, labels)
auc &lt;- roc(labels,as.vector(lasso.prob))
overfitted_auc &lt;- as.numeric(auc$auc)

## 2. try to correct for optimism

Repeats = 100
res_opt_glmnet &lt;- boot(xx.glmnet, statistic = compare_opt_glmnet, R = Repeats)
optimism_glmnet &lt;- mean(res_opt_glmnet$t[ , 3])
enhanced_glmnet &lt;- overfitted_auc - optimism_glmnet

</pre>
<p>Here are the results of the above code on random data only (pure madness).</p>
<pre><span>> </span><span>enhanced_glmnet
</span><span>[1] 0.8916488</span></pre>
<p>There is some disagreement how to implement this method in Caret as Davis Vaughan disagrees with doing it the way shown <a rel="nofollow" href="https://intobioinformatics.wordpress.com/2018/12/25/optimism-corrected-bootstrapping-a-problematic-method/" target="_blank">here</a>. So, until Max Kuhn gets back to me, relying on the last two posts, I think all the evidence points to a massive positive bias in peoples results using this method with high numbers of features.</p>
<p>If in doubt compare your results with LOOCV and k fold cross validation, this is how I discovered this method is dodgy by seeing MASSIVE differences on null data-sets where no real predictive ability should be found. These two methods are more widely used and reliable.</p>
<p>Sorry @ Frank Harrell, I don’t have time atm to do the extra bits you suggest.<br>
Game on @ Davis Vaughan. Do your own implementation with the same data as I have used with glmnet and glm.</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, 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>
<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/27/part-3-two-more-implementations-of-optimism-corrected-bootstrapping-show-shocking-bias/"> 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/escs1jZZHz0" height="1"></a></div>