Learn R Programming

ggRandomForests (version 1.0.0)

gg_variable.ggRandomForests: Marginal variable depedance data object.

Description

randomForestSRC::plot.variable generates a data.frame containing the marginal variable dependance or the partial variable dependence. The gg_variable function creates a data.frame of containing the full set of covariate data (predictor variables) and the predicted response for each observation. Marginal dependence figures are created using the plot.gg_variable function.

Usage

gg_variable.ggRandomForests(object, time, time.labels, oob = TRUE, ...)

Arguments

object
a randomForestSRC::rfsrc object
time
point (or vector of points) of interest (for survival forests only)
time.labels
If more than one time is specified, a vector of time.labels for differentiating the time points (for survival forests only)
oob
indicate if predicted results should include oob or full data set.
...
extra arguments

Value

  • A matrix for creating the marginal variable dependence plots.

Details

The marginal variable dependence is determined by comparing relation between the predicted response from the randomforest and a covariate of interest.

The gg_variable function operates on a randomForestSRC::rfsrc object, or the output from the randomForestSRC::plot.variable function.

See Also

plot.gg_variable randomForestSRC::plot.variable

Examples

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

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

## !! TODO... finish classification variable dependence
# ggrf <- gg_variable(iris_rf, which.outcome=1)


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

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

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

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

# Others are continuous
plot(ggrf, x_var="disp")
plot(ggrf, x_var="hp")
plot(ggrf, 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 1 year survival time.
ggrf <- gg_variable(veteran_rf, time=30)

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

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

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

Run the code above in your browser using DataLab