# rfPermute: A tutorial for evaluating, diagnosing, and visualzing Random Forest model results.

#### Eric Archer

#### Marine Mammal and Turtle Division, SWFSC, NOAA Fisheries

#### 8901 La Jolla, Shores Dr., La Jolla, CA 92037

#### 09 February 2022

## 1. Introduction

rfPermute is a package that provides a variety of functions for evaluating the results of Random Forest classification and regression models. The central feature of the package is the estimation of statistical significance (p-values) of variable importance measures as generated by the randomForest package by Andy Liaw and Matthew Wiener.

To install rfPermute from CRAN:

    install.packages('rfPermute')

To install the latest version from GitHub:

    # make sure you have devtools installed
    if (!require('devtools')) install.packages('devtools')

    # install from GitHub
    devtools::install_github('EricArcher/rfPermute')

If you do not currently have randomForest installed, installing rfPermute will install it for you.

To start, lets create a simple randomForest classification model that we can use throughout this tutorial. The model will use the `mtcars` dataset that is shipped with R. We’ll use it to build a model to classify whether or not the car is automatic or manual transmission (column `am`) based on other features of the cars. We’ll specify that we want to return importance scores (`importance = TRUE`), and run it for a smaller number of trees (`ntree = 300`) but will leave the rest of the parameters to their defaults.

    library(randomForest)
    data(mtcars)
    # copy the mtcars data frame so we can modify it
    df <- mtcars
    # recode the transmission column labels to be more informative
    df$am <- factor(c("Automatic", "Manual")[df$am + 1])

    # straight Random Forest classification model with random sampling with replacement
    rf <- randomForest(am ~ ., df, ntree = 300, importance = TRUE)
    rf

    Call:
     randomForest(formula = am ~ ., data = df, ntree = 300, importance = TRUE)
                   Type of random forest: classification
                         Number of trees: 300
    No. of variables tried at each split: 3

            OOB estimate of  error rate: 12.5%
    Confusion matrix:
              Automatic Manual class.error
    Automatic        17      2      0.1053
    Manual            2     11      0.1538

We see that the model seems to do a relatively good classification job with an overall OOB error rate of 0.125.

## 2. Model Diagnostics

### plotTrace()

The most important diagnostic for a Random Forest model is the trace plot. This shows how the error rate (OOB for classification models and MSE for regression models) changes as trees were added to the forest. The forest should have enough trees in it such that the error rate is stable. The `plotTrace()` function is a rewrite of `randomForest::plot.randomForest()` using `ggplot2` graphics and providing a legend:

    library(rfPermute)
    plotTrace(rf)

Here, it looks stable over 300 trees, but we should run it for a few more to make sure. We’ll increase the number of trees to 1000:

    rf <- randomForest(am ~ ., df, importance = TRUE, ntree = 1000)
    rf

    Call:
     randomForest(formula = am ~ ., data = df, importance = TRUE,      ntree = 1000)
                   Type of random forest: classification
                         Number of trees: 1000
    No. of variables tried at each split: 3

            OOB estimate of  error rate: 12.5%
    Confusion matrix:
              Automatic Manual class.error
    Automatic        17      2      0.1053
    Manual            2     11      0.1538

Notice this may not appreciably change the confusion matrix, but the trace (below) shows fairly good stability at the final model:

    plotTrace(rf)

### plotInbag()

Another feature to examine is the rate at which cases are selected to be used in the model. We want to make sure that enough trees have been built so that the sample usage frequency (the fraction of times they are “inbag”) is close to their expectation. We can see the distribution of this inbag rate with the `plotInbag()` function. To demonstrate its use, we will build three normal Random Forest models with an increasing number of trees. In the first, we only have 50 trees:

    rf.50 <- randomForest(am ~ ., data = df, ntree = 50)
    plotInbag(rf.50)

