... | ... |
@@ -26,7 +26,7 @@ Description: The software formalises a framework for classification in R. |
26 | 26 |
may be developed by the user, by creating an interface to the framework. |
27 | 27 |
License: GPL-3 |
28 | 28 |
Packaged: 2014-10-18 11:16:55 UTC; dario |
29 |
-RoxygenNote: 7.2.0 |
|
29 |
+RoxygenNote: 7.2.1 |
|
30 | 30 |
SystemRequirements: C++14 |
31 | 31 |
Collate: |
32 | 32 |
'ROCplot.R' |
33 | 33 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,74 @@ |
1 |
+# Generated by roxygen2: do not edit by hand |
|
2 |
+ |
|
3 |
+export(ClassifyResult) |
|
4 |
+export(FeatureSetCollection) |
|
5 |
+export(ROCplot) |
|
6 |
+export(actualOutcome) |
|
7 |
+export(allFeatureNames) |
|
8 |
+export(available) |
|
9 |
+export(calcCVperformance) |
|
10 |
+export(calcExternalPerformance) |
|
11 |
+export(chosenFeatureNames) |
|
12 |
+export(crossValidate) |
|
13 |
+export(distribution) |
|
14 |
+export(edgesToHubNetworks) |
|
15 |
+export(featureSetSummary) |
|
16 |
+export(generateCrossValParams) |
|
17 |
+export(generateModellingParams) |
|
18 |
+export(getLocationsAndScales) |
|
19 |
+export(interactorDifferences) |
|
20 |
+export(models) |
|
21 |
+export(performance) |
|
22 |
+export(performancePlot) |
|
23 |
+export(plotFeatureClasses) |
|
24 |
+export(predictions) |
|
25 |
+export(prepareData) |
|
26 |
+export(rankingPlot) |
|
27 |
+export(sampleNames) |
|
28 |
+export(samplesMetricMap) |
|
29 |
+export(selectionPlot) |
|
30 |
+export(totalPredictions) |
|
31 |
+export(tunedParameters) |
|
32 |
+exportClasses(ClassifyResult) |
|
33 |
+exportClasses(FeatureSetCollection) |
|
34 |
+exportMethods("[") |
|
35 |
+exportMethods("[[") |
|
36 |
+exportMethods(ClassifyResult) |
|
37 |
+exportMethods(FeatureSetCollection) |
|
38 |
+exportMethods(ROCplot) |
|
39 |
+exportMethods(actualOutcome) |
|
40 |
+exportMethods(allFeatureNames) |
|
41 |
+exportMethods(calcCVperformance) |
|
42 |
+exportMethods(calcExternalPerformance) |
|
43 |
+exportMethods(chosenFeatureNames) |
|
44 |
+exportMethods(crossValidate) |
|
45 |
+exportMethods(distribution) |
|
46 |
+exportMethods(featureSetSummary) |
|
47 |
+exportMethods(getLocationsAndScales) |
|
48 |
+exportMethods(interactorDifferences) |
|
49 |
+exportMethods(length) |
|
50 |
+exportMethods(models) |
|
51 |
+exportMethods(performance) |
|
52 |
+exportMethods(performancePlot) |
|
53 |
+exportMethods(plotFeatureClasses) |
|
54 |
+exportMethods(predict) |
|
55 |
+exportMethods(predictions) |
|
56 |
+exportMethods(prepareData) |
|
57 |
+exportMethods(rankingPlot) |
|
58 |
+exportMethods(sampleNames) |
|
59 |
+exportMethods(samplesMetricMap) |
|
60 |
+exportMethods(selectionPlot) |
|
61 |
+exportMethods(show) |
|
62 |
+exportMethods(totalPredictions) |
|
63 |
+exportMethods(tunedParameters) |
|
64 |
+import(BiocParallel) |
|
65 |
+import(grid) |
|
66 |
+import(utils) |
|
67 |
+importFrom(S4Vectors,as.data.frame) |
|
68 |
+importFrom(dplyr,mutate) |
|
69 |
+importFrom(dplyr,n) |
|
70 |
+importFrom(rlang,sym) |
|
71 |
+importFrom(survival,Surv) |
|
72 |
+importFrom(survival,concordance) |
|
73 |
+importFrom(tidyr,gather) |
|
74 |
+useDynLib(ClassifyR, .registration = TRUE) |
... | ... |
@@ -59,7 +59,7 @@ |
59 | 59 |
#' actual <- factor(c(rep("Healthy", 10), rep("Cancer", 10)), levels = c("Healthy", "Cancer")) |
60 | 60 |
#' result1 <- ClassifyResult(DataFrame(characteristic = c("Data Set", "Selection Name", "Classifier Name", "Cross-validation"), |
61 | 61 |
#' value = c("Melanoma", "t-test", "Random Forest", "2-fold")), |
62 |
-#' LETTERS[1:20], list(paste("Gene", LETTERS[1:10]), paste("Gene", LETTERS[c(5:1, 6:10)])), |
|
62 |
+#' LETTERS[1:20], paste("Gene", LETTERS[1:10]), list(paste("Gene", LETTERS[1:10]), paste("Gene", LETTERS[c(5:1, 6:10)])), |
|
63 | 63 |
#' list(paste("Gene", LETTERS[1:3]), paste("Gene", LETTERS[1:5])), |
64 | 64 |
#' list(function(oracle){}), NULL, predicted, actual) |
65 | 65 |
#' |
... | ... |
@@ -67,7 +67,7 @@ |
67 | 67 |
#' predicted[c(2, 6), "Cancer"] <- c(0.60, 0.40) |
68 | 68 |
#' result2 <- ClassifyResult(DataFrame(characteristic = c("Data Set", "Selection Name", "Classifier Name", "Cross-validation"), |
69 | 69 |
#' value = c("Example", "Bartlett Test", "Differential Variability", "2-fold")), |
70 |
-#' LETTERS[1:20], list(paste("Gene", LETTERS[1:10]), paste("Gene", LETTERS[c(5:1, 6:10)])), |
|
70 |
+#' LETTERS[1:20], paste("Gene", LETTERS[1:10]), list(paste("Gene", LETTERS[1:10]), paste("Gene", LETTERS[c(5:1, 6:10)])), |
|
71 | 71 |
#' list(paste("Gene", LETTERS[1:3]), paste("Gene", LETTERS[1:5])), |
72 | 72 |
#' list(function(oracle){}), NULL, predicted, actual) |
73 | 73 |
#' ROCplot(list(result1, result2), plotTitle = "Cancer ROC") |
... | ... |
@@ -5,13 +5,13 @@ |
5 | 5 |
#' known classes and a vector of predicted classes determined outside of the |
6 | 6 |
#' ClassifyR package, a single metric value is calculated. If |
7 | 7 |
#' \code{calcCVperformance} is used, annotates the results of calling |
8 |
-#' \code{\link{runTests}} with one of the user-specified performance measures. |
|
8 |
+#' \code{\link{crossValidate}} with one of the user-specified performance measures. |
|
9 | 9 |
#' |
10 | 10 |
#' All metrics except Matthews Correlation Coefficient are suitable for |
11 | 11 |
#' evaluating classification scenarios with more than two classes and are |
12 | 12 |
#' reimplementations of those available from Intel DAAL. |
13 | 13 |
#' |
14 |
-#' If \code{\link{runTests}} was run in resampling mode, one performance |
|
14 |
+#' If \code{\link{crossValidate}} was run in resampling mode, one performance |
|
15 | 15 |
#' measure is produced for every resampling. If the leave-k-out mode was used, |
16 | 16 |
#' then the predictions are concatenated, and one performance measure is |
17 | 17 |
#' calculated for all classifications. |
... | ... |
@@ -75,7 +75,7 @@ |
75 | 75 |
#' class = factor(sample(LETTERS[1:2], 50, replace = TRUE))) |
76 | 76 |
#' actual <- factor(sample(LETTERS[1:2], 10, replace = TRUE)) |
77 | 77 |
#' result <- ClassifyResult(DataFrame(characteristic = "Data Set", value = "Example"), |
78 |
-#' paste("A", 1:10, sep = ''), list(paste("Gene", 1:50), paste("Gene", 1:50)), list(paste("Gene", 1:5), paste("Gene", 1:10)), |
|
78 |
+#' paste("A", 1:10, sep = ''), paste("Gene", 1:50), list(paste("Gene", 1:50), paste("Gene", 1:50)), list(paste("Gene", 1:5), paste("Gene", 1:10)), |
|
79 | 79 |
#' list(function(oracle){}), NULL, predictTable, actual) |
80 | 80 |
#' result <- calcCVperformance(result) |
81 | 81 |
#' performance(result) |
... | ... |
@@ -12,105 +12,35 @@ |
12 | 12 |
|
13 | 13 |
|
14 | 14 |
# Delete when sparsediscrim is restored to CRAN. |
15 |
-#' Trained dlda Object |
|
16 |
-#' |
|
17 |
-#' Enables S4 method dispatching on it. |
|
18 |
-#' |
|
19 |
-#' |
|
20 |
-#' @name dlda-class |
|
21 |
-#' @aliases dlda dlda-class |
|
22 |
-#' @docType class |
|
23 |
-#' @author Dario Strbenac |
|
24 |
-#' @usage NULL |
|
15 |
+# Trained dlda Object |
|
25 | 16 |
dlda <- function(x, ...) { |
26 | 17 |
UseMethod("dlda") |
27 | 18 |
} |
28 |
- |
|
29 | 19 |
setOldClass("dlda") |
30 | 20 |
|
31 |
- |
|
32 |
-#' Trained pamr Object |
|
33 |
-#' |
|
34 |
-#' Enables S4 method dispatching on it. |
|
35 |
-#' |
|
36 |
-#' |
|
37 |
-#' @name pamrtrained-class |
|
38 |
-#' @aliases pamrtrained pamrtrained-class |
|
39 |
-#' @docType class |
|
40 |
-#' @author Dario Strbenac |
|
21 |
+# Trained pamr Object |
|
41 | 22 |
setOldClass("pamrtrained") |
42 | 23 |
|
43 | 24 |
|
44 |
-#' Trained svm Object |
|
45 |
-#' |
|
46 |
-#' Enables S4 method dispatching on it. |
|
47 |
-#' |
|
48 |
-#' |
|
49 |
-#' @name svm-class |
|
50 |
-#' @aliases svm svm-class |
|
51 |
-#' @docType class |
|
52 |
-#' @author Dario Strbenac |
|
25 |
+# Trained svm Object |
|
53 | 26 |
setOldClass("svm") |
54 | 27 |
|
55 |
-#' Trained multnet Object |
|
56 |
-#' |
|
57 |
-#' Enables S4 method dispatching on it. |
|
58 |
-#' |
|
59 |
-#' |
|
60 |
-#' @name multnet-class |
|
61 |
-#' @aliases multnet multnet-class |
|
62 |
-#' @docType class |
|
63 |
-#' @author Dario Strbenac |
|
28 |
+# Trained multnet Object |
|
64 | 29 |
setOldClass("multnet") |
65 | 30 |
|
66 |
-#' @name coxnet-class |
|
67 |
-#' @aliases coxnet coxnet-class |
|
68 |
-#' @docType class |
|
69 |
-#' @author Dario Strbenac |
|
31 |
+# Trained coxnet Object |
|
70 | 32 |
setOldClass("coxnet") |
71 | 33 |
|
72 |
- |
|
73 |
- |
|
74 |
-#' Trained randomForest Object |
|
75 |
-#' |
|
76 |
-#' Enables S4 method dispatching on it. |
|
77 |
-#' |
|
78 |
-#' |
|
79 |
-#' @name randomForest-class |
|
80 |
-#' @aliases randomForest randomForest-class |
|
81 |
-#' @docType class |
|
82 |
-#' @author Dario Strbenac |
|
34 |
+# Trained randomForest Object |
|
83 | 35 |
setOldClass("randomForest") |
84 | 36 |
|
85 |
- |
|
86 |
-#' Trained coxph Object |
|
87 |
-#' |
|
88 |
-#' Enables S4 method dispatching on it. |
|
89 |
-#' |
|
90 |
-#' |
|
91 |
-#' @name coxph-class |
|
92 |
-#' @aliases coxph coxph-class |
|
93 |
-#' @docType class |
|
37 |
+# Trained coxph Object |
|
94 | 38 |
setOldClass("coxph") |
95 | 39 |
|
96 |
-#' Survival Data Container |
|
97 |
-#' |
|
98 |
-#' Enables S4 method dispatching on it. |
|
99 |
-#' |
|
100 |
-#' |
|
101 |
-#' @name Surv-class |
|
102 |
-#' @aliases Surv Surv-class |
|
103 |
-#' @docType class |
|
40 |
+# Survival Data Container |
|
104 | 41 |
setOldClass("Surv") |
105 | 42 |
|
106 |
-#' Survival Forest Data Container |
|
107 |
-#' |
|
108 |
-#' Enables S4 method dispatching on it. |
|
109 |
-#' |
|
110 |
-#' |
|
111 |
-#' @name rfsrc-class |
|
112 |
-#' @aliases rfsrc rfsrc-class |
|
113 |
-#' @docType class |
|
43 |
+# Survival Forest Data Container |
|
114 | 44 |
setOldClass("rfsrc") |
115 | 45 |
|
116 | 46 |
################################################################################ |
... | ... |
@@ -120,122 +50,29 @@ setOldClass("rfsrc") |
120 | 50 |
################################################################################ |
121 | 51 |
|
122 | 52 |
|
123 |
-#' Union of A Function and NULL |
|
124 |
-#' |
|
125 |
-#' Allows a slot to be either a function or empty. |
|
126 |
-#' |
|
127 |
-#' |
|
128 |
-#' @name functionOrNULL-class |
|
129 |
-#' @aliases functionOrNULL functionOrNULL-class |
|
130 |
-#' @docType class |
|
131 |
-#' @author Dario Strbenac |
|
132 |
-#' @examples |
|
133 |
-#' |
|
134 |
-#' PredictParams(NULL) # Training function does both tasks. |
|
135 |
-#' PredictParams(DLDApredictInterface) |
|
136 |
-#' |
|
53 |
+# Union of A Function and NULL |
|
137 | 54 |
setClassUnion("functionOrNULL", c("function", "NULL")) |
138 | 55 |
|
139 |
-#' Union of Functions and List of Functions |
|
140 |
-#' |
|
141 |
-#' Allows a slot to be either a function or a list of functions. |
|
142 |
-#' |
|
143 |
-#' |
|
144 |
-#' @name functionOrList-class |
|
145 |
-#' @aliases functionOrList functionOrList-class |
|
146 |
-#' @docType class |
|
147 |
-#' @author Dario Strbenac |
|
148 |
-#' @examples |
|
149 |
-#' |
|
150 |
-#' SelectParams(limmaRanking) |
|
151 |
-#' SelectParams(list(limmaRanking, differentMeansRanking)) # Ensemble selection. |
|
152 |
-#' |
|
56 |
+# Union of Functions and List of Functions. Useful for allowing ensemble feature selection. |
|
153 | 57 |
setClassUnion("functionOrList", c("function", "list")) |
154 | 58 |
|
155 | 59 |
|
156 |
-#' Union of A Numeric Value and NULL |
|
157 |
-#' |
|
158 |
-#' Allows a slot to be either a numeric value or empty. No constructor. |
|
159 |
-#' |
|
160 |
-#' |
|
161 |
-#' @name numericOrNULL-class |
|
162 |
-#' @aliases numericOrNULL numericOrNULL-class |
|
163 |
-#' @docType class |
|
164 |
-#' @author Dario Strbenac |
|
60 |
+# Union of A Numeric Value and NULL |
|
165 | 61 |
setClassUnion("numericOrNULL", c("numeric", "NULL")) |
166 | 62 |
|
167 |
- |
|
168 |
-#' Union of a Character and a DataFrame |
|
169 |
-#' |
|
170 |
-#' Allows a slot to be either a character or a DataFrame. |
|
171 |
-#' |
|
172 |
-#' |
|
173 |
-#' @name characterOrDataFrame-class |
|
174 |
-#' @aliases characterOrDataFrame characterOrDataFrame-class |
|
175 |
-#' @docType class |
|
176 |
-#' @author Dario Strbenac |
|
177 |
-#' @examples |
|
178 |
-#' |
|
179 |
-#' setClass("Selections", representation(features = "characterOrDataFrame")) |
|
180 |
-#' selections <- new("Selections", features = c("BRAF", "NRAS")) |
|
181 |
-#' featuresTable <- DataFrame(assay = c("RNA-seq", "Mass spectrometry"), |
|
182 |
-#' feature = c("PD-1", "MITF")) |
|
183 |
-#' omicsSelections <- new("Selections", features = featuresTable) |
|
63 |
+# Union of a Character and a DataFrame |
|
184 | 64 |
setClassUnion("characterOrDataFrame", c("character", "DataFrame")) |
185 | 65 |
|
186 |
-#' Union of a Surv class and a factor |
|
187 |
-#' |
|
188 |
-#' Enables different functionality to be executed depending on whether |
|
189 |
-#' input data dependent variable is survival or categorical classes. |
|
190 |
-#' |
|
191 |
-#' |
|
192 |
-#' @name characterOrDataFrame-class |
|
193 |
-#' @aliases characterOrDataFrame characterOrDataFrame-class |
|
194 |
-#' @docType class |
|
195 |
-#' @author Dario Strbenac |
|
196 |
-#' @examples |
|
197 |
-#' |
|
198 |
-#' setClass("Selections", representation(features = "characterOrDataFrame")) |
|
199 |
-#' selections <- new("Selections", features = c("BRAF", "NRAS")) |
|
200 |
-#' featuresTable <- DataFrame(assay = c("RNA-seq", "Mass spectrometry"), |
|
201 |
-#' feature = c("PD-1", "MITF")) |
|
202 |
-#' omicsSelections <- new("Selections", features = featuresTable) |
|
66 |
+# Union of a Surv class and a factor |
|
203 | 67 |
setClassUnion("factorOrSurv", c("factor", "Surv")) |
204 | 68 |
|
205 |
- |
|
206 |
- |
|
207 |
-#' Union of a List and NULL |
|
208 |
-#' |
|
209 |
-#' Allows a slot to be either a list or a NULL. |
|
210 |
-#' |
|
211 |
-#' |
|
212 |
-#' @name listOrNULL-class |
|
213 |
-#' @aliases listOrNULL listOrNULL-class |
|
214 |
-#' @docType class |
|
215 |
-#' @author Dario Strbenac |
|
216 |
-#' @examples |
|
217 |
-#' |
|
218 |
-#' setClass("EasyClassifier", representation(model = "listOrNULL")) |
|
219 |
-#' classifier <- new("EasyClassifier", model = NULL) # Optimistic classifier. |
|
220 |
-#' |
|
69 |
+# Union of a List and NULL |
|
221 | 70 |
setClassUnion("listOrNULL", c("list", "NULL")) |
222 | 71 |
|
223 |
-#' Union of NULL and DataFrame Class |
|
224 |
-#' |
|
225 |
-#' Allows cross-validation to accept data as either a \code{DataFrame} (for a |
|
226 |
-#' single data set) or \code{DataFrameList} (for a list of tables of related |
|
227 |
-#' measurements, such as different projects measuring the same outcome and the |
|
228 |
-#' same kind of measurements). No constructor. |
|
229 |
-#' |
|
230 |
-#' |
|
231 |
-#' @name DataFrameOrNULL-class |
|
232 |
-#' @aliases DataFrameOrNULL DataFrameOrNULL-class |
|
233 |
-#' @docType class |
|
234 |
-#' @author Dario Strbenac |
|
72 |
+# Union of NULL and DataFrame Class |
|
235 | 73 |
setClassUnion("DataFrameOrNULL", c("DataFrame", "NULL")) |
236 | 74 |
|
237 | 75 |
|
238 |
- |
|
239 | 76 |
################################################################################ |
240 | 77 |
# |
241 | 78 |
# Params |
... | ... |
@@ -244,56 +81,8 @@ setClassUnion("DataFrameOrNULL", c("DataFrame", "NULL")) |
244 | 81 |
|
245 | 82 |
##### CrossValParams ##### |
246 | 83 |
|
247 |
-#' Parameters for Cross-validation Specification |
|
248 |
-#' |
|
249 |
-#' Collects and checks necessary parameters required for cross-validation by |
|
250 |
-#' \code{\link{runTests}}. |
|
251 |
-#' |
|
252 |
-#' |
|
253 |
-#' @name CrossValParams |
|
254 |
-#' @rdname CrossValParams-class |
|
255 |
-#' @aliases CrossValParams CrossValParams-class |
|
256 |
-#' @docType class |
|
257 |
-#' |
|
258 |
-#' @param samplesSplits Default: "Permute k-Fold". A character value |
|
259 |
-#' specifying what kind of sample splitting to do. |
|
260 |
-#' @param permutations Default: 100. Number of times to permute the |
|
261 |
-#' data set before it is split into training and test sets. Only relevant if |
|
262 |
-#' \code{samplesSplits} is either \code{"Permute k-Fold"} or \code{"Permute |
|
263 |
-#' Percentage Split"}. |
|
264 |
-#' @param percentTest The percentage of the data |
|
265 |
-#' set to assign to the test set, with the remainder of the samples belonging |
|
266 |
-#' to the training set. Only relevant if \code{samplesSplits} is \code{"Permute |
|
267 |
-#' Percentage Split"}. |
|
268 |
-#' @param folds The number of approximately equal-sized folds to partition |
|
269 |
-#' the samples into. Only relevant if \code{samplesSplits} is \code{"Permute k-Fold"} |
|
270 |
-#' or \code{"k-Fold"}. |
|
271 |
-#' @param leave The number of samples to generate all possible |
|
272 |
-#' combination of and use as the test set. Only relevant if \code{samplesSplits} is |
|
273 |
-#' \code{"Leave-k-Out"}. If set to 1, it is the traditional leave-one-out cross-validation, |
|
274 |
-#' sometimes written as LOOCV. |
|
275 |
-#' @param tuneMode Default: Resubstitution. The scheme to use for selecting any tuning parameters. |
|
276 |
-#' @param adaptiveResamplingDelta Default: \code{NULL}. If not null, adaptive resampling of training |
|
277 |
-#' samples is performed and this number is the difference in consecutive iterations that the |
|
278 |
-#' class probability or risk of all samples must change less than for the iterative process to stop. 0.01 |
|
279 |
-#' was used in the original publication. |
|
280 |
-#' @param parallelParams An instance of \code{\link{BiocParallelParam}} specifying |
|
281 |
-#' the kind of parallelisation to use. Default is to use two cores less than the total number of |
|
282 |
-#' cores the computer has, if it has four or more cores, otherwise one core, as is the |
|
283 |
-#' default of \code{\link{bpparam}}. To make results fully reproducible, please |
|
284 |
-#' choose a specific back-end depending on your operating system and also set |
|
285 |
-#' \code{RNGseed} to a number. |
|
286 |
-#' |
|
287 |
-#' @author Dario Strbenac |
|
288 |
-#' @examples |
|
289 |
-#' |
|
290 |
-#' CrossValParams() # Default is 100 permutations and 5 folds of each. |
|
291 |
-#' snow <- SnowParam(workers = 4, RNGseed = 999) |
|
292 |
-#' CrossValParams("Leave-k-Out", leave = 2, parallelParams = snow) |
|
293 |
-#' # Fully reproducible Leave-2-out cross-validation on 4 cores, |
|
294 |
-#' # even if feature selection or classifier use random sampling. |
|
295 |
-#' |
|
296 |
-#' @exportClass CrossValParams |
|
84 |
+# Parameters for Cross-validation Specification |
|
85 |
+ |
|
297 | 86 |
setClass("CrossValParams", representation( |
298 | 87 |
samplesSplits = "character", |
299 | 88 |
permutations = "numericOrNULL", |
... | ... |
@@ -306,9 +95,7 @@ setClass("CrossValParams", representation( |
306 | 95 |
) |
307 | 96 |
) |
308 | 97 |
|
309 |
-# CrossValParams constructor is an ordinary function for performance reasons. |
|
310 |
-#' @export |
|
311 |
-#' @rdname CrossValParams-class |
|
98 |
+# CrossValParams constructor is an ordinary function and not S4 method for performance reasons. |
|
312 | 99 |
CrossValParams <- function(samplesSplits = c("Permute k-Fold", "Permute Percentage Split", "Leave-k-Out", "k-Fold"), |
313 | 100 |
permutations = 100, percentTest = 25, folds = 5, leave = 2, |
314 | 101 |
tuneMode = c("Resubstitution", "Nested CV", "none"), adaptiveResamplingDelta = NULL, parallelParams = bpparam()) |
... | ... |
@@ -339,43 +126,18 @@ CrossValParams <- function(samplesSplits = c("Permute k-Fold", "Permute Percenta |
339 | 126 |
|
340 | 127 |
##### StageParams ##### |
341 | 128 |
|
342 |
-#' StageParams Virtual Class |
|
343 |
-#' |
|
344 |
-#' A class for any one of \code{\link{TransformParams}}, |
|
345 |
-#' \code{\link{SelectParams}}, \code{\link{TrainParams}} or |
|
346 |
-#' \code{\link{PredictParams}}. Allows a method to dispatch on any of the |
|
347 |
-#' parameter objects specifying any stage of cross-validation. |
|
348 |
-#' |
|
349 |
-#' |
|
350 |
-#' @name StageParams-class |
|
351 |
-#' @aliases StageParams StageParams-class |
|
352 |
-#' @author Dario Strbenac |
|
353 |
-setClass("StageParams", representation("VIRTUAL")) |
|
354 |
- |
|
129 |
+# StageParams Virtual Class. A class for any one of TransformParams, |
|
130 |
+# SelectParams, TrainParams, PredictParams. Allows a method to dispatch on |
|
131 |
+# any of the parameter objects specifying any stage of cross-validation. |
|
355 | 132 |
|
356 |
-#' Union of A StageParams Object and NULL |
|
357 |
-#' @name StageParamsOrMissing-class |
|
358 |
-#' @rdname StageParamsOrElse |
|
359 |
-#' @aliases StageParamsOrMissing StageParamsOrMissing-class |
|
360 |
-#' @author Dario Strbenac |
|
133 |
+setClass("StageParams", representation("VIRTUAL")) |
|
361 | 134 |
setClassUnion("StageParamsOrMissing", c("StageParams", "missing")) |
362 | 135 |
|
363 |
- |
|
364 |
-#' Union of A StageParams Object and NULL |
|
365 |
-#' |
|
366 |
-#' StageParamsOrMissing: Allows a slot to be either a class that has StageParams as its virtual |
|
367 |
-#' parent class or empty. No constructor. |
|
368 |
-#' StageParamsOrMissingOrNULL: Allows a slot to be either a class that has StageParams as its virtual |
|
369 |
-#' parent class or empty or NULL. No constructor. |
|
370 |
-#' |
|
371 |
-#' @name StageParamsOrMissingOrNULL-class |
|
372 |
-#' @rdname StageParamsOrElse |
|
373 |
-#' @aliases StageParamsOrMissingOrNULL StageParamsOrMissingOrNULL-class |
|
136 |
+# Union of a StageParams object and NULL for parameter that's optional. |
|
374 | 137 |
setClassUnion("StageParamsOrMissingOrNULL", c("StageParams", "missing", "NULL")) |
375 | 138 |
|
376 | 139 |
|
377 | 140 |
##### TransformParams ##### |
378 |
-#' @exportClass TransformParams |
|
379 | 141 |
setClass("TransformParams", representation( |
380 | 142 |
transform = "function", |
381 | 143 |
characteristics = "DataFrame", |
... | ... |
@@ -383,80 +145,14 @@ setClass("TransformParams", representation( |
383 | 145 |
otherParams = "list"), contains = "StageParams" |
384 | 146 |
) |
385 | 147 |
|
386 |
-#' Union of A TransformParams Object and NULL |
|
387 |
-#' |
|
388 |
-#' Allows a slot to be either a TransformParams class object or empty. No |
|
389 |
-#' constructor. |
|
390 |
-#' |
|
391 |
-#' |
|
392 |
-#' @name TransformParamsOrNULL-class |
|
393 |
-#' @aliases TransformParamsOrNULL TransformParamsOrNULL-class |
|
394 |
-#' @docType class |
|
395 |
-#' @author Dario Strbenac |
|
396 |
-#' @examples |
|
397 |
-#' |
|
398 |
-#' ModellingParams(transformParams = NULL) |
|
399 |
-#' ModellingParams(transformParams = TransformParams(subtractFromLocation), |
|
400 |
-#' selectParams = SelectParams(leveneRanking)) |
|
401 |
-#' |
|
148 |
+# Union of a TransformParams pbject and NULL. |
|
402 | 149 |
setClassUnion("TransformParamsOrNULL", c("TransformParams", "NULL")) |
403 | 150 |
|
151 |
+# Parameters for Data Transformation within CV. |
|
404 | 152 |
|
405 |
-#' Parameters for Data Transformation |
|
406 |
-#' |
|
407 |
-#' Collects and checks necessary parameters required for transformation within CV. The |
|
408 |
-#' empty constructor is for when no data transformation is desired. See |
|
409 |
-#' \code{\link{subtractFromLocation}} for an example of such a function. |
|
410 |
-#' |
|
411 |
-#' |
|
412 |
-#' @name TransformParams |
|
413 |
-#' @rdname TransformParams-class |
|
414 |
-#' @aliases TransformParams TransformParams-class TransformParams,ANY-method |
|
415 |
-#' TransformParams,function-method show,TransformParams-method |
|
416 |
-#' @docType class |
|
417 |
-#' @usage NULL |
|
418 |
-#' @section Constructor: |
|
419 |
-#' \describe{ |
|
420 |
-#' \item{}{ |
|
421 |
-#' \code{TransformParams(transform, characteristics = DataFrame(), intermediate = character(0), ...)} |
|
422 |
-#' Creates a \code{TransformParams} object which stores the function which will do the |
|
423 |
-#' transformation and parameters that the function will use. |
|
424 |
-#' \describe{ |
|
425 |
-#' \item{\code{transform}}{A function which will do the transformation. The |
|
426 |
-#' first argument must be a \code{\link{DataFrame}} object.} |
|
427 |
-#' \item{\code{characteristics}}{A \code{\link{DataFrame}} describing the |
|
428 |
-#' characteristics of data transformation to be done. First column must be |
|
429 |
-#' named \code{"charateristic"} and second column must be named \code{"value"}. |
|
430 |
-#' If using wrapper functions for data transformation in this package, the data |
|
431 |
-#' transformation name will automatically be generated and therefore it is not |
|
432 |
-#' necessary to specify it.} |
|
433 |
-#' \item{\code{intermediate}}{Character vector. Names of any variables created in |
|
434 |
-#' prior stages by \code{\link{runTest}} that need to be passed to a feature selection |
|
435 |
-#' function.} |
|
436 |
-#' \item{\code{...}}{Other named parameters which will be used by the transformation function.} |
|
437 |
-#' } } } |
|
438 |
-#' |
|
439 |
-#' @section Summary: |
|
440 |
-#' \code{transformParams} is a \code{TransformParams} object. |
|
441 |
-#' \describe{ |
|
442 |
-#' \item{}{ |
|
443 |
-#' \code{show(transformParams)}: Prints a short summary of what \code{transformParams} contains. |
|
444 |
-#' }} |
|
445 |
-#' |
|
446 |
-#' @author Dario Strbenac |
|
447 |
-#' @examples |
|
448 |
-#' |
|
449 |
-#' transformParams <- TransformParams(subtractFromLocation, location = "median") |
|
450 |
-#' # Subtract all values from training set median, to obtain absolute deviations. |
|
451 |
-#' |
|
452 |
-#' @export |
|
453 |
-#' @usage NULL |
|
454 | 153 |
setGeneric("TransformParams", function(transform, ...) |
455 | 154 |
standardGeneric("TransformParams")) |
456 | 155 |
|
457 |
-#' @rdname TransformParams-class |
|
458 |
-#' @usage NULL |
|
459 |
-#' @export |
|
460 | 156 |
setMethod("TransformParams", "function", |
461 | 157 |
function(transform, characteristics = S4Vectors::DataFrame(), intermediate = character(0), ...) |
462 | 158 |
{ |
... | ... |
@@ -468,8 +164,10 @@ setMethod("TransformParams", "function", |
468 | 164 |
intermediate = intermediate, otherParams = list(...)) |
469 | 165 |
}) |
470 | 166 |
|
471 |
-#' @usage NULL |
|
167 |
+#' Inspect Data Transformation Details |
|
168 |
+#' |
|
472 | 169 |
#' @rdname TransformParams-class |
170 |
+#' @param object An object of class \code{TransformParams} to inspect. |
|
473 | 171 |
#' @export |
474 | 172 |
setMethod("show", "TransformParams", |
475 | 173 |
function(object) |
... | ... |
@@ -492,6 +190,7 @@ setMethod("show", "TransformParams", |
492 | 190 |
##### FeatureSetCollection ##### |
493 | 191 |
#' @docType class |
494 | 192 |
#' @exportClass FeatureSetCollection |
193 |
+#' @rdname FeatureSetCollection |
|
495 | 194 |
setClass("FeatureSetCollection", representation(sets = "list")) |
496 | 195 |
#' |
497 | 196 |
#' Container for Storing A Collection of Sets |
... | ... |
@@ -601,6 +300,7 @@ setMethod("length", c("FeatureSetCollection"), |
601 | 300 |
}) |
602 | 301 |
|
603 | 302 |
#' @usage NULL |
303 |
+#' @rdname FeatureSetCollection |
|
604 | 304 |
#' @export |
605 | 305 |
setMethod("show", "FeatureSetCollection", |
606 | 306 |
function(object) |
... | ... |
@@ -673,7 +373,6 @@ setMethod("show", "FeatureSetCollection", |
673 | 373 |
} |
674 | 374 |
) |
675 | 375 |
|
676 |
-#' @usage NULL |
|
677 | 376 |
#' @export |
678 | 377 |
setMethod("[", c("FeatureSetCollection", "numeric", "missing", "ANY"), |
679 | 378 |
function(x, i, j, ..., drop = TRUE) |
... | ... |
@@ -681,7 +380,6 @@ setMethod("[", c("FeatureSetCollection", "numeric", "missing", "ANY"), |
681 | 380 |
new("FeatureSetCollection", sets = x@sets[i]) |
682 | 381 |
}) |
683 | 382 |
|
684 |
-#' @usage NULL |
|
685 | 383 |
#' @export |
686 | 384 |
setMethod("[[", c("FeatureSetCollection", "ANY", "missing"), |
687 | 385 |
function(x, i, j, ...) |
... | ... |
@@ -689,29 +387,10 @@ setMethod("[[", c("FeatureSetCollection", "ANY", "missing"), |
689 | 387 |
x@sets[[i]] |
690 | 388 |
}) |
691 | 389 |
|
692 |
- |
|
693 |
-#' Union of a FeatureSetCollection and NULL |
|
694 |
-#' |
|
695 |
-#' Allows a slot to be either a FeatureSetCollectionOrNULL object or empty. |
|
696 |
-#' |
|
697 |
-#' |
|
698 |
-#' @name FeatureSetCollectionOrNULL-class |
|
699 |
-#' @aliases FeatureSetCollectionOrNULL FeatureSetCollectionOrNULL-class |
|
700 |
-#' @docType class |
|
701 |
-#' @author Dario Strbenac |
|
702 |
-#' @examples |
|
703 |
-#' |
|
704 |
-#' TrainParams(DLDAtrainInterface, transform = NULL) # Use the input data as-is. |
|
705 |
-#' |
|
706 | 390 |
setClassUnion("FeatureSetCollectionOrNULL", c("FeatureSetCollection", "NULL")) |
707 | 391 |
|
708 |
- |
|
709 |
- |
|
710 |
- |
|
711 |
- |
|
712 | 392 |
##### SelectParams ##### |
713 | 393 |
|
714 |
-#' @exportClass SelectParams |
|
715 | 394 |
setClass("SelectParams", representation( |
716 | 395 |
featureRanking = "functionOrList", |
717 | 396 |
characteristics = "DataFrame", |
... | ... |
@@ -722,97 +401,13 @@ setClass("SelectParams", representation( |
722 | 401 |
otherParams = "listOrNULL"), contains = "StageParams" |
723 | 402 |
) |
724 | 403 |
|
725 |
- |
|
726 |
-#' Union of A SelectParams Object and NULL |
|
727 |
-#' |
|
728 |
-#' Allows a slot to be either a SelectParams class object or empty. No |
|
729 |
-#' constructor. |
|
730 |
-#' |
|
731 |
-#' |
|
732 |
-#' @name SelectParamsOrNULL-class |
|
733 |
-#' @aliases SelectParamsOrNULL SelectParamsOrNULL-class |
|
734 |
-#' @docType class |
|
735 |
-#' @author Dario Strbenac |
|
736 |
-#' @examples |
|
737 |
-#' |
|
738 |
-#' ModellingParams(selectParams = NULL) |
|
739 |
-#' ModellingParams(selectParams = SelectParams(differentMeansRanking)) |
|
740 |
-#' |
|
741 | 404 |
setClassUnion("SelectParamsOrNULL", c("SelectParams", "NULL")) |
742 | 405 |
|
743 |
- |
|
744 |
-#' Parameters for Feature Selection |
|
745 |
-#' |
|
746 |
-#' Collects and checks necessary parameters required for feature selection. |
|
747 |
-#' Either one function is specified or a list of functions to perform ensemble |
|
748 |
-#' feature selection. The empty constructor is provided for convenience. |
|
749 |
-#' |
|
750 |
-#' |
|
751 |
-#' @name SelectParams |
|
752 |
-#' @rdname SelectParams-class |
|
753 |
-#' @aliases SelectParams SelectParams-class SelectParams,missing-method |
|
754 |
-#' SelectParams,functionOrList-method |
|
755 |
-#' @docType class |
|
756 |
-#' @section Constructor: |
|
757 |
-#' \describe{ \item{}{ |
|
758 |
-#' \code{SelectParams()} Creates a default \code{SelectParams} object. This uses either |
|
759 |
-#' an ordinary t-test or ANOVA (depending on the number of classes) and tries the |
|
760 |
-#' top 10 to top 100 features in increments of 10, and picks the number of features |
|
761 |
-#' with the best resubstitution balanced error rate. Users should create an appropriate |
|
762 |
-#' \code{SelectParams} object for the characteristics of their data.} |
|
763 |
-#' \item{}{\preformatted{SelectParams(featureSelection, characteristics = DataFrame(), minPresence = 1, intermediate = character(0), |
|
764 |
-#' subsetToSelections = TRUE, tuneParams = list(nFeatures = seq(10, 100, 10), performanceType = "Balanced Error"), ...)} Creates a \code{SelectParams} |
|
765 |
-#' object which stores the function(s) which will do the selection and parameters that the |
|
766 |
-#' function will use. |
|
767 |
-#' \describe{\item{\code{featureRanking}}{Either a function which will rank the features |
|
768 |
-#' from most promising to least promising or a list of such functions. For a particular function, |
|
769 |
-#' the first argument must be an \code{\link{DataFrame}} object. The function's return value must |
|
770 |
-#' be a vector of indices.} |
|
771 |
-#' \item{\code{characteristics}}{A \code{\link{DataFrame}} describing the characteristics |
|
772 |
-#' of feature selection to be done. First column must be named \code{"charateristic"} and |
|
773 |
-#' second column must be named \code{"value"}. If using wrapper functions for feature |
|
774 |
-#' selection in this package, the feature selection name will automatically be |
|
775 |
-#' generated and therefore it is not necessary to specify it.} |
|
776 |
-#' \item{\code{minPresence}}{If a list of functions was provided, how many of |
|
777 |
-#' those must a feature have been selected by to be used in classification. 1 |
|
778 |
-#' is equivalent to a set union and a number the same length as |
|
779 |
-#' \code{featureSelection} is equivalent to set intersection.} |
|
780 |
-#' \item{\code{intermediate}}{Character vector. Names of any variables created |
|
781 |
-#' in prior stages by \code{\link{runTest}} that need to be passed to a feature |
|
782 |
-#' selection function.} |
|
783 |
-#' \item{\code{subsetToSelections}}{Whether to subset the data table(s), after feature selection has been done.} |
|
784 |
-#' \item{\code{tuneParams}}{A list specifying tuning parameters required during feature selection. The names of |
|
785 |
-#' the list are the names of the parameters and the vectors are the values of the parameters to try. All possible |
|
786 |
-#' combinations are generated. Two elements named \code{nFeatures} and \code{performanceType} are mandatory, to |
|
787 |
-#' define the performance metric which will be used to select features and how many top-ranked features to try.} |
|
788 |
-#' \item{\code{...}}{Other named parameters which will be used by the |
|
789 |
-#' selection function. If \code{featureSelection} was a list of functions, |
|
790 |
-#' this must be a list of lists, as long as \code{featureSelection}.} } } } |
|
791 |
-#' @section Summary: |
|
792 |
-#' \code{selectParams} is a \code{SelectParams} object. |
|
793 |
-#' \describe{ |
|
794 |
-#' \item{}{ |
|
795 |
-#' \code{show(SelectParams)}: Prints a short summary of what \code{selectParams} contains. |
|
796 |
-#' }} |
|
797 |
-#' @author Dario Strbenac |
|
798 |
-#' @examples |
|
799 |
-#' |
|
800 |
-#' #if(require(sparsediscrim)) |
|
801 |
-#' #{ |
|
802 |
-#' SelectParams(differentMeansRanking) |
|
803 |
-#' |
|
804 |
-#' # Ensemble feature selection. |
|
805 |
-#' SelectParams(list(differentMeansRanking, pairsDifferencesRanking)) |
|
806 |
-#' #} |
|
807 |
-#' |
|
808 |
-#' @export |
|
809 |
-#' @usage NULL |
|
406 |
+# Parameters for Feature Selection |
|
810 | 407 |
setGeneric("SelectParams", function(featureRanking, ...) |
811 | 408 |
standardGeneric("SelectParams")) |
812 | 409 |
|
813 |
-#' @rdname SelectParams-class |
|
814 |
-#' @usage NULL |
|
815 |
-#' @export |
|
410 |
+# Default constructor. |
|
816 | 411 |
setMethod("SelectParams", "missing", function() |
817 | 412 |
{ |
818 | 413 |
new("SelectParams", featureRanking = differentMeansRanking, |
... | ... |
@@ -820,9 +415,7 @@ setMethod("SelectParams", "missing", function() |
820 | 415 |
minPresence = 1, intermediate = character(0), subsetToSelections = TRUE, |
821 | 416 |
tuneParams = list(nFeatures = seq(10, 100, 10), performanceType = "Balanced Error")) |
822 | 417 |
}) |
823 |
-#' @rdname SelectParams-class |
|
824 |
-#' @usage NULL |
|
825 |
-#' @export |
|
418 |
+ |
|
826 | 419 |
setMethod("SelectParams", c("functionOrList"), |
827 | 420 |
function(featureRanking, characteristics = DataFrame(), minPresence = 1, |
828 | 421 |
intermediate = character(0), subsetToSelections = TRUE, tuneParams = list(nFeatures = seq(10, 100, 10), performanceType = "Balanced Error"), ...) |
... | ... |
@@ -844,8 +437,10 @@ setMethod("SelectParams", c("functionOrList"), |
844 | 437 |
tuneParams = tuneParams, otherParams = others) |
845 | 438 |
}) |
846 | 439 |
|
847 |
-#' @usage NULL |
|
440 |
+#' Container for Storing Details of Feature Selection Function(s) |
|
441 |
+#' |
|
848 | 442 |
#' @rdname SelectParams-class |
443 |
+#' @param object An object of class \code{SelectParams} to inspect. |
|
849 | 444 |
#' @export |
850 | 445 |
setMethod("show", "SelectParams", |
851 | 446 |
function(object) |
... | ... |
@@ -873,84 +468,17 @@ setMethod("show", "SelectParams", |
873 | 468 |
|
874 | 469 |
##### TrainParams ##### |
875 | 470 |
|
876 |
-#' @exportClass TrainParams |
|
877 | 471 |
setClass("TrainParams", representation( |
878 | 472 |
classifier = "function", |
879 | 473 |
characteristics = "DataFrame", |
880 | 474 |
intermediate = "character", |
881 | 475 |
tuneParams = "listOrNULL", |
882 | 476 |
otherParams = "listOrNULL", |
883 |
- getFeatures = "functionOrNULL" |
|
884 |
-), contains = "StageParams" |
|
885 |
-) |
|
886 |
- |
|
477 |
+ getFeatures = "functionOrNULL"), contains = "StageParams") |
|
887 | 478 |
|
888 |
-#' Parameters for Classifier Training |
|
889 |
-#' |
|
890 |
-#' Collects and checks necessary parameters required for classifier training. |
|
891 |
-#' The empty constructor is provided for convenience. |
|
892 |
-#' |
|
893 |
-#' |
|
894 |
-#' @name TrainParams |
|
895 |
-#' @rdname TrainParams-class |
|
896 |
-#' @aliases TrainParams TrainParams-class TrainParams,missing-method |
|
897 |
-#' TrainParams,function-method show,TrainParams-method |
|
898 |
-#' @docType class |
|
899 |
-#' @section Constructor: |
|
900 |
-#' \describe{ |
|
901 |
-#' \item{}{\code{TrainParams()} Creates a default \code{TrainParams} object. |
|
902 |
-#' The classifier function is \code{dlda} for Diagonal LDA. Users should create |
|
903 |
-#' an appropriate \code{TrainParams} object for the characteristics of their data, |
|
904 |
-#' once they are familiar with this software.} |
|
905 |
-#' \item{}{\preformatted{TrainParams(classifier, characteristics = DataFrame(), |
|
906 |
-#' intermediate = character(0), getFeatures = NULL, ...)} |
|
907 |
-#' Creates a \code{TrainParams} object which stores the function which will do the |
|
908 |
-#' classifier building and parameters that the function will use. |
|
909 |
-#' \describe{ |
|
910 |
-#' \item{\code{classifier}}{A function which will construct a classifier, and |
|
911 |
-#' also possibly make the predictions. The first argument must be a |
|
912 |
-#' \code{\link{DataFrame}} object. The second argument must be a vector of |
|
913 |
-#' classes. If the function also makes predictions and the value of the |
|
914 |
-#' \code{predictor} setting of \code{PredictParams} is therefore \code{NULL}, |
|
915 |
-#' the third argument must be a \code{DataFrame} of test data. The function |
|
916 |
-#' must also accept a parameter named \code{verbose}. The function's return |
|
917 |
-#' value can be either a trained classifier if the function only does training |
|
918 |
-#' or a vector or data frame of class predictions if it also does prediction |
|
919 |
-#' with the test set samples.} |
|
920 |
-#' \item{\code{characteristics}}{A \code{\link{DataFrame}} describing the |
|
921 |
-#' characteristics of the classifier used. First column must be named \code{"charateristic"} |
|
922 |
-#' and second column must be named \code{"value"}. If using wrapper functions for classifiers |
|
923 |
-#' in this package, a classifier name will automatically be generated and |
|
924 |
-#' therefore it is not necessary to specify it.} |
|
925 |
-#' \item{\code{intermediate}}{Character vector. Names of any variables created |
|
926 |
-#' in prior stages by \code{\link{runTest}} that need to be passed to |
|
927 |
-#' \code{classifier}.} |
|
928 |
-#' \item{\code{getFeatures}}{A function may be specified that extracts the selected |
|
929 |
-#' features from the trained model. This is relevant if using a classifier that does |
|
930 |
-#' feature selection within training (e.g. random forest). The function must return a |
|
931 |
-#' list of two vectors. The first vector contains the ranked features (or empty if the |
|
932 |
-#' training algorithm doesn't produce rankings) and the second vector contains the selected |
|
933 |
-#' features.} |
|
934 |
-#' \item{\code{...}}{Other named parameters which will be used by the classifier.} } } } |
|
935 |
-#' @section Summary: |
|
936 |
-#' \code{trainParams} is a \code{TrainParams} object. |
|
937 |
-#' \describe{ |
|
938 |
-#' \item{}{ |
|
939 |
-#' \code{show(trainParams)}: Prints a short summary of what \code{trainParams} contains. |
|
940 |
-#' }} |
|
941 |
-#' @author Dario Strbenac |
|
942 |
-#' @examples |
|
943 |
-#' |
|
944 |
-#' #if(require(sparsediscrim)) |
|
945 |
-#' trainParams <- TrainParams(DLDAtrainInterface) |
|
946 |
-#' |
|
947 |
-#' @usage NULL |
|
948 |
-#' @export |
|
479 |
+# Parameters for Classifier Training |
|
949 | 480 |
setGeneric("TrainParams", function(classifier, ...) standardGeneric("TrainParams")) |
950 | 481 |
|
951 |
-#' @usage NULL |
|
952 |
-#' @rdname TrainParams-class |
|
953 |
-#' @export |
|
954 | 482 |
setMethod("TrainParams", "missing", function() |
955 | 483 |
{ |
956 | 484 |
new("TrainParams", classifier = DLDAtrainInterface, |
... | ... |
@@ -958,9 +486,6 @@ setMethod("TrainParams", "missing", function() |
958 | 486 |
intermediate = character(0), getFeatures = NULL) |
959 | 487 |
}) |
960 | 488 |
|
961 |
-#' @usage NULL |
|
962 |
-#' @rdname TrainParams-class |
|
963 |
-#' @export |
|
964 | 489 |
setMethod("TrainParams", c("function"), |
965 | 490 |
function(classifier, balancing = c("downsample", "upsample", "none"), characteristics = DataFrame(), intermediate = character(0), tuneParams = NULL, getFeatures = NULL, ...) |
966 | 491 |
{ |
... | ... |
@@ -973,7 +498,10 @@ setMethod("TrainParams", c("function"), |
973 | 498 |
otherParams = list(...)) |
974 | 499 |
}) |
975 | 500 |
|
976 |
-#' @usage NULL |
|
501 |
+#' Inspect Model Training Details |
|
502 |
+#' |
|
503 |
+#' @rdname TrainParams-class |
|
504 |
+#' @param object An object of class \code{TrainParams} to inspect. |
|
977 | 505 |
#' @export |
978 | 506 |
setMethod("show", "TrainParams", |
979 | 507 |
function(object) |
... | ... |
@@ -995,7 +523,6 @@ setMethod("show", "TrainParams", |
995 | 523 |
|
996 | 524 |
##### PredictParams ##### |
997 | 525 |
|
998 |
-#' @exportClass PredictParams |
|
999 | 526 |
setClass("PredictParams", representation( |
1000 | 527 |
predictor = "functionOrNULL", |
1001 | 528 |
characteristics = "DataFrame", |
... | ... |
@@ -1003,63 +530,9 @@ setClass("PredictParams", representation( |
1003 | 530 |
otherParams = "listOrNULL"), contains = "StageParams" |
1004 | 531 |
) |
1005 | 532 |
|
1006 |
-#' Parameters for Classifier Prediction |
|
1007 |
-#' |
|
1008 |
-#' Collects the function to be used for making predictions and any associated |
|
1009 |
-#' parameters. |
|
1010 |
-#' |
|
1011 |
-#' The function specified must return either a factor vector of class |
|
1012 |
-#' predictions, or a numeric vector of scores for the second class, according |
|
1013 |
-#' to the levels of the class vector of the input data set, or a data frame |
|
1014 |
-#' which has two columns named class and score. |
|
1015 |
-#' |
|
1016 |
-#' |
|
1017 |
-#' @name PredictParams |
|
1018 |
-#' @rdname PredictParams-class |
|
1019 |
-#' @aliases PredictParams PredictParams-class PredictParams,missing-method |
|
1020 |
-#' PredictParams,functionOrNULL-method show,PredictParams-method |
|
1021 |
-#' @docType class |
|
1022 |
-#' @section Constructor: \describe{ \item{}{ \code{PredictParams()} Creates a |
|
1023 |
-#' default PredictParams object. This assumes that the object returned by the |
|
1024 |
-#' classifier has a list element named \code{"class"}. } \item{}{ |
|
1025 |
-#' \code{PredictParams(predictor, characteristics = DataFrame(), intermediate = |
|
1026 |
-#' character(0), ...)} Creates a PredictParams object which stores the function |
|
1027 |
-#' which will do the class prediction, if required, and parameters that the |
|
1028 |
-#' function will use. If the training function also makes predictions, this |
|
1029 |
-#' must be set to \code{NULL}. } \describe{ \item{\code{predictor}}{Either |
|
1030 |
-#' \code{NULL} or a function to make predictions with. If it is a function, |
|
1031 |
-#' then the first argument must accept the classifier made in the training |
|
1032 |
-#' step. The second argument must accept a \code{\link{DataFrame}} of new |
|
1033 |
-#' data.} \item{\code{characteristics}}{A \code{\link{DataFrame}} describing |
|
1034 |
-#' the characteristics of the predictor function used. First column must be |
|
1035 |
-#' named \code{"charateristic"} and second column must be named |
|
1036 |
-#' \code{"value"}.} \item{\code{intermediate}}{Character vector. Names of any |
|
1037 |
-#' variables created in prior stages in \code{\link{runTest}} that need to be |
|
1038 |
-#' passed to the prediction function.} \item{\code{...}}{Other arguments that |
|
1039 |
-#' \code{predictor} may use.} } } |
|
1040 |
-#' @section Summary: |
|
1041 |
-#' \code{predictParams} is a \code{PredictParams} object. |
|
1042 |
-#' \describe{ |
|
1043 |
-#' \item{}{ |
|
1044 |
-#' \code{show(predictParams)}: Prints a short summary of what \code{predictParams} contains. |
|
1045 |
-#' }} |
|
1046 |
-#' @author Dario Strbenac |
|
1047 |
-#' @examples |
|
1048 |
-#' |
|
1049 |
-#' predictParams <- PredictParams(predictor = DLDApredictInterface) |
|
1050 |
-#' # For prediction by trained object created by DLDA training function. |
|
1051 |
-#' PredictParams(predictor = NULL) |
|
1052 |
-#' # For when the training function also does prediction and directly returns the |
|
1053 |
-#' # predictions. |
|
1054 |
-#' |
|
1055 |
-#' @export |
|
1056 |
-#' @usage NULL |
|
1057 | 533 |
setGeneric("PredictParams", function(predictor, ...) |
1058 | 534 |
standardGeneric("PredictParams")) |
1059 | 535 |
|
1060 |
-#' @usage NULL |
|
1061 |
-#' @rdname PredictParams-class |
|
1062 |
-#' @export |
|
1063 | 536 |
setMethod("PredictParams", "missing", function() |
1064 | 537 |
{ |
1065 | 538 |
new("PredictParams", predictor = DLDApredictInterface, |
... | ... |
@@ -1067,9 +540,6 @@ setMethod("PredictParams", "missing", function() |
1067 | 540 |
intermediate = character(0), otherParams = NULL) |
1068 | 541 |
}) |
1069 | 542 |
|
1070 |
-#' @usage NULL |
|
1071 |
-#' @rdname PredictParams-class |
|
1072 |
-#' @export |
|
1073 | 543 |
setMethod("PredictParams", c("functionOrNULL"), |
1074 | 544 |
function(predictor, characteristics = DataFrame(), intermediate = character(0), ...) |
1075 | 545 |
{ |
... | ... |
@@ -1081,7 +551,10 @@ setMethod("PredictParams", c("functionOrNULL"), |
1081 | 551 |
intermediate = intermediate, otherParams = others) |
1082 | 552 |
}) |
1083 | 553 |
|
1084 |
-#' @usage NULL |
|
554 |
+#' Inspect Prediction Function Details |
|
555 |
+#' |
|
556 |
+#' @rdname PredictParams-class |
|
557 |
+#' @param object An object of class \code{TrainParams} to inspect. |
|
1085 | 558 |
#' @export |
1086 | 559 |
setMethod("show", "PredictParams", |
1087 | 560 |
function(object) |
... | ... |
@@ -1106,29 +579,8 @@ setMethod("show", "PredictParams", |
1106 | 579 |
cat("Prediction is done by function specified to TrainParams.\n") |
1107 | 580 |
}) |
1108 | 581 |
|
1109 |
- |
|
1110 |
- |
|
1111 |
- |
|
1112 |
- |
|
1113 |
- |
|
1114 |
-#' Union of A PredictParams Object and NULL |
|
1115 |
-#' |
|
1116 |
-#' Allows a slot to be either a PredictParams class object or empty. No |
|
1117 |
-#' constructor. In other words, the training function specified also makes |
|
1118 |
-#' predictions with the test set. |
|
1119 |
-#' |
|
1120 |
-#' |
|
1121 |
-#' @name PredictParamsOrNULL |
|
1122 |
-#' @aliases PredictParamsOrNULL PredictParamsOrNULL-class |
|
1123 |
-#' @docType class |
|
1124 |
-#' @author Dario Strbenac |
|
1125 |
-#' @examples |
|
1126 |
-#' |
|
1127 |
-#' ModellingParams(trainParams = TrainParams(kNNinterface, k = 5), predictParams = NULL) |
|
1128 |
-#' |
|
1129 | 582 |
setClassUnion("PredictParamsOrNULL", c("PredictParams", "NULL")) |
1130 | 583 |
|
1131 |
-#' @exportClass ModellingParams |
|
1132 | 584 |
setClass("ModellingParams", representation( |
1133 | 585 |
balancing = "character", |
1134 | 586 |
transformParams = "TransformParamsOrNULL", |
... | ... |
@@ -1138,45 +590,6 @@ setClass("ModellingParams", representation( |
1138 | 590 |
doImportance = "logical" |
1139 | 591 |
)) |
1140 | 592 |
|
1141 |
-##### ModellingParams ##### |
|
1142 |
- |
|
1143 |
-#' Parameters for Data Modelling Specification |
|
1144 |
-#' |
|
1145 |
-#' Collects and checks necessary parameters required for data modelling. Apart |
|
1146 |
-#' from data transfomation that needs to be done within cross-validation (e.g. |
|
1147 |
-#' \code{\link{subtractFromLocation}}), feature selection, model training and |
|
1148 |
-#' prediction, this container also stores a setting for class imbalance |
|
1149 |
-#' rebalancing. |
|
1150 |
-#' |
|
1151 |
-#' @name ModellingParams |
|
1152 |
-#' @rdname ModellingParams-class |
|
1153 |
-#' @aliases ModellingParams ModellingParams-class |
|
1154 |
-#' @docType class |
|
1155 |
-#' @param balancing Default: "downsample". A character value specifying what kind |
|
1156 |
-#' of class balancing to do, if any. |
|
1157 |
-#' @param transformParams Parameters used for feature transformation inside of C.V. |
|
1158 |
-#' specified by a \code{\link{TransformParams}} instance. Optional, can be \code{NULL}. |
|
1159 |
-#' @param selectParams Parameters used during feature selection specified |
|
1160 |
-#' by a \code{\link{SelectParams}} instance. By default, parameters for selection |
|
1161 |
-#' based on differences in means of numeric data. Optional, can be \code{NULL}. |
|
1162 |
-#' @param trainParams Parameters for model training specified by a \code{\link{TrainParams}} instance. |
|
1163 |
-#' By default, uses diagonal LDA. |
|
1164 |
-#' @param predictParams Parameters for model training specified by a \code{\link{PredictParams}} instance. |
|
1165 |
-#' By default, uses diagonal LDA. |
|
1166 |
-#' @param doImportance Default: \code{FALSE}. Whether or not to carry out removal of each feature, one at a time, which |
|
1167 |
-#' was chosen and then retrain and model and predict the test set, to measure the change in performance metric. Can |
|
1168 |
-#' also be set to TRUE, if required. Modelling run time will be noticeably longer. |
|
1169 |
-#' @author Dario Strbenac |
|
1170 |
-#' @examples |
|
1171 |
-#' |
|
1172 |
-#' #if(require(sparsediscrim)) |
|
1173 |
-#' #{ |
|
1174 |
-#' ModellingParams() # Default is differences in means selection and DLDA. |
|
1175 |
-#' ModellingParams(selectParams = NULL, # No feature selection before training. |
|
1176 |
-#' trainParams = TrainParams(randomForestTrainInterface), |
|
1177 |
-#' predictParams = PredictParams(randomForestPredictInterface)) |
|
1178 |
-#' #} |
|
1179 |
-#' @export |
|
1180 | 593 |
ModellingParams <- function(balancing = c("downsample", "upsample", "none"), |
1181 | 594 |
transformParams = NULL, selectParams = SelectParams(), |
1182 | 595 |
trainParams = TrainParams(), predictParams = PredictParams(), |
... | ... |
@@ -1188,16 +601,6 @@ ModellingParams <- function(balancing = c("downsample", "upsample", "none"), |
1188 | 601 |
doImportance = doImportance) |
1189 | 602 |
} |
1190 | 603 |
|
1191 |
- |
|
1192 |
-#' Union of A ModellingParams Object and NULL |
|
1193 |
-#' |
|
1194 |
-#' Allows a slot to be either a ModellingParams class object or empty. No |
|
1195 |
-#' constructor. |
|
1196 |
-#' |
|
1197 |
-#' |
|
1198 |
-#' @name ModellingParamsOrNULL-class |
|
1199 |
-#' @aliases ModellingParamsOrNULL ModellingParamsOrNULL-class |
|
1200 |
-#' @docType class |
|
1201 | 604 |
setClassUnion("ModellingParamsOrNULL", c("ModellingParams", "NULL")) |
1202 | 605 |
|
1203 | 606 |
|
... | ... |
@@ -1209,7 +612,7 @@ setClassUnion("ModellingParamsOrNULL", c("ModellingParams", "NULL")) |
1209 | 612 |
#' classes, the identifiers of features selected for each fold of each |
1210 | 613 |
#' permutation or each hold-out classification, and performance metrics such as |
1211 | 614 |
#' error rates. This class is not intended to be created by the user. It is |
1212 |
-#' created by \code{\link{runTest}} or \code{\link{runTests}}. |
|
615 |
+#' created by \code{\link{crossValidate}}. |
|
1213 | 616 |
#' |
1214 | 617 |
#' @name ClassifyResult |
1215 | 618 |
#' @rdname ClassifyResult-class |
... | ... |
@@ -1288,14 +691,7 @@ setClassUnion("ModellingParamsOrNULL", c("ModellingParams", "NULL")) |
1288 | 691 |
#' #if(require(sparsediscrim)) |
1289 | 692 |
#' #{ |
1290 | 693 |
#' data(asthma) |
1291 |
-#' |
|
1292 |
-#' LOOCVparams <- CrossValParams("Leave-k-Out", leave = 1) |
|
1293 |
-#' modellingParams <- ModellingParams() |
|
1294 |
-#' classified <- |
|
1295 |
-#' runTests(measurements, classes, LOOCVparams, modellingParams, |
|
1296 |
-#' DataFrame(characteristic = c("Data Set", "Classification"), |
|
1297 |
-#' value = c("Asthma", "Different Means")) |
|
1298 |
-#' ) |
|
694 |
+#' classified <- crossValidate(measurements, classes) |
|
1299 | 695 |
#' class(classified) |
1300 | 696 |
#' #} |
1301 | 697 |
#' |
... | ... |
@@ -1335,8 +731,6 @@ setMethod("ClassifyResult", c("DataFrame", "character"), |
1335 | 731 |
predictions = predictions, actualOutcome = actualOutcome, importance = importance, modellingParams = modellingParams, finalModel = finalModel) |
1336 | 732 |
}) |
1337 | 733 |
|
1338 |
-#' @usage NULL |
|
1339 |
-#' @export |
|
1340 | 734 |
setMethod("show", "ClassifyResult", function(object) |
1341 | 735 |
{ |
1342 | 736 |
cat("An object of class 'ClassifyResult'.\n") |
... | ... |
@@ -108,7 +108,6 @@ setMethod("crossValidate", "DataFrame", |
108 | 108 |
|
109 | 109 |
# Which data-types or data-views are present? |
110 | 110 |
assayIDs <- unique(mcols(measurements)[, "assay"]) |
111 |
- if(!is.null(characteristicsLabel)) assayIDs <- characteristicsLabel |
|
112 | 111 |
if(is.null(assayIDs)) assayIDs <- 1 |
113 | 112 |
|
114 | 113 |
checkData(measurements, outcome) |
... | ... |
@@ -283,7 +282,7 @@ setMethod("crossValidate", "DataFrame", |
283 | 282 |
}, simplify = FALSE) |
284 | 283 |
|
285 | 284 |
} |
286 |
- |
|
285 |
+ if(length(result) == 1) result <- result[[1]] |
|
287 | 286 |
result |
288 | 287 |
|
289 | 288 |
}) |
... | ... |
@@ -36,8 +36,7 @@ |
36 | 36 |
#' #if(require(sparsediscrim)) |
37 | 37 |
#' #{ |
38 | 38 |
#' data(asthma) |
39 |
-#' CVparams <- CrossValParams(permutations = 5) |
|
40 |
-#' result <- runTests(measurements, classes, CVparams, ModellingParams()) |
|
39 |
+#' result <- crossValidate(measurements, classes, nRepeats = 5) |
|
41 | 40 |
#' featureDistribution <- distribution(result, "features", summaryType = "count", |
42 | 41 |
#' plotType = "histogram", binwidth = 1) |
43 | 42 |
#' print(head(featureDistribution)) |
... | ... |
@@ -63,7 +63,7 @@ naiveBayesKernel <- function(measurementsTrain, classesTrain, measurementsTest, |
63 | 63 |
}) |
64 | 64 |
}) # Matrix, rows are test samples, columns are features. |
65 | 65 |
|
66 |
- if(difference == "weighted" && weight == "crossover distance") |
|
66 |
+ if(difference == "weighted" && weighting == "crossover distance") |
|
67 | 67 |
{ |
68 | 68 |
if(verbose == 3) |
69 | 69 |
message("Calculating horizontal distances to crossover points of class densities.") |
... | ... |
@@ -51,6 +51,7 @@ |
51 | 51 |
#' @param rotate90 Logical. IF \code{TRUE}, the plot is horizontal. |
52 | 52 |
#' @param showLegend If \code{TRUE}, a legend is plotted next to the plot. If |
53 | 53 |
#' FALSE, it is hidden. |
54 |
+#' @param ... Not used by end user. |
|
54 | 55 |
#' @return An object of class \code{ggplot} and a plot on the current graphics |
55 | 56 |
#' device, if \code{plot} is \code{TRUE}. |
56 | 57 |
#' @author Dario Strbenac |
... | ... |
@@ -63,7 +64,7 @@ |
63 | 64 |
#' result1 <- ClassifyResult(DataFrame(characteristic = c("Data Set", "Selection Name", "Classifier Name", |
64 | 65 |
#' "Cross-validation"), |
65 | 66 |
#' value = c("Example", "t-test", "Differential Expression", "2 Permutations, 2 Folds")), |
66 |
-#' LETTERS[1:10], list(paste("Gene", 1:100), paste("Gene", c(10:1, 11:100)), paste("Gene", 1:100), paste("Gene", 1:100)), |
|
67 |
+#' LETTERS[1:10], paste("Gene", 1:100), list(paste("Gene", 1:100), paste("Gene", c(10:1, 11:100)), paste("Gene", 1:100), paste("Gene", 1:100)), |
|
67 | 68 |
#' list(paste("Gene", 1:3), paste("Gene", c(2, 5, 6)), paste("Gene", 1:4), paste("Gene", 5:8)), |
68 | 69 |
#' list(function(oracle){}), NULL, predicted, actual) |
69 | 70 |
#' result1 <- calcCVperformance(result1, "Macro F1") |
... | ... |
@@ -75,7 +76,7 @@ |
75 | 76 |
#' result2 <- ClassifyResult(DataFrame(characteristic = c("Data Set", "Selection Name", "Classifier Name", |
76 | 77 |
#' "Cross-validation"), |
77 | 78 |
#' value = c("Example", "Bartlett Test", "Differential Variability", "2 Permutations, 2 Folds")), |
78 |
-#' LETTERS[1:10], list(paste("Gene", 1:100), paste("Gene", c(10:1, 11:100)), paste("Gene", 1:100), paste("Gene", 1:100)), |
|
79 |
+#' LETTERS[1:10], paste("Gene", 1:100), list(paste("Gene", 1:100), paste("Gene", c(10:1, 11:100)), paste("Gene", 1:100), paste("Gene", 1:100)), |
|
79 | 80 |
#' list(c(1:3), c(4:6), c(1, 6, 7, 9), c(5:8)), |
80 | 81 |
#' list(function(oracle){}), NULL, predicted, actual) |
81 | 82 |
#' result2 <- calcCVperformance(result2, "Macro F1") |
... | ... |
@@ -91,7 +92,13 @@ setGeneric("performancePlot", function(results, ...) standardGeneric("performanc |
91 | 92 |
|
92 | 93 |
#' @rdname performancePlot |
93 | 94 |
#' @export |
94 |
-setMethod("performancePlot", "list", |
|
95 |
+setMethod("performancePlot", "ClassifyResult", function(results, ...) { |
|
96 |
+ performancePlot(list(assay = results), ...) |
|
97 |
+}) |
|
98 |
+ |
|
99 |
+#' @rdname performancePlot |
|
100 |
+#' @export |
|
101 |
+setMethod("performancePlot", "list", |
|
95 | 102 |
function(results, performanceName = "auto", |
96 | 103 |
characteristicsList = list(x = "auto"), aggregate = character(), coloursList = list(), orderingList = list(), |
97 | 104 |
densityStyle = c("box", "violin"), yLimits = NULL, fontSizes = c(24, 16, 12, 12), title = NULL, |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
#' Plot Density, Scatterplot, Parallel Plot or Bar Chart for Features By Class |
2 | 2 |
#' |
3 |
-#' Allows the visualisation of measurements in the data set. If \code{targets} |
|
3 |
+#' Allows the visualisation of measurements in the data set. If \code{useFeatures} |
|
4 | 4 |
#' is of type \code{\link{Pairs}}, then a parallel plot is automatically drawn. |
5 | 5 |
#' If it's a single categorical variable, then a bar chart is automatically |
6 | 6 |
#' drawn. |
... | ... |
@@ -130,7 +130,7 @@ |
130 | 130 |
#' dataContainer <- MultiAssayExperiment(list(RNA = genesMatrix), |
131 | 131 |
#' colData = cbind(clinicalData, class = classes)) |
132 | 132 |
#' targetFeatures <- DataFrame(assay = "RNA", feature = "Gene 50") |
133 |
-#' plotFeatureClasses(dataContainer, targets = targetFeatures, classesColumn = "class", |
|
133 |
+#' plotFeatureClasses(dataContainer, useFeatures = targetFeatures, classesColumn = "class", |
|
134 | 134 |
#' groupBy = c("clinical", "Gender"), # Table name, feature name. |
135 | 135 |
#' xAxisLabel = bquote(log[2]*'(expression)'), dotBinWidth = 0.5) |
136 | 136 |
#' |
... | ... |
@@ -141,6 +141,13 @@ |
141 | 141 |
setGeneric("plotFeatureClasses", function(measurements, ...) |
142 | 142 |
standardGeneric("plotFeatureClasses")) |
143 | 143 |
|
144 |
+#' @rdname plotFeatureClasses |
|
145 |
+#' @export |
|
146 |
+setMethod("plotFeatureClasses", "matrix", function(measurements, ...) |
|
147 |
+{ |
|
148 |
+ plotFeatureClasses(S4Vectors::DataFrame(measurements, check.names = FALSE), ...) |
|
149 |
+}) |
|
150 |
+ |
|
144 | 151 |
#' @rdname plotFeatureClasses |
145 | 152 |
#' @export |
146 | 153 |
setMethod("plotFeatureClasses", "DataFrame", function(measurements, classes, useFeatures, groupBy = NULL, |
... | ... |
@@ -153,9 +160,9 @@ setMethod("plotFeatureClasses", "DataFrame", function(measurements, classes, use |
153 | 160 |
colours = c("#3F48CC", "#880015"), |
154 | 161 |
showAssayName = TRUE, plot = TRUE) |
155 | 162 |
{ |
156 |
- if(missing(targets)) |
|
157 |
- stop("'targets' must be specified.") |
|
158 |
- |
|
163 |
+ if(missing(useFeatures)) |
|
164 |
+ stop("'useFeatures' must be specified.") |
|
165 |
+ |
|
159 | 166 |
if(is.character(groupBy)) |
160 | 167 |
{ |
161 | 168 |
groupingName <- groupBy |
... | ... |
@@ -182,16 +189,15 @@ setMethod("plotFeatureClasses", "DataFrame", function(measurements, classes, use |
182 | 189 |
yLabelPositions <- ggplot2::waiver() |
183 | 190 |
|
184 | 191 |
# Subsetting of measurements to the features of interest. |
185 |
- |
|
186 |
- if(!is(targets, "DataFrame")) |
|
192 |
+ if(!is(useFeatures, "data.frame") && !is(useFeatures, "DataFrame")) |
|
187 | 193 |
{ |
188 |
- if(!"Pairs" %in% class(targets)) # A simple vector. |
|
189 |
- measurements <- tryCatch(measurements[targets], error = function(error) message("Error: Parameter 'targets' not in measurements, subscript contains out-of-bounds indices")) |
|
194 |
+ if(!is(useFeatures, "Pairs")) # A simple vector. |
|
195 |
+ measurements <- tryCatch(measurements[useFeatures], error = function(error) message("Error: Parameter 'useFeatures' not in measurements, subscript contains out-of-bounds indices")) |
|
190 | 196 |
else # Pairs object. |
191 |
- measurements <- tryCatch(measurements[union(S4Vectors::first(targets), S4Vectors::second(targets))], error = function(error) message("Error: Parameter 'targets' not in measurements, subscript contains out-of-bounds indices")) |
|
197 |
+ measurements <- tryCatch(measurements[union(S4Vectors::first(useFeatures), S4Vectors::second(useFeatures))], error = function(error) message("Error: Parameter 'useFeatures' not in measurements, subscript contains out-of-bounds indices")) |
|
192 | 198 |
} |
193 | 199 |
|
194 |
- if(!"Pairs" %in% class(targets)) |
|
200 |
+ if(!is(useFeatures, "Pairs")) |
|
195 | 201 |
{ |
196 | 202 |
invisible(lapply(seq_along(measurements), function(columnIndex) # Plot a single feature at a time. |
197 | 203 |
{ |
... | ... |
@@ -310,7 +316,7 @@ setMethod("plotFeatureClasses", "DataFrame", function(measurements, classes, use |
310 | 316 |
} |
311 | 317 |
})) |
312 | 318 |
} else { # Plot parallel plots. |
313 |
- invisible(lapply(targets, function(featurePair) # Plot a single feature at a time. |
|
319 |
+ invisible(lapply(useFeatures, function(featurePair) # Plot a single feature at a time. |
|
314 | 320 |
{ |
315 | 321 |
plotData <- data.frame(first = measurements[, S4Vectors::first(featurePair)], |
316 | 322 |
second = measurements[, S4Vectors::second(featurePair)], class = classes) |
... | ... |
@@ -341,4 +347,52 @@ setMethod("plotFeatureClasses", "DataFrame", function(measurements, classes, use |
341 | 347 |
pairsPlot |
342 | 348 |
})) |
343 | 349 |
} |
344 |
-}) |
|
345 | 350 |
\ No newline at end of file |
351 |
+}) |
|
352 |
+ |
|
353 |
+#' @rdname plotFeatureClasses |
|
354 |
+#' @export |
|
355 |
+setMethod("plotFeatureClasses", "MultiAssayExperiment", |
|
356 |
+ function(measurements, useFeatures, classesColumn, groupBy = NULL, groupingName = NULL, showAssayName = TRUE, ...) |
|
357 |
+ { |
|
358 |
+ if(missing(useFeatures)) |
|
359 |
+ stop("'useFeatures' must be specified by the user.") |
|
360 |
+ if(!all(useFeatures[, 1] %in% c(names(measurements), "sampleInfo"))) |
|
361 |
+ stop("Some table names in 'useFeatures' are not assay names in 'measurements' or \"sampleInfo\".") |
|
362 |
+ |
|
363 |
+ assaysuseFeatures <- useFeatures[useFeatures[, 1] != "sampleInfo", ] |
|
364 |
+ sampleInfouseFeatures <- useFeatures[useFeatures[, 1] == "sampleInfo", ] |
|
365 |
+ measurements <- measurements[assaysuseFeatures[, 2], , assaysuseFeatures[, 1]] |
|
366 |
+ classes <- MultiAssayExperiment::colData(measurements)[, classesColumn] |
|
367 |
+ |
|
368 |
+ if(!is.null(groupBy)) |
|
369 |
+ { |
|
370 |
+ if(is.null(groupingName)) |
|
371 |
+ groupingName <- groupBy[2] |
|
372 |
+ groupingTable <- groupBy[1] |
|
373 |
+ if(groupingTable == "sampleInfo") |
|
374 |
+ { |
|
375 |
+ groupBy <- MultiAssayExperiment::colData(measurements)[, groupBy[2]] |
|
376 |
+ } else { # One of the omics tables. |
|
377 |
+ groupBy <- measurements[groupBy[2], , groupingTable] |
|
378 |
+ if(showAssayName == TRUE) |
|
379 |
+ groupingName <- paste(groupingName, groupingTable) |
|
380 |
+ } |
|
381 |
+ levelsOrder <- levels(groupBy) |
|
382 |
+ groupBy <- list(legends = factor(groupBy, levels = levelsOrder), |
|
383 |
+ facets = {groupText <- paste(groupingName, "is", groupBy) |
|
384 |
+ factor(groupText, levels = paste(groupingName, "is", levelsOrder))} |
|
385 |
+ ) |
|
386 |
+ } |
|
387 |
+ |
|
388 |
+ MultiAssayExperiment::colData(measurements) <- MultiAssayExperiment::colData(measurements)[colnames(MultiAssayExperiment::colData(measurements)) %in% sampleInfouseFeatures[, 2]] |
|
389 |
+ measurements <- MultiAssayExperiment::wideFormat(measurements, colDataCols = seq_along(MultiAssayExperiment::colData(measurements)), check.names = FALSE, collapse = ':') |
|
390 |
+ measurements <- measurements[, -1, drop = FALSE] # Remove sample IDs. |
|
391 |
+ S4Vectors::mcols(measurements)[, "sourceName"] <- gsub("colDataCols", "sampleInfo", S4Vectors::mcols(measurements)[, "sourceName"]) |
|
392 |
+ colnames(S4Vectors::mcols(measurements))[1] <- "assay" |
|
393 |
+ S4Vectors::mcols(measurements)[, "feature"] <- S4Vectors::mcols(measurements)[, "rowname"] |
|
394 |
+ missingIndices <- is.na(S4Vectors::mcols(measurements)[, "feature"]) |
|
395 |
+ S4Vectors::mcols(measurements)[missingIndices, "feature"] <- colnames(measurements)[missingIndices] |
|
396 |
+ S4Vectors::mcols(measurements) <- S4Vectors::mcols(measurements)[, c("assay", "feature")] |
|
397 |
+ |
|
398 |
+ plotFeatureClasses(measurements, classes, S4Vectors::mcols(measurements), groupBy, groupingName, showAssayName = showAssayName, ...) |
|
399 |
+ }) |
|
346 | 400 |
\ No newline at end of file |
... | ... |
@@ -46,8 +46,10 @@ setMethod("prepareData", "matrix", |
46 | 46 |
prepareData(S4Vectors::DataFrame(measurements, check.names = FALSE), outcome, ...) |
47 | 47 |
}) |
48 | 48 |
|
49 |
+#' @rdname prepareData |
|
50 |
+#' @export |
|
49 | 51 |
setMethod("prepareData", "DataFrame", |
50 |
- function(measurements, outcome, useFeatures = "all", maxMissingProp = 0.3, topNvariance = NULL) |
|
52 |
+ function(measurements, outcome, useFeatures = "all", maxMissingProp = 0.0, topNvariance = NULL) |
|
51 | 53 |
{ |
52 | 54 |
if(useFeatures != "all") # Subset to only the desired ones. |
53 | 55 |
measurements <- measurements[, useFeatures] |
... | ... |
@@ -137,6 +139,8 @@ setMethod("prepareData", "DataFrame", |
137 | 139 |
list(measurements = measurements, outcome = outcome) |
138 | 140 |
}) |
139 | 141 |
|
142 |
+#' @rdname prepareData |
|
143 |
+#' @export |
|
140 | 144 |
setMethod("prepareData", "MultiAssayExperiment", |
141 | 145 |
function(measurements, outcomeColumns = NULL, useFeatures = data.frame(assay = names(measurements), feature = rep("all", length(measurements))), ...) |
142 | 146 |
{ |
... | ... |
@@ -68,6 +68,7 @@ |
68 | 68 |
#' graphics device. |
69 | 69 |
#' @param parallelParams An object of class \code{\link{MulticoreParam}} or |
70 | 70 |
#' \code{\link{SnowParam}}. |
71 |
+#' @param ... Not used by end user. |
|
71 | 72 |
#' @return An object of class \code{ggplot} and a plot on the current graphics |
72 | 73 |
#' device, if \code{plot} is \code{TRUE}. |
73 | 74 |
#' @author Dario Strbenac |
... | ... |
@@ -107,6 +108,12 @@ |
107 | 108 |
setGeneric("rankingPlot", function(results, ...) |
108 | 109 |
standardGeneric("rankingPlot")) |
109 | 110 |
|
111 |
+#' @rdname rankingPlot |
|
112 |
+#' @export |
|
113 |
+setMethod("rankingPlot", "ClassifyResult", function(results, ...) { |
|
114 |
+ rankingPlot(list(assay = results), ...) |
|
115 |
+}) |
|
116 |
+ |
|
110 | 117 |
#' @rdname rankingPlot |
111 | 118 |
#' @export |
112 | 119 |
setMethod("rankingPlot", "list", |
... | ... |
@@ -126,7 +133,8 @@ setMethod("rankingPlot", "list", |
126 | 133 |
if(comparison == "within" && !is.null(referenceLevel)) |
127 | 134 |
stop("'comparison' should not be \"within\" if 'referenceLevel' is not NULL.") |
128 | 135 |
|
129 |
- nFeatures <- nrow(featuresInfo(results[[1]])) |
|
136 |
+ originalFeatures <- allFeatureNames(results[[1]]) |
|
137 |
+ if(is.character(originalFeatures)) nFeatures <- length(originalFeatures) else nFeatures <- nrow(originalFeatures) |
|
130 | 138 |
error <- character() |
131 | 139 |
if(max(topRanked) > nFeatures) |
132 | 140 |
error <- paste("'topRanked' is as high as", max(topRanked)) |
... | ... |
@@ -1,81 +1,8 @@ |
1 |
-#' Perform a Single Classification |
|
2 |
-#' |
|
3 |
-#' For a data set of features and samples, the classification process is run. |
|
4 |
-#' It consists of data transformation, feature selection, classifier training |
|
5 |
-#' and testing. |
|
6 |
-#' |
|
7 |
-#' This function only performs one classification and prediction. See |
|
8 |
-#' \code{\link{runTests}} for a driver function that enables a number of |
|
9 |
-#' different cross-validation schemes to be applied and uses this function to |
|
10 |
-#' perform each iteration. |
|
11 |
-#' |
|
12 |
-#' @aliases runTest runTest,matrix-method runTest,DataFrame-method |
|
13 |
-#' runTest,MultiAssayExperiment-method |
|
14 |
-#' @param measurementsTrain Either a \code{\link{matrix}}, \code{\link{DataFrame}} |
|
15 |