View source: R/partial_plot.boostmtree.R
| partial.plot | R Documentation |
Create partial-dependence summaries for one or more covariates from a fitted
boostmtree object. The function can either draw the plots immediately,
write them to a PDF file, or return the computed curve data for further use.
partial.plot(object, ...)
## S3 method for class 'boostmtree'
partial.plot(
object,
M = NULL,
x.var.names = NULL,
time.points = NULL,
x.var.values = NULL,
n.points = 25,
subset = NULL,
prob.class = FALSE,
response.labels = NULL,
conditional.x.var.names = NULL,
conditional.values = NULL,
output = c("plot", "data", "pdf"),
file = NULL,
verbose = TRUE,
use.cv.flag = NULL,
...
)
## S3 method for class 'partial.plot.boostmtree'
plot(
x,
output = c("plot", "pdf"),
file = NULL,
verbose = TRUE,
...
)
object |
A fitted object of class |
M |
Number of boosting iterations to use. By default the function uses the fitted stopping value when available and otherwise uses the full fitted path. |
x.var.names |
Names of the covariates for which partial-dependence summaries are requested. By default all fitted covariates are used. |
time.points |
Time points at which the fitted curves should be displayed. By default the deciles of the observed time values are used. Requested values are matched to the nearest observed training times. |
x.var.values |
Optional named list giving the covariate values at which each partial-dependence curve should be evaluated. When omitted, the function uses evenly spaced observed values. |
n.points |
Maximum number of covariate values used for each partial-dependence
curve when |
subset |
Optional vector selecting the fitted subjects to be used when averaging the partial-dependence curves. |
prob.class |
Logical flag used only for ordinal fits. When |
response.labels |
Optional character vector selecting which response
components to include in the summary. For continuous fits the only available
label is |
conditional.x.var.names |
Optional names of additional covariates whose values should be held fixed while the partial-dependence curves are computed. |
conditional.values |
Values corresponding to |
output |
Either |
file |
Optional file name used when |
verbose |
Should the file location be reported when PDF output is requested? |
use.cv.flag |
Should the partial-dependence curves be based on the
OOB/CV coefficient path? The default is to use the fitted object setting.
This option is only meaningful when the model was fitted with
|
x |
An object returned by |
... |
Further arguments passed to |
Partial-dependence plots show how the fitted mean response changes as one covariate is varied over a grid of values while the remaining covariates are held fixed at their observed values. In a longitudinal model this produces a family of curves, one for each requested time point.
For each chosen covariate value, the function constructs a modified subject-level
covariate data set, obtains fitted values from predict.boostmtree,
and then averages those fitted values over subjects at the selected times.
This gives an adjusted view of the fitted effect of the chosen covariate, in the
sense of Friedman (2001), while retaining the time-varying structure of the
longitudinal fit.
The returned object stores the computed curve data and can be plotted later with
plot(). For families with multiple boosted subproblems or multiple class
probabilities, response.labels can be used to restrict attention to a
subset of response components.
If output = "data", an object of class "partial.plot.boostmtree"
with components:
curvesPartial-dependence curves. For continuous and binary fits this is a named list indexed by covariate name. For nominal and ordinal fits it is a list indexed first by response component and then by covariate.
time.pointsThe observed time points used in the summary.
x.var.namesCovariate names included in the summary.
response.labelsSelected labels for the response component(s) included in the summary.
If output = "plot" or "pdf", the same object is returned
invisibly after plotting.
Friedman, J. H. (2001). Greedy function approximation: a gradient boosting machine. Annals of Statistics, 29, 1189–1232.
## -------------------------------------------------------------
## Continuous longitudinal partial dependence.
## -------------------------------------------------------------
set.seed(19)
sim.obj <- simLong(n = 40, n.time = 4, model = 2, family = "continuous")
dta <- sim.obj$data.list
fit <- boostmtree(
x = dta$features,
tm = dta$time,
id = dta$id,
y = dta$y,
family = "continuous",
M = 50,
verbose = FALSE
)
## Draw directly on the active device.
partial.plot(fit, x.var.names = c("x1", "x2"))
## Return the underlying curve data.
pp <- partial.plot(
fit,
x.var.names = "x2",
output = "data"
)
str(pp$curves)
## -------------------------------------------------------------
## Ordinal illustration using class probabilities.
## -------------------------------------------------------------
fit.ord <- boostmtree(
x = dta$features,
tm = dta$time,
id = dta$id,
y = cut(dta$y, breaks = 3, labels = c("low", "mid", "high")),
family = "ordinal",
M = 25,
verbose = FALSE
)
partial.plot(
fit.ord,
x.var.names = "x1",
prob.class = TRUE,
response.labels = c("low", "high")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.