Since we are sampling at random with replacement, the expectation is that a sample will be in approximately 63% of the trees. The red line shows this expectation, with a fairly wide distribution around this value in this particular model.
Here is a summary of the inbag rates for the model with 50 trees:

    summary((rf.50$ntree - rf.50$oob.times) / rf.50$ntree)

       Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
      0.480   0.615   0.640   0.641   0.680   0.780

The difference in this distribution can be seen if we increase the number of trees to 200:

    rf.200 <- randomForest(am ~ ., data = df, ntree = 200)
    plotInbag(rf.200)

Here we see the x-axis is narrowing, indicating that the variance of the sample inbag rates is more closely approaching the expected value:

    summary((rf.200$ntree - rf.200$oob.times) / rf.200$ntree)

       Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
      0.555   0.620   0.630   0.638   0.670   0.710

Finally as an extreme, here is a 10,000 tree model:

    rf.10k <- randomForest(am ~ ., data = df, ntree = 10000)
    plotInbag(rf.10k)

We see that the variance in inbag rates has narrowed significantly. Ideally, we want this variance to be relatively small to ensure that most samples are getting in a high percentage of trees in the forest:

    summary((rf.10k$ntree - rf.10k$oob.times) / rf.10k$ntree)

       Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
      0.630   0.635   0.638   0.638   0.641   0.648

### balancedSampsize()

If you have classes with unequal sample sizes, the default settings will produce a model that will tend to perform better on the larger class, regardless of the how well the predictors can classify individual cases. To avoid this bias, it is suggested that a balanced model be created, where the classes are represented by an equal number of samples in each tree and sampling is done without replacement. The `balancedSampsize()` function is provided to create a vector like this. By default, it selects half of the smallest class size as the sample size for every class:

    sampsize <- balancedSampsize(df$am)
    sampsize

    Automatic    Manual
            7         7

Here is the new balanced model:

    rf.balanced <- randomForest(am ~ ., data = df, replace = FALSE, sampsize = sampsize, ntree = 1000)
    confusionMatrix(rf.balanced)

              Automatic Manual pct.correct LCI_0.95 UCI_0.95
    Automatic        16      3       84.21    60.42    96.62
    Manual            2     11       84.62    54.55    98.08
    Overall          NA     NA       84.38    67.21    94.72

If you have a model with stratified sampling, or you sample without replacement, you will need specify these conditions to the `plotInbag()` function, so these expectations can be correctly computed.

    plotTrace(rf.balanced)

    plotInbag(rf.balanced, replace = FALSE, sampsize = sampsize)

Notice how there are two modes in the distribution here because of the stratified sampling without replacement. We see that the distribution is relatively well centered on the expectations. Along with the trace plot, this indicates that the model is stable and cases are being used in a sufficient number trees such that casewise variability in the predictors is being incorporated.

## 3. Variable Importance

For many uses, the measurements of variable (predictor) importance from a Random Forest model are of interest. These give a relative ranking of how important each predictor is to the model classification ability. Here is the standard output of importance scores from randomForest:

    round(importance(rf), 3)

         Automatic Manual MeanDecreaseAccuracy MeanDecreaseGini
    mpg      6.750  7.922                9.033            1.069
    cyl      3.891  3.199                4.677            0.338
    disp     9.274 12.633               13.689            1.774
    hp       2.751  4.302                4.683            0.828
    drat     7.606 13.067               13.795            2.068
    wt      16.724 22.284               24.109            3.855
    qsec     7.824  6.032                8.141            1.565
    vs       4.715  0.753                3.511            0.175
    gear    14.855 19.051               19.672            2.910
    carb     0.284 -0.185               -0.335            0.381

… and a graphical visualization of their distribution:

    varImpPlot(rf)

