Predict values of random forest model response variables from new data.
Arguments
- model
S4 object of class
RandomForest
- new_data
S4 object of class
AnalysisData
- idx
sample information column to use for sample names. If
NULL
, the sample row number will be used. Sample names should be unique for each row of data.- type
one of
response
,prob
, orvotes
to indicate the type of prediction to make- ...
arguments to pass to
randomForest::predict.randomForest()
Details
The features contained within new_data
should match those of the features used to train model
.
The features()
method can be used to check this.
The argument returnModels = TRUE
should also be used when training the RandomForest-class
object used for argument model
.
Examples
library(metaboData)
## Prepare some data
x <- analysisData(abr1$neg[,200:300],abr1$fact) %>%
occupancyMaximum(cls = 'day') %>%
transformTICnorm()
## Extract data from which to train a random forest model
training_data <- x %>%
keepClasses(cls = 'day',
classes = c('H','1'))
## Extract data for which response values will be predicted
test_data <- x %>%
keepClasses(cls = 'day',
classes = c('2','3'))
rf <- randomForest(training_data,
cls = 'day',
returnModels = TRUE)
predict(rf,
test_data)
#> # A tibble: 40 × 5
#> response comparison rep sample prediction
#> <chr> <chr> <dbl> <int> <fct>
#> 1 day 1~H 1 1 H
#> 2 day 1~H 1 2 H
#> 3 day 1~H 1 3 H
#> 4 day 1~H 1 4 H
#> 5 day 1~H 1 5 H
#> 6 day 1~H 1 6 H
#> 7 day 1~H 1 7 H
#> 8 day 1~H 1 8 H
#> 9 day 1~H 1 9 H
#> 10 day 1~H 1 10 1
#> # ℹ 30 more rows