plot.DynForest {DynForest}R Documentation

Plot function in DynForest

Description

This function displays a plot of CIF for a given node and tree (for class DynForest), the most predictive variables with the minimal depth (for class DynForestVarDepth), the variable importance (for class DynForestVIMP) or the grouped variable importance (for class DynForestgVIMP).

Usage

## S3 method for class 'DynForest'
plot(x, tree = NULL, nodes = NULL, id = NULL, max_tree = NULL, ...)

## S3 method for class 'DynForestVarDepth'
plot(x, plot_level = c("predictor", "feature"), ...)

## S3 method for class 'DynForestVIMP'
plot(x, PCT = FALSE, ordering = TRUE, ...)

## S3 method for class 'DynForestgVIMP'
plot(x, PCT = FALSE, ...)

## S3 method for class 'DynForestPred'
plot(x, id = NULL, ...)

Arguments

x

Object inheriting from classes DynForest, DynForestVarDepth, DynForestVIMP or DynForestgVIMP, to respectively plot the CIF, the minimal depth, the variable importance or grouped variable importance.

tree

For DynForest class, integer indicating the tree identifier

nodes

For DynForest class, identifiers for the selected nodes

id

For DynForest and DynForestPred classes, identifier for a given subject

max_tree

For DynForest class, integer indicating the number of tree to display while using id argument

...

Optional parameters to be passed to the low level function

plot_level

For DynForestVarDepth class, compute the statistic at predictor (plot_level="predictor") or feature (plot_level="feature") level

PCT

For DynForestVIMP or DynForestgVIMP class, display VIMP statistic in percentage. Default value is FALSE.

ordering

For DynForestVIMP class, order predictors according to VIMP value. Default value is TRUE.

Value

plot() function displays:

With DynForestVarDepth the minimal depth for each predictor/feature
With DynForestVIMP the VIMP for each predictor
With DynForestgVIMP the grouped-VIMP for each given group

See Also

DynForest var_depth compute_VIMP compute_gVIMP

Examples


data(pbc2)

# Get Gaussian distribution for longitudinal predictors
pbc2$serBilir <- log(pbc2$serBilir)
pbc2$SGOT <- log(pbc2$SGOT)
pbc2$albumin <- log(pbc2$albumin)
pbc2$alkaline <- log(pbc2$alkaline)

# Sample 100 subjects
set.seed(1234)
id <- unique(pbc2$id)
id_sample <- sample(id, 100)
id_row <- which(pbc2$id%in%id_sample)

pbc2_train <- pbc2[id_row,]

timeData_train <- pbc2_train[,c("id","time",
                                "serBilir","SGOT",
                                "albumin","alkaline")]

# Create object with longitudinal association for each predictor
timeVarModel <- list(serBilir = list(fixed = serBilir ~ time,
                                     random = ~ time),
                     SGOT = list(fixed = SGOT ~ time + I(time^2),
                                 random = ~ time + I(time^2)),
                     albumin = list(fixed = albumin ~ time,
                                    random = ~ time),
                     alkaline = list(fixed = alkaline ~ time,
                                     random = ~ time))

# Build fixed data
fixedData_train <- unique(pbc2_train[,c("id","age","drug","sex")])

# Build outcome data
Y <- list(type = "surv",
          Y = unique(pbc2_train[,c("id","years","event")]))

# Run DynForest function
res_dyn <- DynForest(timeData = timeData_train, fixedData = fixedData_train,
                     timeVar = "time", idVar = "id",
                     timeVarModel = timeVarModel, Y = Y,
                     ntree = 50, nodesize = 5, minsplit = 5,
                     cause = 2, ncores = 2, seed = 1234)

# Plot estimated CIF at nodes 17 and 32
plot(x = res_dyn, tree = 1, nodes = c(17,32))

# Run var_depth function
res_varDepth <- var_depth(res_dyn)

# Plot minimal depth
plot(x = res_varDepth, plot_level = "feature")

# Compute VIMP statistic
res_dyn_VIMP <- compute_VIMP(DynForest_obj = res_dyn, ncores = 2)

# Plot VIMP
plot(x = res_dyn_VIMP, PCT = TRUE)

# Compute gVIMP statistic
res_dyn_gVIMP <- compute_gVIMP(DynForest_obj = res_dyn,
                               group = list(group1 = c("serBilir","SGOT"),
                                            group2 = c("albumin","alkaline")),
                               ncores = 2)

# Plot gVIMP
plot(x = res_dyn_gVIMP, PCT = TRUE)

# Sample 5 subjects to predict the event
set.seed(123)
id_pred <- sample(id, 5)

# Create predictors objects
pbc2_pred <- pbc2[which(pbc2$id%in%id_pred),]
timeData_pred <- pbc2_pred[,c("id", "time", "serBilir", "SGOT", "albumin", "alkaline")]
fixedData_pred <- unique(pbc2_pred[,c("id","age","drug","sex")])

# Predict the CIF function for the new subjects with landmark time at 4 years
pred_dyn <- predict(object = res_dyn,
                    timeData = timeData_pred, fixedData = fixedData_pred,
                    idVar = "id", timeVar = "time",
                    t0 = 4)

# Plot predicted CIF for subjects 26 and 110
plot(x = pred_dyn, id = c(26, 110))




[Package DynForest version 1.1.3 Index]