Skip to content

Commit

Permalink
Default values of characteristicsList[['x']] and performanceName chan…
Browse files Browse the repository at this point in the history
…ged to "auto" so that characteristic which varies between results the most is automatically chosen. C-index is chosen for performance metric if results have survival predictions and balanced accuracy if classification was done.
  • Loading branch information
Dario Strbenac committed Aug 4, 2022
1 parent 41ee06e commit f96a2df
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 28 deletions.
3 changes: 1 addition & 2 deletions R/ROCplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ setMethod("ROCplot", "list",
function(results, mode = c("merge", "average"), interval = 95,
comparison = "Classifier Name", lineColours = NULL,
lineWidth = 1, fontSizes = c(24, 16, 12, 12, 12), labelPositions = seq(0.0, 1.0, 0.2),
plotTitle = "ROC", legendTitle = NULL, xLabel = "False Positive Rate", yLabel = "True Positive Rate",
plot = TRUE, showAUC = TRUE)
plotTitle = "ROC", legendTitle = NULL, xLabel = "False Positive Rate", yLabel = "True Positive Rate", showAUC = TRUE)
{
if(!requireNamespace("ggplot2", quietly = TRUE))
stop("The package 'ggplot2' could not be found. Please install it.")
Expand Down
28 changes: 21 additions & 7 deletions R/performancePlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@
#' \code{characteristicsList['x']} to aggregate to a single number by taking
#' the mean. This is particularly meaningful when the cross-validation is
#' leave-k-out, when k is small.
#' @param performanceName Default: "Balanced Accuracy". The name of the
#' performance measure to make comparisons of. This is one of the names printed
#' @param performanceName Default: "auto". The name of the
#' performance measure or "auto". If the results are classification then
#' balanced accuracy will be displayed. Otherwise, the results would be survival risk
#' predictions and then C-index will be displayed. This is one of the names printed
#' in the Performance Measures field when a \code{\link{ClassifyResult}} object is
#' printed, or if none are stored, the performance metric will be calculated.
#' printed, or if none are stored, the performance metric will be calculated automatically.
#' @param characteristicsList A named list of characteristics. Each element's
#' name must be one of \code{"x"}, \code{"row"}, \code{"column"},
#' \code{fillColour}, or \code{fillLine}. The value of each element must be a
#' \code{"fillColour"}, or \code{"fillLine"}. The value of each element must be a
#' characteristic name, as stored in the \code{"characteristic"} column of the
#' results' characteristics table. Only \code{"x"} is mandatory.
#' results' characteristics table. Only \code{"x"} is mandatory. It is
#' \code{"auto"} by default, which will identify a characteristic that has a unique
#' value for each element of \code{results}.
#' @param coloursList A named list of plot aspects and colours for the aspects.
#' No elements are mandatory. If specified, each list element's name must be
#' either \code{"fillColours"} or \code{"lineColours"}. If a characteristic is
Expand Down Expand Up @@ -90,8 +94,8 @@ setGeneric("performancePlot", function(results, ...) standardGeneric("performanc
#' @rdname performancePlot
#' @export
setMethod("performancePlot", "list",
function(results, performanceName = "Balanced Accuracy",
characteristicsList = list(x = "Classifier Name"), aggregate = character(), coloursList = list(), orderingList = list(),
function(results, performanceName = "auto",
characteristicsList = list(x = "auto"), aggregate = character(), coloursList = list(), orderingList = list(),
densityStyle = c("box", "violin"), yLimits = NULL, fontSizes = c(24, 16, 12, 12), title = NULL,
margin = grid::unit(c(1, 1, 1, 1), "lines"), rotate90 = FALSE, showLegend = TRUE)
{
Expand All @@ -101,6 +105,16 @@ setMethod("performancePlot", "list",
stop("The package 'scales' could not be found. Please install it.")
densityStyle <- match.arg(densityStyle)
densityStyle <- ifelse(densityStyle == "box", ggplot2::geom_boxplot, ggplot2::geom_violin)
if(characteristicsList[["x"]] == "auto")
{
characteristicsCounts <- table(unlist(lapply(results, function(result) result@characteristics[["characteristic"]])))
if(max(characteristicsCounts) == length(results))
characteristicsList[["x"]] <- names(characteristicsCounts)[characteristicsCounts == max(characteristicsCounts)][1]
else
stop("No characteristic is present for all results but must be.")
}
if(performanceName == "auto")
performanceName <- ifelse("risk" %in% colnames(results[[1]]@predictions), "C-index", "Balanced Accuracy")

ggplot2::theme_set(ggplot2::theme_classic() + ggplot2::theme(panel.border = ggplot2::element_rect(fill = NA)))
performanceNames <- unlist(lapply(results, function(result)
Expand Down
14 changes: 12 additions & 2 deletions R/selectionPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
#' name must be one of \code{"x"}, \code{"row"}, \code{"column"},
#' \code{"fillColour"}, or \code{"lineColour"}. The value of each element must be a
#' characteristic name, as stored in the \code{"characteristic"} column of the
#' results' characteristics table. Only \code{"x"} is mandatory.
#' results' characteristics table. Only \code{"x"} is mandatory. It is
#' \code{"auto"} by default, which will identify a characteristic that has a unique
#' value for each element of \code{results}.
#' @param coloursList A named list of plot aspects and colours for the aspects.
#' No elements are mandatory. If specified, each list element's name must be
#' either \code{"fillColours"} or \code{"lineColours"}. If a characteristic is
Expand Down Expand Up @@ -137,7 +139,7 @@ standardGeneric("selectionPlot"))
setMethod("selectionPlot", "list",
function(results,
comparison = "within", referenceLevel = NULL,
characteristicsList = list(x = "Classifier Name"), coloursList = list(), orderingList = list(), binsList = list(),
characteristicsList = list(x = "auto"), coloursList = list(), orderingList = list(), binsList = list(),
yMax = 100, fontSizes = c(24, 16, 12, 16), title = if(comparison == "within") "Feature Selection Stability" else if(comparison == "size") "Feature Selection Size" else if(comparison == "importance") "Variable Importance" else "Feature Selection Commonality",
yLabel = if(is.null(referenceLevel) && !comparison %in% c("size", "importance")) "Common Features (%)" else if(comparison == "size") "Set Size" else if(comparison == "importance") tail(names(results[[1]]@importance), 1) else paste("Common Features with", referenceLevel, "(%)"),
margin = grid::unit(c(1, 1, 1, 1), "lines"), rotate90 = FALSE, showLegend = TRUE, plot = TRUE, parallelParams = bpparam())
Expand All @@ -150,6 +152,14 @@ setMethod("selectionPlot", "list",
stop("'comparison' should not be \"within\" if 'referenceLevel' is not NULL.")

ggplot2::theme_set(ggplot2::theme_classic() + ggplot2::theme(panel.border = ggplot2::element_rect(fill = NA)))
if(characteristicsList[["x"]] == "auto")
{
characteristicsCounts <- table(unlist(lapply(results, function(result) result@characteristics[["characteristic"]])))
if(max(characteristicsCounts) == length(results))
characteristicsList[["x"]] <- names(characteristicsCounts)[characteristicsCounts == max(characteristicsCounts)][1]
else
stop("No characteristic is present for all results but must be.")
}

allFeaturesList <- lapply(results, function(result)
{
Expand Down
3 changes: 0 additions & 3 deletions man/ROCplot.Rd

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

24 changes: 12 additions & 12 deletions man/performancePlot.Rd

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

6 changes: 4 additions & 2 deletions man/selectionPlot.Rd

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

0 comments on commit f96a2df

Please sign in to comment.