Skip to contents

Classification using the random forest algorithm.

Usage

rfClassification(
  object,
  assessRes,
  scores = c("prediction", "all", "none"),
  mtry,
  fcol = "markers",
  ...
)

Arguments

object

An instance of class "MSnSet".

assessRes

An instance of class "GenRegRes", as generated by rfOptimisation.

scores

One of "prediction", "all" or "none" to report the score for the predicted class only, for all classes or none.

mtry

If assessRes is missing, a mtry must be provided.

fcol

The feature meta-data containing marker definitions. Default is markers.

...

Additional parameters passed to randomForest from package randomForest.

Value

An instance of class "MSnSet" with rf and rf.scores feature variables storing the classification results and scores respectively.

Author

Laurent Gatto

Examples

library(pRolocdata)
data(dunkley2006)
## reducing parameter search space and iterations 
params <- rfOptimisation(dunkley2006, mtry = c(2, 5, 10),  times = 3)
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |=====                                                                 |   7%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |===================                                                   |  27%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |=================================                                     |  47%
  |                                                                            
  |=====================================                                 |  53%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |===================================================                   |  73%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |=============================================================         |  87%
  |                                                                            
  |=================================================================     |  93%
  |                                                                            
  |======================================================================| 100%
params
#> Object of class "GenRegRes"
#> Algorithm: randomForest 
#> Hyper-parameters:
#>  mtry: 2 5 10
#> Design:
#>  Replication: 3 x 5-fold X-validation
#>  Partitioning: 0.2/0.8 (test/train)
#> Results
#>  macro F1:
#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
#>  0.9639  0.9690  0.9740  0.9724  0.9767  0.9793 
#>  best mtry: 2 5   
plot(params)

f1Count(params)
#> 
#> 2 
#> 1 
levelPlot(params)

getParams(params)
#> mtry 
#>    2 
res <- rfClassification(dunkley2006, params)
#> [1] "markers"
getPredictions(res, fcol = "rf")
#> ans
#>      ER lumen   ER membrane         Golgi Mitochondrion            PM 
#>            19           179            95           104           134 
#>       Plastid      Ribosome           TGN       vacuole 
#>            51            53            21            33 
#> MSnSet (storageMode: lockedEnvironment)
#> assayData: 689 features, 16 samples 
#>   element names: exprs 
#> protocolData: none
#> phenoData
#>   sampleNames: M1F1A M1F4A ... M2F11B (16 total)
#>   varLabels: membrane.prep fraction replicate
#>   varMetadata: labelDescription
#> featureData
#>   featureNames: AT1G09210 AT1G21750 ... AT4G39080 (689 total)
#>   fvarLabels: assigned evidence ... rf.pred (11 total)
#>   fvarMetadata: labelDescription
#> experimentData: use 'experimentData(object)'
#>   pubMedIds: 16618929 
#> Annotation:  
#> - - - Processing information - - -
#> Loaded on Thu Jul 16 22:53:08 2015. 
#> Normalised to sum of intensities. 
#> Added markers from  'mrk' marker vector. Thu Jul 16 22:53:08 2015 
#> Performed random forest prediction (mtry=2) Fri Oct 18 17:20:59 2024 
#> Added rf predictions according to global threshold = 0 Fri Oct 18 17:20:59 2024 
#>  MSnbase version: 1.17.12 
getPredictions(res, fcol = "rf", t = 0.75)
#> ans
#>      ER lumen   ER membrane         Golgi Mitochondrion            PM 
#>            14           139            77            89            94 
#>       Plastid      Ribosome           TGN       unknown       vacuole 
#>            45            20            13           171            27 
#> MSnSet (storageMode: lockedEnvironment)
#> assayData: 689 features, 16 samples 
#>   element names: exprs 
#> protocolData: none
#> phenoData
#>   sampleNames: M1F1A M1F4A ... M2F11B (16 total)
#>   varLabels: membrane.prep fraction replicate
#>   varMetadata: labelDescription
#> featureData
#>   featureNames: AT1G09210 AT1G21750 ... AT4G39080 (689 total)
#>   fvarLabels: assigned evidence ... rf.pred (11 total)
#>   fvarMetadata: labelDescription
#> experimentData: use 'experimentData(object)'
#>   pubMedIds: 16618929 
#> Annotation:  
#> - - - Processing information - - -
#> Loaded on Thu Jul 16 22:53:08 2015. 
#> Normalised to sum of intensities. 
#> Added markers from  'mrk' marker vector. Thu Jul 16 22:53:08 2015 
#> Performed random forest prediction (mtry=2) Fri Oct 18 17:20:59 2024 
#> Added rf predictions according to global threshold = 0.75 Fri Oct 18 17:20:59 2024 
#>  MSnbase version: 1.17.12 
plot2D(res, fcol = "rf")