diff --git a/DESCRIPTION b/DESCRIPTION index 63607b20..08d311d6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,7 +23,7 @@ Imports: car, plotROC, ROCR, tseries -RoxygenNote: 6.0.1 +RoxygenNote: 6.1.0 Suggests: aods3, breakDown, DALEX, diff --git a/R/modelEvaluation.R b/R/modelEvaluation.R index 2c420857..d76d0221 100644 --- a/R/modelEvaluation.R +++ b/R/modelEvaluation.R @@ -10,6 +10,7 @@ modelEvaluation <- function(object, variable = NULL){ if(!("modelAudit" %in% class(object))) stop("The function requires an object created with audit().") CGainsDF <- getCGainsDF(object)[-1,] + idealCGainsDF <- getidealCGainsDF(object)[-1,] result <- data.frame( y=object$y, @@ -18,6 +19,7 @@ modelEvaluation <- function(object, variable = NULL){ class(result) <- c("modelEvaluation", "data.frame") attr(result,'CGains') <- CGainsDF + attr(result,'idealCGains') <- idealCGainsDF return(result) } @@ -35,3 +37,15 @@ getCGainsDF <- function(object){ return(res) } +getidealCGainsDF <- function(object){ + + predictions <- object$y + y <- as.numeric(as.character(object$y)) + + pred <- ROCR::prediction(predictions, y) + gain <- ROCR::performance(pred, "tpr", "rpp") + + res <- data.frame(rpp = gain@x.values[[1]], tp = pred@tp[[1]], alpha = gain@alpha.values[[1]], + label = "ideal") + return(res) +} diff --git a/R/plotLift.R b/R/plotLift.R index d04f516a..8c24bcca 100644 --- a/R/plotLift.R +++ b/R/plotLift.R @@ -32,6 +32,14 @@ plotLIFT <- function(object, ...){ rpp <- tp <- label <- NULL df <- attributes(object)$CGains + idealdf <- attributes(object)$idealCGains + idealdf <- rbind(idealdf, c(0, 0, 0, "ideal")) + idealdf$tp <- as.numeric(idealdf$tp) + idealdf$rpp <- as.numeric(idealdf$rpp) + idealdf$alpha <- as.numeric(idealdf$alpha) + + randomdf <- data.frame(rpp = c(0, 1), tp = c(0, max(idealdf$tp)), alpha = c(0, 1), + label =c("random", "random")) dfl <- list(...) if (length(dfl) > 0) { @@ -48,6 +56,8 @@ plotLIFT <- function(object, ...){ ggplot(df, aes(x = rpp, y = tp, color = label)) + geom_line() + + geom_line(data = idealdf, aes(x = rpp, y = tp), color = "orange") + + geom_line(data = randomdf, aes(x = rpp, y = tp), color = "black") + xlab("rate of positive prediction") + ylab("true positive") + ggtitle("LIFT Chart") + diff --git a/R/plotModelRanking.R b/R/plotModelRanking.R index ede93d2f..c7d92727 100644 --- a/R/plotModelRanking.R +++ b/R/plotModelRanking.R @@ -69,7 +69,7 @@ plotModelRanking <- function(object, ..., scores = c("MAE", "MSE", "REC", "RROC" df$scaled <- scr df$scaled <- format(as.numeric(df$scaled), scientific = FALSE, digits = 3) df$score <- format(df$score, scientific = TRUE, digits = 3) - df <- df[ ,c(3,2,4,1)] + df <- df[ ,c(3,2,1,4)] table_score <- tableGrob(df, diff --git a/R/plotREC.R b/R/plotREC.R index 982e5b5e..3be1fdcb 100644 --- a/R/plotREC.R +++ b/R/plotREC.R @@ -54,6 +54,7 @@ plotREC <- function(object, ...){ labels = paste(seq(0, 100, 10),"%")) + theme_light() + xlab("error tolerance") + + ylab("") + ggtitle("REC Curve") } diff --git a/man/plot.modelAudit.Rd b/man/plot.modelAudit.Rd index 12cb791e..d6bb94b5 100644 --- a/man/plot.modelAudit.Rd +++ b/man/plot.modelAudit.Rd @@ -22,8 +22,8 @@ \method{plot}{modelResiduals}(x, ..., type = "Residual", ask = TRUE, grid = TRUE) -\method{plot}{observationInfluence}(x, ..., type = "Residual", ask = TRUE, - grid = TRUE) +\method{plot}{observationInfluence}(x, ..., type = "Residual", + ask = TRUE, grid = TRUE) } \arguments{ \item{x}{object of class modelAudit, modelResiduals or observationInfluence.} diff --git a/man/plotResidual.Rd b/man/plotResidual.Rd index 93d34fee..7b6c2a92 100644 --- a/man/plotResidual.Rd +++ b/man/plotResidual.Rd @@ -4,8 +4,8 @@ \alias{plotResidual} \title{Plot Residuals vs Observed, Fitted or Variable Values} \usage{ -plotResidual(object, ..., variable = NULL, points = TRUE, lines = FALSE, - std.residuals = FALSE, nlabel = 0) +plotResidual(object, ..., variable = NULL, points = TRUE, + lines = FALSE, std.residuals = FALSE, nlabel = 0) } \arguments{ \item{object}{An object of class modelAudit or modelResiduals.}