Learn R Programming

ggRandomForests (version 1.1.1)

plot.gg_variable: Plot a gg_variable object,

Description

Plot a gg_variable object,

Usage

## S3 method for class 'gg_variable':
plot(x, x_var, time, time_labels, panel = FALSE,
  oob = TRUE, smooth = TRUE, ...)

Arguments

x
gg_variable object created from a randomForestSRC::rfsrc object
x_var
variable (or list of variables) of interest.
time
For survival, one or more times of interest
time_labels
string labels for times
panel
Should plots be facetted along multiple x_var?
oob
oob estimates (boolean)
smooth
type of smooth curve
...
arguments passed to the gg_variable function.

Value

  • ggplot object

References

Breiman L. (2001). Random forests, Machine Learning, 45:5-32.

Ishwaran H. and Kogalur U.B. (2007). Random survival forests for R, Rnews, 7(2):25-31.

Ishwaran H. and Kogalur U.B. (2013). Random Forests for Survival, Regression and Classification (RF-SRC), R package version 1.4.

Examples

Run this code
## ------------------------------------------------------------
## classification
## ------------------------------------------------------------

## iris
#iris.obj <- rfsrc(Species ~., data = iris)
data(iris_rf, package="ggRandomForests")


## ------------------------------------------------------------
## regression
## ------------------------------------------------------------

## airquality
#airq.obj <- rfsrc(Ozone ~ ., data = airquality)
data(airq_rf, package="ggRandomForests")
gg_dta <- gg_variable(airq_rf)
plot(gg_dta, x_var="Wind")
plot(gg_dta, x_var="Temp")
plot(gg_dta, x_var="Solar.R")

## motor trend cars
#mtcars.obj <- rfsrc(mpg ~ ., data = mtcars)
data(mtcars_rf, package="ggRandomForests")
gg_dta <- gg_variable(mtcars_rf)

# mtcars$cyl is an ordinal variable
plot(gg_dta, x_var="cyl")

# Others are continuous
plot(gg_dta, x_var="disp")
plot(gg_dta, x_var="hp")
plot(gg_dta, x_var="wt")

## ------------------------------------------------------------
## survival examples
## ------------------------------------------------------------

## survival
# data(veteran, package = "randomForestSRC")
# veteran_rf <- rfsrc(Surv(time,status)~., veteran, nsplit = 10, ntree = 100)
data(veteran_rf, package="ggRandomForests")

# get the 30 day survival time.
gg_dta <- gg_variable(veteran_rf, time=30)

# Generate variable dependance plots for age and diagtime
plot(gg_dta, x_var = "age")
plot(gg_dta, x_var = "diagtime")

# If we want to compare survival at different time points, say 30, 90 day
# and 1 year
gg_dta <- gg_variable(veteran_rf, time=c(30, 90, 365))

# Generate variable dependance plots for age and diagtime
plot(gg_dta, x_var = "age")
plot(gg_dta, x_var = "diagtime")

Run the code above in your browser using DataLab