Skip to content

Commit

Permalink
Merge pull request #59 from PNNL-Comp-Mass-Spec/58-add-showing-confid…
Browse files Browse the repository at this point in the history
…ence-intervals-to-plotauc

adding confidence interval to AUC plot
  • Loading branch information
vladpetyuk authored Sep 4, 2023
2 parents be978cb + 834305e commit 9608ff8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ importFrom(lme4,lmer)
importFrom(methods,setMethod)
importFrom(outliers,grubbs.test)
importFrom(outliers,outlier)
importFrom(pROC,ci.se)
importFrom(pROC,roc)
importFrom(parallel,clusterApply)
importFrom(parallel,clusterEvalQ)
importFrom(parallel,clusterExport)
Expand Down
47 changes: 40 additions & 7 deletions R/plotAUC.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,52 @@
#'
#' @param modelingResult output from either
#' \code{lr_modeling} or \code{rf_modeling}
#' @param CI (logical) Plot confidence interval or not. Default is False.
#' @param ... further arguments passes to the \code{plot} method of the
#' \code{\link[pROC]{ci.se}} object of the \code{pROC} package.
#'
#'
#' @importFrom ROCR performance
#' @importFrom graphics abline
#' @importFrom pROC roc ci.se
#'
#' @export plotAUC
#'
plotAUC <- function(modelingResult){
perf <- performance(modelingResult$pred,"tpr","fpr")
# x=1-spec, y=sens
plot(perf,
main=sprintf("AUC: %s", round(modelingResult$auc,2)),
col=2, lwd=2)
abline(a=0,b=1,lwd=2,lty=2,col="gray")
plotAUC <- function(modelingResult, CI = FALSE, ...){

if(!CI){
perf <- performance(modelingResult$pred,"tpr","fpr")
# x=1-spec, y=sens
plot(perf,
main=sprintf("AUC: %s", round(modelingResult$auc,2)),
col=2, lwd=2)
abline(a=0,b=1,lwd=2,lty=2,col="gray")
}else{
old_par <- par()
par(pty="s")
pROC_obj <- roc(modelingResult$pred@labels[[1]],
modelingResult$pred@predictions[[1]],
direction = "<",
smoothed = T,
# arguments for ci
ci=TRUE,
ci.alpha=0.95,
stratified=FALSE,
# arguments for plot
plot=TRUE,
auc.polygon=F,
max.auc.polygon=F,
grid=F,
print.auc=TRUE,
print.auc.y=0.1,
print.auc.x=0.8,
show.thres=TRUE)
sens.ci <- ci.se(pROC_obj)
plot(sens.ci, type="shape", col="#FF8888", conf=95, ...)
abline(a=1,b=-1,lty=2,lwd=2,col="grey50")
par(old_par)
}

}


Expand Down
7 changes: 6 additions & 1 deletion man/plotAUC.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9608ff8

Please sign in to comment.