Plot the local importance scores calculated by ivarpro. Examine how one predictor's scores vary across observations, or compare score distributions across predictors in a summary plot.

# S3 method for class 'ivarpro'
plot(x, var, col.var = NULL, size.var = NULL,
  data = NULL, target = NULL, pch = 16, cex = 0.8,
  cex.range = c(0.5, 2), main = NULL, xlab = NULL,
  ylab = "iVarPro gradient", legend = TRUE, ...)

shap.ivarpro(ivar, dat = NULL, feature_names = NULL,
  max.points = 5000, max.points.per.feature = NULL,
  point.alpha = 1.0, point.size = 0.35, point.pch = 16,
  scale.value = TRUE, style = c("blobby", "jitter"),
  blobby.separation = 3, target = NULL)

Arguments

x, ivar

An ivarpro object, or a numeric data frame or matrix with one row per observation and one column per predictor containing the local importance scores.

var

Predictor to display, given by its column name or index in the gradient table. For a categorical predictor converted to 0/1 indicators, use an indicator column's name or index.

col.var

Name of a column in the plotting data used to color points. Factors and numeric variables with few distinct values give group colors; continuous variables give a color gradient.

size.var

Name of a column in the plotting data used to scale point sizes.

data, dat

Data frame or matrix with the same observations in the same order as the gradient table. By default, uses the data stored by ivarpro or predict.ivarpro. The plotted predictor columns must be numeric; the stored data include the 0/1 indicators used for categorical predictors.

target

For an object with several targets, the response or class name, or its integer position. If omitted, the first target is used with a warning.

pch, cex

Point symbol and size for the single-predictor plot. Group-specific point styles can override pch.

cex.range

Range of point sizes when size.var is supplied.

main, xlab, ylab

Plot title and axis labels.

legend

Logical. If TRUE, displays the color legend in the single-predictor plot when col.var is supplied.

...

Graphical arguments and optional display controls for plot; see Details.

feature_names

Names for an unnamed gradient matrix in the summary plot. Existing column names take precedence.

max.points

Maximum total number of points displayed in the summary plot. A random subset is plotted when this limit is exceeded.

max.points.per.feature

Optional additional limit on the number of displayed points per predictor.

point.alpha, point.size, point.pch

Point opacity, size, and symbol for the summary plot.

scale.value

Logical. If TRUE, rescales each predictor's displayed values to the range zero to one for coloring. With FALSE, uses a common range across predictors. This affects the colors, not the importance scores.

style

Arrangement of points in the summary plot. "blobby" separates overlapping points to show where scores are concentrated; "jitter" adds random vertical displacement.

blobby.separation

Spacing between points for style = "blobby". Larger values increase separation.

Details

These plots show how the local relationships estimated by ivarpro vary across observations. Use shap.ivarpro(x) for an overview of the predictors, then plot(x, var = "x1") to examine one predictor more closely. Each point represents an observation's local importance score for a predictor.

The scores summarize local slopes, called gradients. With signed scores, positive values indicate that larger predictor values locally accompany larger values of the prediction target; negative values indicate the opposite direction. Distance from zero shows the strength of the local change on the chosen scale. Results calculated with use.abs = TRUE show strength without direction.

Single-predictor plot

plot(x, var = "x1") places values of x1 on the horizontal axis and its local scores on the vertical axis. A line at zero separates positive and negative scores. Add col.var = "x2" to see whether the relationship with x1 differs according to x2. size.var can represent a further variable through point size.

Smooth curves are added by default when enough observations are available: one curve without a color variable, or separate curves for its groups. Continuous color variables are divided into ranges based on quantiles for these curves.

Adjusting the single-predictor plot

Supply these controls through ...:

Smooth curves

Use smooth = FALSE to omit them, or smooth.span to adjust smoothing.

Overlapping points

Small horizontal jitter is added by default. Use jitter = FALSE to disable it, or jitter.seed for reproducible jitter. col.style selects "auto", "solid", "outline", or "binary" point styling. The automatic style distinguishes categorical color groups using outlined or filled and open symbols.

Predictor distribution

Use x.dist = "rug" for ticks showing observed predictor values, x.dist = "hist" for a histogram, or x.dist = "density" for a density curve. Combinations such as x.dist = c("hist", "rug") are allowed. These displays use observations with plotted scores.

Zero reference line

Use zero.line = FALSE to omit it.

Summary plot

shap.ivarpro(x) gives each predictor a separate row. Horizontal position shows the score; color shows the observation's predictor value. Predictors are ordered by their mean absolute scores. In the default "blobby" display, overlapping points are spread vertically to show where scores are concentrated. This SHAP-style layout displays the local gradients calculated by ivarpro.

By default, colors show low to high values separately for each predictor. scale.value controls this color scaling. The gradient scale is set by the original ivarpro call: for example, scale = "global" uses the predictor's training-sample standard deviation, and scale = "none" gives slopes per predictor unit. See ivarpro for the scaling choices.

Columns with only zero or nonfinite scores are omitted. Each point requires a finite score and predictor value. max.points and max.points.per.feature limit the display size without changing the stored scores.

Choosing a target and supplying data

For a list of responses or classes, supply the whole object and choose one with target, for example plot(x, var = "x1", target = 2). Omitting target selects the first element with a warning.

Both functions use stored data by default. When no data are stored, supply the matching predictor values through data to plot or dat to shap.ivarpro. Rows must match the gradient table, and column names should match the plotted predictors. For categorical predictors, use the same numeric 0/1 indicator columns used to calculate their scores.

Value

Draws the requested plot. plot.ivarpro returns TRUE invisibly; shap.ivarpro returns NULL invisibly.

Examples

# \donttest{
## Compare local mortality gradients and inspect peak oxygen uptake.
library(survival)
data(peakVO2, package = "randomForestSRC")
peak <- na.omit(peakVO2)
set.seed(137)
vp <- varpro(Surv(ttodead, died) ~ ., peak,
             split.weight = FALSE, ntree = 100,
             parallel = FALSE)
ivp <- ivarpro(vp)
print(head(ivp))
shap.ivarpro(ivp)
plot(ivp, var = "peak.vo2", col.var = "interval")
## scale points to "y" (here equal to mortality)
plot(ivp, var = "peak.vo2", col.var = "interval", size.var = "y",
     x.dist = c("hist", "rug"), jitter = FALSE)
# }