partial.plot: Partial relationship graph.

View source: R/partial.plot.r

partial.plotR Documentation

Partial relationship graph.

Description

Draw partial relationship graph between focal explanatory variables and response variable with controlling effects of other explanatory variables.

Usage

partial.plot(
  model,
  x.names,
  data = NULL,
  type = "response",
  positive.class = "",
  fun.3d = persp,
  draw.residual = TRUE,
  draw.relationship = TRUE,
  draw.interval = TRUE,
  draw.hist = FALSE,
  interval.levels = 0.95,
  resolution = NULL,
  col = gg.colors,
  lty = "solid",
  lwd = 1,
  pch = 16,
  xlab = NULL,
  ylab = NULL,
  zlab = NULL,
  add = FALSE,
  sep = " - ",
  extrapolate = FALSE,
  n.cores = NULL,
  draw = TRUE,
  extraporate = extrapolate,
  ...
)

Arguments

model

a model object by which relationship between focal explanatory variables and response variables is determined. Basically, statistical models and machine learning models supported by model.adapter class are supported.

x.names

a character vector specifying name of focal explanatory variables. Combination of one or two numeric factors and any number of factors is supported. Currently, at least one numeric variable should be specified. This problem may be fixed in future.

data

a data.frame used for prediction. If not specified, this function try to obtain original data used for the modeling from the object specified by the model argument.

type

a character literal indicating type of scale of plotting. This is similar to type argument of many predict methods. Possible values are "response", "link" and "prob". If "link" is specified, partial relationship and residuals are drawn in the scale of the linear predictor. On the other hand, partial relationship and residuals are drawn in the scale of the response variable if "response" is specified. For classification models, only "prob", which calculate probability of a specific class, can be used. Future version will automatically change type to "prob" for classification models.

positive.class

a class for which predicted probability is calculated. If not specified, first class of the factor or first unique value of the response variable is used.

fun.3d

a function to produce 3d graph. Currently persp, image, contour and persp3d are supported.

draw.residual

a logical. If TRUE, points representing partial residual are drawn. When 'prob' is specified for type, draw.residual is set to FALSE.

draw.relationship

a logical. If TRUE, partial relationships between focal explanatory variables and response variable are drawn.

draw.interval

a logical. If TRUE, interval of partial relationships are drawn. Note that currently this intervals are confidential intervals if model is supported by lsmeans and are quantile of perdicted values for the model not supported by lsmeans.

interval.levels

values between 0 <= levels <= 1 indicating level(s) of interval.

For the models supported by lsmeans, this can be a value indicating confidence interval. Only the first element of the numeric vector is used for confidence intervals.

For the models not supported by lsmeans, this can be a value of lower and upper quantile, e.g., values = 0.95 indicates lower quantile is 0.05 and uppter quantile is 0.95. A numeric vector of length two specifying both lower and upper quantiles also can be specified.

resolution

an integer specifying resolution of lines, polygons, wireframes, and images of numeric variables. Default value is 100 for 2D plots and 10 for 3D plots. Larger number indicate higher resolution. Note that this parameter can affect computation time so that higher resolution require more times to draw the graph.

col, lty, lwd, pch

a functions or vectors representing graphic parameters. For the detail, see pal option of color.ramp function.

xlab, ylab, zlab

label of X, Y and Z axis.

add

add graphic element to existing plot if TRUE.

sep

a character used for separator of factor levels.

extrapolate

a logical indicating whether extrapolation is allowed for predicted relationships.

n.cores

an integer representing number of processes used for calculation. If NULL is specified, maximum number of logical processors are used. This value is ignored when the models compatible with lsmeans are specified.

draw

if TRUE, draw partial dependence plot. If FALSE, only calculations of plot parameters were done.

...

other graphic parameters passed to plotting functions. Possible parameters for each element of the graph is:

Partial relatioship lines

lty, lwd, lend,ljoin, lmitre, col, parameters supported by lines.default.

Interval of partial relationship

none.

Partial residual points

pch, bg, cex, col, parameters supported by points.default. In the case not drawing interval of partial relationship, all parameters are used.

3D partial relationship by persp

cex.lab, font.lab, cex.axis, font.axis, parameters supported by persp.default.

3D partial relationship by image

asp, axes, bg, paramters supported by link[graphics]{image.default},

3D partial relationship by contour

xaxs, yaxs, lab, col.main, cex.sub, xpd, mgp, cex.axis, col.axis, font.axis, xaxp, yaxp, tck, tcl, las, fg, xaxt, yaxt, bty, parameters supported by contour.default, plot.window, title, Axis, axis and box functions.

3D partial relationship by persp3d

col, parameters supported by persp3d.default, surface3d and rgl.material functions.

Details

For models supported by lsmeans, this function calculate partial dependence using lsmeans and adjusted partial residual to match result of lsmeans. For models having complicated interactions such as machine learning models, partial dependence is calculated by similar way as partialPlot function in randomForest package.

For the detailed explanation, see vignette("partial.plot") (English) or vignette("partial.plot.j") (Japanese)

Value

An object of pp.legend containing information which will be used for drawing legend.

Examples

#---------------------------------------------------------------------------
# Example 1: normal partial.plot with partial relationship graph with
# points representing partial residuals.
#---------------------------------------------------------------------------
data(iris)
model <- lm(
    Petal.Length ~ (Sepal.Length + Petal.Width) * Species, data = iris
)
partial.plot(model, c("Sepal.Length", "Species"), pch = 16)
partial.plot(model, c("Petal.Width", "Species"), pch = 16)


#---------------------------------------------------------------------------
# Example 2: no residuals.
#---------------------------------------------------------------------------
partial.plot(
    model, c("Sepal.Length", "Species"), pch = 16, draw.residual = FALSE
)


#---------------------------------------------------------------------------
# Example 3: no partial relationship.
#---------------------------------------------------------------------------
partial.plot(
    model, c("Sepal.Length", "Species"), pch = 16,
    draw.relationship = FALSE
)


Marchen/partial.plot documentation built on Feb. 13, 2025, 4:18 a.m.