We see that `wt` and `gear` are the most important predictor variables, while `cyl`, `vs`, and `carb` are the least important predictors. These variable importance scores are derived from randomly permuting each predictor variable one at a time in the out-of-bag (OOB) data for each tree and summarizing how much worse the model prediction is. A predictor that is very important in the overall model will have degraded performance when permuted. Conversely, a variable with no predictive power (not strongly correlated with the response variable anywhere in the parameter space) will not affect the predictive capability of the model much at all as its influence on the model’s predictive ability was low to begin with. The degree to which this happens is the Decrease in Mean Accuracy that is summarized in the importance scores.

However, there is nothing in this output that suggests which of the importance scores are “significant” predictors and which are not. That is, where is the line between predictors that really influence the model’s accuracy and those that aren’t providing any more predictive power than a random predictor. By “random” predictor, we mean a predictor with values distributed at random relative to the response variable (here, transmission type - `am`). Answering this requires creating a null distribution of importance scores that we can then compare the observed importance scores to. Because the importance scores come from predictions made by the model taking the covariance of predictors into account, we need to maintain that covariance structure when creating this null distribution.

In rfPermute, we satisfy this requirement by just permuting the response variable and then fitting the same model again. Variable importance scores are computed as before, however in this case they are computed as if the entire matrix of predictors were randomly distributed with respect to the response. Doing this procedure multiple times generates a null distribution of model-specific and, in the case of classification models, class-specific importance scores for each predictor variable. Those observed importance scores for which only a small fraction of the samples from this null are the same or greater (a p-value, typically 5%) can be considered to be significantly more important than a random predictor.

rfPermute computes these null distributions and p-values by providing an interface that is a wrapper for randomForest. The rfPermute model is run with a call to `rfPermute()`. The model construction and arguments are the same as a call to `randomForest()`. The function that adds an argument specifying the number of permutations to conduct for the null distributions (`nrep`). Because this process runs a full Random Forest model multiple times, it can be computationally expensive. Thus, the runs can be distributed over multiple cores, which can be specified with the `num.cores` argument. Here is an example with the same model as above:

    rp <- rfPermute(am ~ ., df, ntree = 300, nrep = 1000, num.cores = 6)
    rp

    An rfPermute model

                   Type of random forest: classification
                         Number of trees: 300
    No. of variables tried at each split: 3
           No. of permutation replicates: 100
                              Start time: 2022-02-09 17:11:58
                                End time: 2022-02-09 17:11:58
                                Run time: 0.228 secs

              Automatic Manual pct.correct LCI_0.95 UCI_0.95
    Automatic        17      2        89.5     66.9     98.7
    Manual            2     11        84.6     54.6     98.1
    Overall          NA     NA        87.5     71.0     96.5

This output gives summary information about the rfPermute model that we’ll cover in more detail later. However, notice that the core confusion matrix is the same as the original randomForest model showing that the base classification model is the same.

NOTE: Like the `randomForest()` function, `rfPermute()` can be run using a formula interface as above, or with the default matrix and vector specification interface. All arguments available in `randomForest()` are also available in `rfPermute()`, and are specified in the same way. The only exception is that `rfPermute()` is always run with the `importance = TRUE` argument set and the importance matrix is always available in the output. See `?randomForest` for more information on specifying models.

### importance()

To extract the variable importance scores from an rfPermute model, we also use the `importance()` function, which has a version for the `rfPermute` model object. This function returns a matrix with the importance scores for each type followed by their p-values.

    imp <- importance(rp)
    round(imp, 3)

         Automatic Automatic.pval Manual Manual.pval MeanDecreaseAccuracy
    wt       8.288          0.010 12.418       0.010               13.354
    gear     7.714          0.010 10.778       0.010               10.482
    drat     5.977          0.050  7.566       0.010                8.243
    disp     5.409          0.020  7.068       0.020                7.269
    mpg      2.459          0.287  5.410       0.010                5.049
    qsec     3.527          0.109  2.524       0.158                3.915
    hp       2.977          0.178  2.514       0.129                3.267
    vs       3.304          0.050  0.040       0.317                2.486
    cyl      1.736          0.267  0.233       0.327                1.236
    carb     1.799          0.257 -0.335       0.455                1.018
         MeanDecreaseAccuracy.pval MeanDecreaseGini MeanDecreaseGini.pval
    wt                       0.010            3.850                 0.010
    gear                     0.010            2.840                 0.010
    drat                     0.020            2.142                 0.356
    disp                     0.010            1.668                 0.911
    mpg                      0.109            1.268                 1.000
    qsec                     0.079            1.767                 0.941
    hp                       0.149            0.652                 1.000
    vs                       0.059            0.172                 0.604
    cyl                      0.198            0.301                 0.416
    carb                     0.287            0.395                 0.990

