if (FALSE) {
#---------------------------------------------------------------------
# MASS::Boston data - regression random forest
#---------------------------------------------------------------------
# load the rfsrc object from the cached data
data(rfsrc_boston, package="ggRandomForests")
# The plot.variable call
partial_boston <- plot.variable(rfsrc_boston,
partial=TRUE, show.plots = FALSE )
# plot the forest partial plots
gg_dta <- gg_partial(partial_boston)
plot(gg_dta, panel=TRUE)
#---------------------------------------------------------------------
# randomForestSRC::pbc data - survival random forest
#---------------------------------------------------------------------
# load the rfsrc object from the cached data
data(rfsrc_pbc, package="ggRandomForests")
# Restrict the time of interest to less than 5 years.
time_pts <- rfsrc_pbc$time.interest[which(rfsrc_pbc$time.interest<=5)]
# Find the 50 points in time, evenly space along the distribution of
# event times for a series of partial dependence curves
time_cts <-quantile_pts(time_pts, groups = 50)
# Generate the gg_partial_coplot data object
system.time(partial_pbc_time <- lapply(time_cts, function(ct) {
plot.variable(rfsrc_pbc, xvar = "bili", time = ct,
npts = 50, show.plots = FALSE,
partial = TRUE, surv.type="surv")
}))
# user system elapsed
# 2561.313 81.446 2641.707
# Find the quantile points to create 50 cut points
alb_partial_pts <-quantile_pts(rfsrc_pbc$xvar$albumin, groups = 50)
system.time(partial_pbc_surf <- lapply(alb_partial_pts, function(ct) {
rfsrc_pbc$xvar$albumin <- ct
plot.variable(rfsrc_pbc, xvar = "bili", time = 1,
npts = 50, show.plots = FALSE,
partial = TRUE, surv.type="surv")
}))
# user system elapsed
# 2547.482 91.978 2671.870
}
Run the code above in your browser using DataLab