Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Collate:
'interfaceRandomForest.R'
'interfaceRandomForestSurvival.R'
'interfaceSVM.R'
'interfaceTemplate.R'
'interfaceXGB.R'
'performancePlot.R'
'plotFeatureClasses.R'
Expand All @@ -90,12 +91,12 @@ Collate:
'rankingPairsDifferences.R'
'rankingPlot.R'
'reexports.R'
'registry.R'
'runTest.R'
'runTests.R'
'samplesMetricMap.R'
'selectMulti.R'
'selectionPlot.R'
'simpleParams.R'
'subtractFromLocation.R'
'utilities.R'
URL: https://sydneybiox.github.io/ClassifyR/
Expand Down
2 changes: 2 additions & 0 deletions R/available.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#' @aliases available
#' @param what Default: \code{"classifier"}. Either \code{"classifier"}, \code{"selectionMethod"}
#' or \code{"multiViewMethod"}.
#' @return A data frame of keywords and their descriptions. For classifiers and feature selection methods, the column
#' \code{Outcomes} says whether each one accepts classes, survival outcomes or both.

#' @author Dario Strbenac
#' @examples
Expand Down
75 changes: 1 addition & 74 deletions R/constants.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,80 +25,7 @@ NULL

.ClassifyRenvir[["performanceTypes"]] <- .ClassifyRenvir[["performanceInfoTable"]][, "type"]

# Nice-looking names for feature selection and classification functions, to automatically use
# in a variety of performance plots.
.ClassifyRenvir[["functionsTable"]] <- matrix(
c("subtractFromLocation", "Subtraction From Training Set Location",
"bartlettRanking", "Bartlett Test",
"classifyInterface", "Poisson LDA",
"differentMeansRanking", "Difference in Means",
"DLDAtrainInterface", "Diagonal LDA",
"DMDranking", "Differences of Medians and Deviations",
"edgeRranking", "edgeR LRT",
"GLMtrainInterface", "Logistic Regression",
"penalisedGLMtrainInterface", "Penalised GLMs (Ridge, Elastic net, LASSO)",
"fisherDiscriminant", "Fisher's LDA",
"kNNinterface", "k Nearest Neighbours",
"KolmogorovSmirnovRanking", "Kolmogorov-Smirnov Test",
"kTSPclassifier", "k Top-Scoring Pairs",
"KullbackLeiblerRanking", "Kullback-Leibler Divergence",
"leveneRanking", "Levene Test",
"likelihoodRatioRanking", "Likelihood Ratio Test (Normal)",
"limmaRanking", "Moderated t-test",
"mixModelsTrain", "Mixtures of Normals",
"naiveBayesKernel", "Naive Bayes Kernel",
"NSCtrainInterface", "Nearest Shrunken Centroids",
"pairsDifferencesRanking", "Pairs Differences",
"previousSelection", "Previous Selection",
"previousTrained", "Previous Trained",
"randomSelection", "Random Selection",
"randomForestTrainInterface", "Random Forest",
"SVMtrainInterface", "Support Vector Machine",
"coxphTrainInterface", "Cox Proportional Hazards",
"coxphRanking", "Cox Proportional Hazards",
"coxnetTrainInterface", "Penalised Cox Proportional Hazards",
#"NEMOEtrainInterface", "Nutrition-Ecotype Mixture of Experts",
"rfsrcTrainInterface", "Random Survival Forest",
"extremeGradientBoostingTrainInterface", "Extreme Gradient Boosting"),
ncol = 2, byrow = TRUE, dimnames = list(NULL, c("character", "name"))
) |> as.data.frame()

.ClassifyRenvir[["selectKeywords"]] <- matrix(
c("none", "Skip selection procedure and use all input features.",
"t-test", "T-test.",
"limma", "Moderated t-test.",
"edgeR", "edgeR likelihood ratio test.",
"Bartlett", "Bartlett's test for different variance.",
"Levene", "Levene's test for different variance.",
"DMD", "Differences in means/medians and/or deviations.",
"likelihoodRatio", "Likelihood ratio test (normal distribution).",
"KS", "Kolmogorov-Smirnov test for differences in distributions.",
"KL", "Kullback-Leibler divergence between distributions.",
"CoxPH", "Cox proportional hazards Wald test per-feature.",
"randomSelection", "Randomly selects a specified number of features."
),
ncol = 2, byrow = TRUE, dimnames = list(NULL, c("selectionMethod Keyword", "Description"))
) |> as.data.frame()