By default, the matrix will be sorted by the `MeanDecreaseAccuracy` column, but this can be changed using the `sort.by` argument to the function.

### plotImportance()

The importance scores can also be visualized as a barchart or density chart with `plotImportance()`:

    plotImportance(rp)

This shows a bar graph of the importance score for each type, with significant scores (p-values <= 0.05) colored red. We can see that not all of the predictors are significant. Additionally, although the distributions of importance scores are the same for both transmission classes, there is a difference in which predictors are significantly important for classifying manual vs. automatic transmissions.

Note that this function as well as many others can be used with both rfPermute and randomForest models:

    plotImportance(rf)

Importance scores can also be visualized with heatmaps. Here is a heatmap of the original rfPermute model for just the case-specific importance scores.

    plotImportance(rp, plot.type = "heatmap", imp.type = c("Manual", "Automatic"), size = 6)

In this default option, the heatmap shows importance scores scaled by ranked importance. The white diamonds in the heatmap indicate the significant (p < 0.05) scores.

### plotNull()

The null distributions of importance values are stored in the rfPermute object. The distribution of these can be viewed with the `plotNull()` function which also shows the placement of the observed value relative to the distribution.

    plotNull(rp, imp.type = "MeanDecreaseAccuracy", preds = c("disp", "carb"))

### plotImpPreds()

For classification models, it can be useful to inspect the distributions of the raw predictor values in each case in the order of their importances. This function allows for that visualization. It requires the original data frame (`df` here) and you must specify the column name in that data frame that gives the response class (`am` here).

    plotImpPreds(rp, df, "am")

This produces violin plots for each predictor variable (the panels), separated by the class column (the x-axis). The predictors are sorted from top left to lower right by their importance scores. Here we see that most of the difference between transmission types is in `wt`, while there is more overlap in a variable like `cyl`.

## 3. Model Summaries

### confusionMatrix()

The most basic summary is the confusion matrix, which can be computed with the `confusionMatrix()` function:

    confusionMatrix(rp)

              Automatic Manual pct.correct LCI_0.95 UCI_0.95
    Automatic        17      2       89.47    66.86    98.70
    Manual            2     11       84.62    54.55    98.08
    Overall          NA     NA       87.50    71.01    96.49

In this output, the first two rows are information for the original two classes (0 = manual and 1 = automatic transmissions). The third row gives summary information for the model overall. The first two columns show the actual confusion matrix. The values are the number of samples that were originally from the class in their respective rows that were classified by the model to be in the class in their respective columns. That is, the rows are the original class and the columns are the predicted class. Thus, the diagonals represent the number of samples correctly classified in each class. The remaining columns are:

- `pct.correct`: the percent of samples in the class (row) that were correctly classified.
- `LCI_0.95` and `UCI_0.95`: the lower and upper 95% confidence intervals of percent correctly classified. These values are from a binomial distribution and represent the uncertainty in the estimate of the classification accuracy of the class given the sample size of that class.

