randomForestInterface {ClassifyR} | R Documentation |
A random forest classifier builds multiple decision trees and uses the predictions of the trees to determine a single prediction for each test sample.
## S4 method for signature 'matrix' randomForestTrainInterface(measurements, classes, ...) ## S4 method for signature 'DataFrame' randomForestTrainInterface(measurements, classes, ..., verbose = 3) ## S4 method for signature 'MultiAssayExperiment' randomForestTrainInterface(measurements, targets = names(measurements), ...) ## S4 method for signature 'randomForest,matrix' randomForestPredictInterface(forest, test, ...) ## S4 method for signature 'randomForest,DataFrame' randomForestPredictInterface(forest, test, ..., returnType = c("class", "score", "both"), verbose = 3) ## S4 method for signature 'randomForest,MultiAssayExperiment' randomForestPredictInterface(forest, test, targets = names(test), ...)
measurements |
Either a |
classes |
Either a vector of class labels of class |
forest |
A trained random forest classifier, as created by
|
test |
An object of the same class as |
targets |
If |
... |
Variables not used by the |
returnType |
Default: |
verbose |
Default: 3. A number between 0 and 3 for the amount of progress messages to give. This function only prints progress messages if the value is 3. |
If measurements
is an object of class MultiAssayExperiment
, the factor of sample
classes must be stored in the DataFrame accessible by the colData
function with
column name "class"
.
For randomForestTrainInterface
, the trained random forest. For randomForestPredictInterface
,
either a factor vector of predicted classes, a matrix of scores for each class, or a table of
both the class labels and class scores, depending on the setting of returnType
.
Dario Strbenac
if(require(randomForest)) { # Genes 76 to 100 have differential expression. genesMatrix <- sapply(1:25, function(sample) c(rnorm(100, 9, 2))) genesMatrix <- cbind(genesMatrix, sapply(1:25, function(sample) c(rnorm(75, 9, 2), rnorm(25, 14, 2)))) classes <- factor(rep(c("Poor", "Good"), each = 25)) colnames(genesMatrix) <- paste("Sample", 1:ncol(genesMatrix), sep = '') rownames(genesMatrix) <- paste("Gene", 1:nrow(genesMatrix), sep = '') trainingSamples <- c(1:20, 26:45) testingSamples <- c(21:25, 46:50) trained <- randomForestTrainInterface(genesMatrix[, trainingSamples], classes[trainingSamples]) predicted <- randomForestPredictInterface(trained, genesMatrix[, testingSamples]) }