Random Forest improves estimation performance and reduces instability of decision tree by averaging multiple regression trees, obtained through bootstrap samples.
fit_rf <- randomForest(margin~., data = polls_2008)
plot(fit_rf)
It is possible to see that in this problem, with over 200 trees, the model converges.
Below is the final model of the random forest.
polls_2008 %>%
mutate(y_hat = predict(fit_rf, newdata = polls_2008)) %>%
ggplot() +
geom_point(aes(day, margin), size = 2, alpha = .5) +
geom_line(aes(day, y_hat), col="red")
With random forest, the final model does not have steps and is more flexible, achieved through averaging the estimates of the trees.