randomForestInterface {ClassifyR}R Documentation

An Interface for randomForest Package's randomForest Function

Description

A random forest classifier builds multiple decision trees and uses the predictions of the trees to determine a single prediction for each test sample.

Usage

  ## S4 method for signature 'matrix'
randomForestInterface(measurements, classes, test, ...)
  ## S4 method for signature 'DataFrame'
randomForestInterface(measurements, classes, test, ..., verbose = 3)
  ## S4 method for signature 'MultiAssayExperiment'
randomForestInterface(measurements, targets = names(measurements), test, ...)

Arguments

measurements

Either a matrix, DataFrame or MultiAssayExperiment containing the training data. For a matrix, the rows are features, and the columns are samples.

classes

Either a vector of class labels of class factor of the same length as the number of samples in measurements or if the measurements are of class DataFrame a character vector of length 1 containing the column name in measurement is also permitted. Not used if measurements is a MultiAssayExperiment object.

test

An object of the same class as measurements with no samples in common with measurements and the same number of features as it.

targets

If measurements is a MultiAssayExperiment, the names of the data tables to be used. "clinical" is also a valid value and specifies that integer variables from the clinical data table will be used.

...

Variables not used by the matrix nor the MultiAssayExperiment method which are passed into and used by the DataFrame method (e.g. verbose) or options which are accepted by the randomForest function.

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.

Details

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".

Value

An object of type randomForest. The predictions of the test set samples are stored in the list element named "predicted" of the "test" element.

Author(s)

Dario Strbenac

Examples

  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))
    rownames(genesMatrix) <- paste("Gene", 1:nrow(genesMatrix))
    selected <- rownames(genesMatrix)[91:100]
    trainingSamples <- c(1:20, 26:45)
    testingSamples <- c(21:25, 46:50)
    
    classified <- randomForestInterface(genesMatrix[, trainingSamples],
                                        classes[trainingSamples],
                                        genesMatrix[, testingSamples], ntree = 10)
    classified[["test"]][["predicted"]]
  }

[Package ClassifyR version 2.0.10 Index]