#---------------------------------------------------------------------
# iris data - classification random forest
#---------------------------------------------------------------------
# rfsrc grow call
rfsrc_iris <- rfsrc(Species ~., data = iris)
# plot the forest generalization error convergence
gg_dta <- gg_error(rfsrc_iris)
plot(gg_dta)
# Plot the forest predictions
gg_dta <- gg_rfsrc(rfsrc_iris)
plot(gg_dta)
#---------------------------------------------------------------------
# airq data - regression random forest
#---------------------------------------------------------------------
# rfsrc grow call
rfsrc_airq <- rfsrc(Ozone ~ ., data = airquality,
na.action = "na.impute")
# plot the forest generalization error convergence
gg_dta <- gg_error(rfsrc_airq)
plot(gg_dta)
# Plot the forest predictions
gg_dta <- gg_rfsrc(rfsrc_airq)
plot(gg_dta)
#---------------------------------------------------------------------
# mtcars data - regression random forest
#---------------------------------------------------------------------
# rfsrc grow call
rfsrc_mtcars <- rfsrc(mpg ~ ., data = mtcars)
# plot the forest generalization error convergence
gg_dta <- gg_error(rfsrc_mtcars)
plot(gg_dta)
# Plot the forest predictions
gg_dta <- gg_rfsrc(rfsrc_mtcars)
plot(gg_dta)
#---------------------------------------------------------------------
# MASS::Boston data - regression random forest
#---------------------------------------------------------------------
# Load the data...
data(Boston, package="MASS")
Boston$chas <- as.logical(Boston$chas)
# rfsrc grow call
rfsrc_Boston <- rfsrc(medv~., data=Boston)
# plot the forest generalization error convergence
gg_dta <- gg_error(rfsrc_Boston)
plot(gg_dta)
# Plot the forest predictions
gg_dta <- gg_rfsrc(rfsrc_Boston)
plot(gg_dta)
#---------------------------------------------------------------------
# randomForestSRC::pbc data - survival random forest
#---------------------------------------------------------------------
# Load the data...
# For simplicity here. We do a bit of data tidying
# before running the stored random forest.
data(pbc, package="randomForestSRC")
# Remove non-randomized cases
dta.train <- pbc[-which(is.na(pbc$treatment)),]
# rfsrc grow call
rfsrc_pbc <- rfsrc(Surv(years, status) ~ ., dta.train, nsplit = 10,
na.action="na.impute")
# plot the forest generalization error convergence
gg_dta <- gg_error(rfsrc_pbc)
plot(gg_dta)
# Plot the forest predictions
gg_dta <- gg_rfsrc(rfsrc_pbc)
plot(gg_dta)
#---------------------------------------------------------------------
# randomForestSRC::veteran data - survival random forest
#---------------------------------------------------------------------
# load the data...
# For simplicity. We do a bit of data tidying
# before running the stored random forest.
data(veteran, package="randomForestSRC")
# rfsrc grow call
rfsrc_veteran <- rfsrc(Surv(time, status) ~ ., data = veteran, ...)
# plot the forest generalization error convergence
gg_dta <- gg_error(rfsrc_veteran)
plot(gg_dta)
# Plot the forest predictions
gg_dta <- gg_rfsrc(rfsrc_veteran)
plot(gg_dta)
Run the code above in your browser using DataLab