The `confusionMatrix()` function also provides the ability to compute the binomial probability that `pct.correct` is greater than a given threshold value taking the sample size of the class into account. This is controlled with the `threshold` argument.

    # threshold = 0.6
    confusionMatrix(rp, threshold = 0.6)

              Automatic Manual pct.correct LCI_0.95 UCI_0.95 Pr.gt_0.6
    Automatic        17      2       89.47    66.86    98.70  0.267616
    Manual            2     11       84.62    54.55    98.08  0.003006
    Overall          NA     NA       87.50    71.01    96.49  0.999864

    # threshold = 0.8
    confusionMatrix(rp, threshold = 0.8)

              Automatic Manual pct.correct LCI_0.95 UCI_0.95 Pr.gt_0.8
    Automatic        17      2       89.47    66.86    98.70 5.610e-04
    Manual            2     11       84.62    54.55    98.08 2.650e-08
    Overall          NA     NA       87.50    71.01    96.49 9.069e-01

    # threshold = 0.95
    confusionMatrix(rp, threshold = 0.95)

              Automatic Manual pct.correct LCI_0.95 UCI_0.95 Pr.gt_0.95
    Automatic        17      2       89.47    66.86    98.70  7.643e-12
    Manual            2     11       84.62    54.55    98.08  3.594e-20
    Overall          NA     NA       87.50    71.01    96.49  7.381e-02

Notice that as `threshold` is increased the value of the last column (`Pr.gt_0.##`) decreases. This is expected as the probability that the true percent correctly classifiable is greater than these thresholds should become smaller as the threshold approaches 1.

The confusion matrix can also be visualized as a heatmap with the `plotConfMat()` function:

    plotConfMat(rp)

### classPriors()

- `prior`: the expected percent of samples that would be correctly classified if the model was classifying samples at random. This is based on the relative difference in sample sizes of each class. If all classes have the same sample size, the priors will be all be 1 / k where k is the number of classes.
- `class_p.value`: the binomial probability that the number of correctly classified samples in each class would be observed given the size of that class under the assumption that `prior` is is the correct rate of correct classification.

    classPriors(rp, sampsize = NULL)

              prior class_p.value
    Automatic 59.38     6.992e-04
    Manual    40.62     1.642e-04
    Overall   51.76     3.150e-06

    classPriors(rp, sampsize = c(4, 4))

              prior class_p.value
    Automatic    50     3.815e-05
    Manual       50     1.709e-03
    Overall      50     1.278e-06

    classPriors(rp, sampsize = c(4, 1))

              prior class_p.value
    Automatic 80.00     8.287e-02
    Manual    20.00     4.342e-08
    Overall   55.62     2.019e-05

### casePredictions()

