'randomForest error this function only works for objects of class `(rfsrc, grow)' or '(rfsrc, forest)'

I am trying to generate a partial dependance plot from my tree classification model. I am using randomForest model and I am getting an error message. Would someone point me in the right direction?

"Error in partial(rf.model, pred.var = top_five_predictors[4], plot = FALSE, : this function only works for objects of class `(rfsrc, grow)' or '(rfsrc, forest)'

Here is an extract of my code:

top_five_predictors = c("annualised_mileage", "mth_since_last_serv", "age_of_vehicle_years", "num_serv_dealer_purchased", "sched_serv_warr")

#Construct the 5 plots
library(pdp)

# Annualised Mileage
p1 <- partial(rf.model, pred.var = top_five_predictors[1], plot = FALSE, rug = TRUE, plot.engine = "ggplot2")```



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source