Plots partial dependence functions (i.e., marginal effects) using lattice graphics.
Usage
plotPartial(object, ...)
# S3 method for class 'ice'
plotPartial(
object,
center = FALSE,
plot.pdp = TRUE,
pdp.col = "red2",
pdp.lwd = 2,
pdp.lty = 1,
rug = FALSE,
train = NULL,
...
)
# S3 method for class 'cice'
plotPartial(
object,
plot.pdp = TRUE,
pdp.col = "red2",
pdp.lwd = 2,
pdp.lty = 1,
rug = FALSE,
train = NULL,
...
)
# S3 method for class 'partial'
plotPartial(
object,
center = FALSE,
plot.pdp = TRUE,
pdp.col = "red2",
pdp.lwd = 2,
pdp.lty = 1,
smooth = FALSE,
rug = FALSE,
chull = FALSE,
levelplot = TRUE,
contour = FALSE,
contour.color = "white",
col.regions = NULL,
number = 4,
overlap = 0.1,
train = NULL,
...
)Arguments
- object
An object that inherits from the
"partial"class.- ...
Additional optional arguments to be passed onto
dotplot,levelplot,xyplot, orwireframe.- center
Logical indicating whether or not to produce centered ICE curves (c-ICE curves). Only useful when
objectrepresents a set of ICE curves; seepartial()for details. Default isFALSE.- plot.pdp
Logical indicating whether or not to plot the partial dependence function on top of the ICE curves. Default is
TRUE.- pdp.col
Character string specifying the color to use for the partial dependence function when
plot.pdp = TRUE. Default is"red".- pdp.lwd
Integer specifying the line width to use for the partial dependence function when
plot.pdp = TRUE. Default is1. Seegraphics::par()for more details.- pdp.lty
Integer or character string specifying the line type to use for the partial dependence function when
plot.pdp = TRUE. Default is1. Seegraphics::par()for more details.- rug
Logical indicating whether or not to include rug marks on the predictor axes. Default is
FALSE.- train
Data frame containing the original training data. Only required if
rug = TRUEorchull = TRUE.- smooth
Logical indicating whether or not to overlay a LOESS smooth. Default is
FALSE.- chull
Logical indicating whether or not to restrict the first two variables in
pred.varto lie within the convex hull of their training values; this affectspred.grid. Default isFALSE.- levelplot
Logical indicating whether or not to use a false color level plot (
TRUE) or a 3-D surface (FALSE). Default isTRUE.- contour
Logical indicating whether or not to add contour lines to the level plot. Only used when
levelplot = TRUE. Default isFALSE.- contour.color
Character string specifying the color to use for the contour lines when
contour = TRUE. Default is"white".- col.regions
Vector of colors to be passed on to
lattice::levelplot()'scol.regionargument. Defaults togrDevices::hcl.colors(100)(which is the same viridis color palette used in the past).- number
Integer specifying the number of conditional intervals to use for the continuous panel variables. See
graphics::co.intervals()andlattice::equal.count()for further details.- overlap
The fraction of overlap of the conditioning variables. See
graphics::co.intervals()andlattice::equal.count()for further details.
Details
Deprecated: plotPartial() is deprecated and will be removed
in a future release; please use plot(..., lattice = TRUE) instead,
which produces the same displays through a single interface (see
plot.partial() for details).
Examples
if (FALSE) { # \dontrun{
#
# Regression example (requires randomForest package to run)
#
# Load required packages
library(gridExtra) # for `grid.arrange()`
library(magrittr) # for forward pipe operator `%>%`
library(randomForest)
# Fit a random forest to the Boston housing data
data (boston) # load the boston housing data
set.seed(101) # for reproducibility
boston.rf <- randomForest(cmedv ~ ., data = boston)
# Partial dependence of cmedv on lstat
boston.rf %>%
partial(pred.var = "lstat") %>%
plotPartial(rug = TRUE, train = boston)
# Partial dependence of cmedv on lstat and rm
boston.rf %>%
partial(pred.var = c("lstat", "rm"), chull = TRUE, progress = TRUE) %>%
plotPartial(contour = TRUE, legend.title = "rm")
# ICE curves and c-ICE curves
age.ice <- partial(boston.rf, pred.var = "lstat", ice = TRUE)
p1 <- plotPartial(age.ice, alpha = 0.1)
p2 <- plotPartial(age.ice, center = TRUE, alpha = 0.1)
grid.arrange(p1, p2, ncol = 2)
} # }