In classification models, we often want to explore the individual classifications and their probabilities of assignment. We can extract a data frame of this information with the `casePredictions()` function:

    casePredictions(rp)

                        id  original predicted is.correct Automatic   Manual
    1            Mazda RX4    Manual    Manual       TRUE   0.09259 0.907407
    2        Mazda RX4 Wag    Manual    Manual       TRUE   0.16667 0.833333
    3           Datsun 710    Manual    Manual       TRUE   0.26667 0.733333
    4       Hornet 4 Drive Automatic Automatic       TRUE   0.88785 0.112150
    5    Hornet Sportabout Automatic Automatic       TRUE   0.98519 0.014815
    6              Valiant Automatic Automatic       TRUE   1.00000 0.000000
    7           Duster 360 Automatic Automatic       TRUE   0.92784 0.072165
    8            Merc 240D Automatic Automatic       TRUE   0.63964 0.360360
    9             Merc 230 Automatic    Manual      FALSE   0.42308 0.576923
    10            Merc 280 Automatic Automatic       TRUE   0.69608 0.303922
    11           Merc 280C Automatic Automatic       TRUE   0.76364 0.236364
    12          Merc 450SE Automatic Automatic       TRUE   0.99048 0.009524
    13          Merc 450SL Automatic Automatic       TRUE   0.99029 0.009709
    14         Merc 450SLC Automatic Automatic       TRUE   1.00000 0.000000
    15  Cadillac Fleetwood Automatic Automatic       TRUE   1.00000 0.000000
    16 Lincoln Continental Automatic Automatic       TRUE   1.00000 0.000000
    17   Chrysler Imperial Automatic Automatic       TRUE   1.00000 0.000000
    18            Fiat 128    Manual    Manual       TRUE   0.10377 0.896226
    19         Honda Civic    Manual    Manual       TRUE   0.02083 0.979167
    20      Toyota Corolla    Manual    Manual       TRUE   0.16814 0.831858
    21       Toyota Corona Automatic    Manual      FALSE   0.41509 0.584906
    22    Dodge Challenger Automatic Automatic       TRUE   0.99010 0.009901
    23         AMC Javelin Automatic Automatic       TRUE   1.00000 0.000000
    24          Camaro Z28 Automatic Automatic       TRUE   0.82456 0.175439
    25    Pontiac Firebird Automatic Automatic       TRUE   0.98095 0.019048
    26           Fiat X1-9    Manual    Manual       TRUE   0.02419 0.975806
    27       Porsche 914-2    Manual    Manual       TRUE   0.08411 0.915888
    28        Lotus Europa    Manual    Manual       TRUE   0.11458 0.885417
    29      Ford Pantera L    Manual Automatic      FALSE   0.54717 0.452830
    30        Ferrari Dino    Manual    Manual       TRUE   0.25490 0.745098
    31       Maserati Bora    Manual Automatic      FALSE   0.64348 0.356522
    32          Volvo 142E    Manual    Manual       TRUE   0.24107 0.758929

This data frame gives the `id` of each case, the `original` class of that case, the `predicted` class of the case, and whether or not the assignment `is.correct`. The following columns give the proportion of trees in the forest that voted for that class when the sample was OOB. These can be thought of as the assignment probabilities for each case and will sum to 1 across all classes.

### plotVotes()

A distribution of these assignment probabilities can be visualized with the `plotVotes()` function:

    plotVotes(rp)

The individual samples are arrayed along the x-axis, sorted by class and probability of assignment. The y-axis shows the probability of assignment to each class which is denoted by color in the figure. Models showing strong assignments will have a steep break at the class panel with most individuals in each class having high probabilities to their original class.

### pctCorrect()

The cutoff probability for assignment defaults to 1/k where k is the number of classes. For example, in a two-class model, this is 0.5, while in a three-class model it is 0.3333. Whichever class gets that number or greater votes in the forest is the predicted class. Sometimes, it is good to explore how the class-specific classification rates change if this value is made more stringent. This tells us something about how strongly cases were assigned to classes. We can get a sense of this from looking at the percent that would be correctly classified at different cutoffs with the function `pctCorrect()`:

    pctCorrect(rp, pct = c(0.6, 0.8, 0.95))

          class pct.correct_0.6 pct.correct_0.8 pct.correct_0.95
    1 Automatic           89.47           73.68            57.89
    2    Manual           84.62           61.54            15.38
    3   Overall           87.50           68.75            40.62

Notice that as the cutoff increases, the percent correct at each cutoff decreases, but it is clear that a higher proportion of automatic transmission cases are correctly classified with a higher probability. That is, the model is more certain of these classifications than of the manual transmission cases.

### plotPredictedProbs()

A final exploratory feature of assignment probabilities is an exploration of the differnce in distributions of correct classifications and misclassifications by class. In models with strong performance, it is expected that most misclassified individuals will be weakly classified (have low assignment probabilities) to the wrong class, while the correctly classified individuals will be strongly classified to their own class. The `plotPredictedProbs()` function lets us explore these distributions:

    plotPredictedProbs(rp)

We can see that most of the automatic transmission cases are correctly classified with assignment probabilities greater than 0.7, while the misclassified manual transmission cases have probabilities below tis value. The same is true for the manual transmission classifications.

### plotProximity()

