View source: R/utilities_ivarpro.R
| partial.ivarpro | R Documentation |
partial.ivarpro() draws a base-graphics scatterplot of case-specific
iVarPro gradients for one predictor: x is the predictor value and y is the
iVarPro local gradient. Points can be colored (col.var), sized
(size.var), optionally jittered, and optionally overlaid with loess
smooths stratified by col.var.
partial.ivarpro(ivar,
var,
col.var = NULL,
size.var = NULL,
x = NULL,
ladder = FALSE,
ladder.cuts = NULL,
ladder.max.segments = 3000,
pch = 16,
cex = 0.8,
cex.range = c(0.5, 2),
main = NULL,
xlab = NULL,
ylab = "iVarPro gradient",
legend = TRUE,
...)
ivar |
An object returned by |
var |
Variable to plot (name or column index). Must exist in both
|
col.var |
Optional variable (column name in |
size.var |
Optional variable (column name in |
x |
Optional data.frame or matrix of original feature values. |
ladder |
Logical. If |
ladder.cuts |
Optional subset of ladder indices/values used for the band. |
ladder.max.segments |
Maximum number of ladder segments to draw. |
pch |
Point character for the default point style. |
cex |
Base point size (used when |
cex.range |
Min/max point sizes used when |
main |
Main title (defaults to |
xlab |
X-axis label (defaults to |
ylab |
Y-axis label (defaults to |
legend |
Logical. If |
... |
Additional arguments passed to
|
Jitter is applied for visualization only; loess smooths and the optional
x-axis distribution strip (x.dist) are computed using the
unjittered x-values.
Invisibly returns TRUE.
ivarpro, varpro, shap.ivarpro
## ------------------------------------------------------------
##
## Survival example: peakVO2 partial plot
##
## ------------------------------------------------------------
data(peakVO2, package = "randomForestSRC")
ipv <- ivarpro(varpro(Surv(ttodead, died) ~ ., peakVO2))
## Continuous col.var: legend + smooth strata default to 5 quantiles
partial.ivarpro(ipv, var = "peak.vo2", col.var = "interval", size.var = "y")
## Add an x-axis distribution strip (histogram + rug)
partial.ivarpro(ipv, var = "peak.vo2", col.var = "interval", size.var = "y",
x.dist = c("hist", "rug"))
## Increase legend/smooth strata (e.g., 7 quantiles)
partial.ivarpro(ipv, var = "peak.vo2", col.var = "interval", size.var = "y",
col.legend.n = 7, smooth.n = 7)
## Classic 3-quantile view (5%, 50%, 95%)
partial.ivarpro(ipv, var = "peak.vo2", col.var = "interval", size.var = "y",
col.legend.probs = c(0.05, 0.5, 0.95),
smooth.probs = c(0.05, 0.5, 0.95))
## Factor col.var example: one smooth per level
partial.ivarpro(ipv, var = "peak.vo2", col.var = "betablok", size.var = "y")
## ------------------------------------------------------------
##
## multiclass example: iris (use target= to choose a class)
##
## ------------------------------------------------------------
data(iris)
vp.ir <- varpro(Species ~ ., iris, ntree = 50)
ivp.ir <- ivarpro(vp.ir)
## Plot gradients for the "setosa" class (target selects the list element)
partial.ivarpro(ivp.ir, var = "Petal.Length", target = "setosa",
col.var = "Species", x = iris)
## Alternatively, color by the predicted class probability stored in ivp.ir
partial.ivarpro(ivp.ir, var = "Petal.Length", target = "setosa",
col.var = "y.setosa")
## ------------------------------------------------------------
##
## multiclass example: wine (advanced example)
##
## ------------------------------------------------------------
data(wine, package = "randomForestSRC")
## Give the class labels nicer names than "3", "4", ..., "9"
wine$quality <- factor(wine$quality)
levels(wine$quality) <- paste0("Q", levels(wine$quality)) # "Q3" "Q4" ... "Q9"
vp <- varpro(quality ~ ., wine, ntree = 50)
ivp <- ivarpro(vp)
## Available targets correspond to class probability columns
names(ivp)
## Build a plotting data.frame that contains:
## - predictors (from attr(ivp,"data"))
## - predicted class probabilities (y.Q3, y.Q4, ..., y.Q9)
## - the observed class label (quality)
xdat <- attr(ivp, "data")
xdat$quality <- wine$quality
## Plot gradients for the "Q7" class:
## y-axis: d P(Y="Q7" | x) / d alcohol (iVarPro gradient)
## x-axis: alcohol
## color: observed class label
partial.ivarpro(ivp, var = "alcohol", target = "Q7",
x = xdat, col.var = "quality")
## Alternatively, color by the model's predicted probability for the same class.
## (These columns come from attr(ivp,"data") as y.<class>)
partial.ivarpro(ivp, var = "alcohol", target = "Q7", col.var = "y.Q7")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.