.ClassifyRenvir[["classifyKeywords"]] <- matrix(
c("randomForest", "Random forest.",
"DLDA", "Diagonal Linear Discriminant Analysis.",
"kNN", "k Nearest Neighbours.",
"GLM", "Logistic regression.",
"ridgeGLM", "Ridge GLM multinomial regression (alpha = 0).",
"elasticNetGLM", "Elastic net GLM multinomial regression (alpha = 0.5).",
"LASSOGLM", "LASSO GLM multinomial regression (alpha = 1).",
"SVM", "Support Vector Machine.",
"NSC", "Nearest Shrunken Centroids.",
"naiveBayes", "Naive Bayes kernel feature voting classifier.",
"mixturesNormals", "Mixture of normals feature voting classifier.",
"CoxPH", "Cox proportional hazards.",
"CoxNet", "Penalised Cox proportional hazards.",
"randomSurvivalForest", "Random survival forest.",
"XGB", "Extreme gradient booster."
),
ncol = 2, byrow = TRUE, dimnames = list(NULL, c("classifier Keyword", "Description"))
) |> as.data.frame()
# The classifiers and feature selection methods, their keywords and display names are in the registry (registry.R).

.ClassifyRenvir[["multiViewKeywords"]] <- matrix(
c("none", "Keep assays separate.",
Expand Down
18 changes: 11 additions & 7 deletions R/crossValidate.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ setMethod("crossValidate", "DataFrame",
if(isCategorical) selectionMethod <- "t-test" else selectionMethod <- "CoxPH"
if(length(classifier) == 1 && classifier == "auto")
if(isCategorical) classifier <- "randomForest" else classifier <- "CoxPH"
.checkOutcomeType(classifier, outcome, "classifiers")
.checkOutcomeType(selectionMethod, outcome, "selections")


# Which data-types or data-views are present?
Expand Down Expand Up @@ -413,14 +415,16 @@ cleanClassifier <- function(classifier, measurements, nFeatures){
if(!is.null(names(obsFeatures)) && all(names(obsFeatures) %in% names(classifier)) & is(classifier, "character")) classifier <- as.list(classifier[names(obsFeatures)])

nFeatures <- nFeatures[names(classifier)]
checkENs <- which(classifier %in% c("ridgeGLM", "elasticNetGLM", "LASSOGLM"))
if(length(checkENs) > 0)
# A classifier needing more features than an assay has is replaced by its fallback classifier.
for(index in seq_along(classifier))
{
replacements <- sapply(checkENs, function(checkEN) ifelse(any(nFeatures[[checkEN]] == 1), "GLM", classifier[[checkEN]]))
classifier[checkENs] <- replacements
if(any(replacements == "GLM"))
warning("Penalised GLM requires two or more features as input but there is only one.
Using an ordinary GLM instead.")
entry <- if(length(classifier[[index]]) == 1) .ClassifyRenvir[["classifiers"]][[classifier[[index]]]]
if(!is.null(entry[["fewFeaturesClassifier"]]) && any(nFeatures[[index]] < entry[["minFeatures"]]))
{
warning(classifier[[index]], " requires ", entry[["minFeatures"]], " or more features as input but there are fewer.\n",
"Using ", entry[["fewFeaturesClassifier"]], " instead.")
classifier[[index]] <- entry[["fewFeaturesClassifier"]]
}
}
classifier
}
Expand Down
33 changes: 33 additions & 0 deletions R/interfaceTemplate.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
################################################################################
#
# The contract of a classifier or feature selection interface. Copy this outline for a new method, then register it
# in registry.R.
#
# Training: newTrainInterface(measurementsTrain, outcomeTrain, <parameters>, ..., verbose = 3)
# - measurementsTrain is a DataFrame of the training samples, with features in columns. Categorical features are
# factors; methods needing a numeric matrix encode them with .encodeTrain and, at prediction, .encodeTest.
# - outcomeTrain (named classesTrain by the classifiers of classes only) is a factor of classes or a Surv object, as
# the registry entry's outcomes allow. It is passed by position.
# - <parameters> are the method's settings. Those in the entry's tunePresets are tuned when tuneParams is "auto".
# - It returns the trained model.
#
# Prediction: newPredictInterface(model, measurementsTest, ..., returnType = c("both", "class", "score"), verbose = 3)
# - Classes: "class" gives a factor with the training levels, "score" a samples x classes numeric matrix of class
# scores or probabilities with the class names as column names, and "both" a data frame of a column "class"
# followed by the score columns.
# - Survival: a numeric vector of risk scores, where higher means a higher risk of the event.
# - A classifier that trains and predicts in one function takes measurementsTest as its third argument and has no
# prediction interface (predict = NULL in its registry entry).
#
# Features used by a model (optional), for classifiers that rank or select features themselves: newFeatures(model)
# returns a list of two vectors of column indices of measurementsTrain, the features ranked from best to worst and
# the features the model uses. Other arguments, if any, are named after variables of runTest (for example,
# measurementsTrain), which supplies them. It is the entry's getFeatures.
#
# Feature ranking: newRanking(measurementsTrain, outcomeTrain, ..., verbose = 3) returns the indices of the columns
# of measurementsTrain, from the best feature to the worst.
#
# Each function carries its name as an attribute, which results and plots use to show its display name:
# attr(newTrainInterface, "name") <- "newTrainInterface"
#
################################################################################
Loading