We can visualize the distribution of individual cases in the Random Forest with a proximity plot. Case proximity is a summary of the relative nearness of cases in trees across the whole forest and is produced by setting `proximity = TRUE` in a call to `rfPermute()` or `randomForest()`. The `plotProximity()` function then visualizes this matrix using multi-dimensional scaling:

    rp <- rfPermute(am ~ ., df, nrep = 1000, proximity = TRUE, num.cores = 6)
    plotProximity(rp)

Here, the color of the inner dot indicates the original class, while the outer circle indicates the class to which it was classified. In addtion, 95% confidence ellipses are added for each class.

## 5. Miscellaneous

### combineRP()

If you wish to combine `rfPermute` models (say run on different systems), this can be done with the `combineRP()` function which is a wrapper for `randomForest::combine()` that also combines the null distributions and recalculates the relevant p-values:

    data(iris)
    rp1 <- rfPermute(Species ~ ., iris, ntree = 10, norm.votes = FALSE)
    rp2 <- rfPermute(Species ~ ., iris, ntree = 10, norm.votes = FALSE)
    rp3 <- rfPermute(Species ~ ., iris, ntree = 10, norm.votes = FALSE)

    print(rp1)

    An rfPermute model

                   Type of random forest: classification
                         Number of trees: 10
    No. of variables tried at each split: 2
           No. of permutation replicates: 100
                              Start time: 2022-02-09 17:12:03
                                End time: 2022-02-09 17:12:03
                                Run time: 0.216 secs

               setosa versicolor virginica pct.correct LCI_0.95 UCI_0.95
    setosa         50          0         0       100.0     92.9    100.0
    versicolor      0         47         3        94.0     83.5     98.7
    virginica       0          2        47        95.9     86.0     99.5
    Overall        NA         NA        NA        96.6     92.3     98.9

    print(rp2)

    An rfPermute model

                   Type of random forest: classification
                         Number of trees: 10
    No. of variables tried at each split: 2
           No. of permutation replicates: 100
                              Start time: 2022-02-09 17:12:03
                                End time: 2022-02-09 17:12:03
                                Run time: 0.202 secs

               setosa versicolor virginica pct.correct LCI_0.95 UCI_0.95
    setosa         49          0         0       100.0     92.7    100.0
    versicolor      0         47         3        94.0     83.5     98.7
    virginica       0          5        44        89.8     77.8     96.6
    Overall        NA         NA        NA        94.6     89.6     97.6

    print(rp3)

    An rfPermute model

                   Type of random forest: classification
                         Number of trees: 10
    No. of variables tried at each split: 2
           No. of permutation replicates: 100
                              Start time: 2022-02-09 17:12:03
                                End time: 2022-02-09 17:12:04
                                Run time: 0.214 secs

               setosa versicolor virginica pct.correct LCI_0.95 UCI_0.95
    setosa         49          1         0        98.0     89.4     99.9
    versicolor      0         47         3        94.0     83.5     98.7
    virginica       0          3        47        94.0     83.5     98.7
    Overall        NA         NA        NA        95.3     90.6     98.1

    rp.all <- combineRP(rp1, rp2, rp3)
    print(rp.all)

    An rfPermute model

                   Type of random forest: classification
                         Number of trees: 30
    No. of variables tried at each split: 2
           No. of permutation replicates: 300
                              Start time: 2022-02-09 17:12:03
                                End time: 2022-02-09 17:12:03
                                Run time: 0 secs

               setosa versicolor virginica pct.correct LCI_0.95 UCI_0.95
    setosa         50          0         0       100.0     92.9    100.0
    versicolor      0         47         3        94.0     83.5     98.7
    virginica       0          2        48        96.0     86.3     99.5
    Overall        NA         NA        NA        96.7     92.4     98.9

### cleanRFdata()

The package also provides a helper function for preparing a data frame for a Random Forest classification model. It removes predictors that are constant and cases with missing data.