diff --git a/NAMESPACE b/NAMESPACE index 96c2932..b81e082 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/plotAUC.R b/R/plotAUC.R index 758bc86..376b4e3 100644 --- a/R/plotAUC.R +++ b/R/plotAUC.R @@ -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) + } + } diff --git a/man/plotAUC.Rd b/man/plotAUC.Rd index 99de527..7fb0795 100644 --- a/man/plotAUC.Rd +++ b/man/plotAUC.Rd @@ -4,11 +4,16 @@ \alias{plotAUC} \title{Plot AUC} \usage{ -plotAUC(modelingResult) +plotAUC(modelingResult, CI = FALSE, ...) } \arguments{ \item{modelingResult}{output from either \code{lr_modeling} or \code{rf_modeling}} + +\item{CI}{(logical) Plot confidence interval or not. Default is False.} + +\item{...}{further arguments passes to the \code{plot} method of the +\code{\link[pROC]{ci.se}} object of the \code{pROC} package.} } \description{ Plot AUC after LOOCV Model Evaluation