Learn R Programming

randomForestSRC (version 3.9.0)

plot.quantreg.rfsrc: Plot Conditional Quantiles and CRPS Diagnostics

Description

Plots observed responses against their predicted conditional quantiles. An optional inset compares the forest's continuous ranked probability score (CRPS) with a reference that uses the training-response distribution without predictors. Numerical pinball losses can also be displayed for selected quantile levels.

Usage

# S3 method for rfsrc
plot.quantreg(x, prbL = .25, prbU = .75,
  m.target = NULL, crps = TRUE, subset = NULL,
  xlab = NULL, ylab = NULL, ...,
  inset.args = list(), crps.null = TRUE, quantreg.tau = NULL)

Value

Used for its graphical side effect. Invisibly returns NULL.

Arguments

x

A training or prediction object returned by quantreg, containing observed responses for the observations to be plotted. For new-data diagnostics, include response columns in the quantreg() prediction call.

prbL, prbU

Lower and upper quantile levels, each a single probability in \((0,1)\), with prbL < prbU. The middle level is 0.5 when it lies strictly between them; otherwise it is their midpoint. Each level is matched to the nearest stored probability by get.quantile(). Include the desired levels in prob when calling quantreg() for exact matching.

m.target

Name of one continuous response to display. The default is the first response with quantile results. For multivariate or mixed outcomes, this selects results from x without calculating new predictions.

crps

If TRUE, display the standardized, finite-grid CRPS curve from get.quantile.crps() in an inset.

subset

Observations to plot and score. Supply positive integer row indices or a logical vector with one nonmissing entry per row of the quantile output. NULL uses all rows. Indices refer to the returned results after training or prediction preprocessing; repeated indices include an observation more than once.

xlab, ylab

Main-panel axis labels. Defaults are the selected response name and "Target Quantiles".

...

Named graphical arguments for the main panel, passed to plot.default. Use xlim and ylim for axis limits, main for the title, and cex.axis, las, and related options for the axes. The arguments pch, col, and cex style the middle-quantile points. The function sets the plotted coordinates and initial panel type. These settings do not style the CRPS inset.

inset.args

Named list of graphical arguments for the CRPS inset, passed to plot.default. Use xlim and ylim for inset limits, and col, lty, and lwd for the forest curve. Axis options such as cex.axis, las, and tck also apply. axes = FALSE hides both inset axes; yaxt = "n" hides its right-hand axis. The default list() uses the inset's own settings. Ignored when crps = FALSE. Supply the full argument name.

quantreg.tau

Quantile levels for numerical pinball-loss labels, as a vector of finite probabilities strictly between zero and one. For each level, the plot displays the mean loss for the selected response and subset in the lower-right corner of the main panel. The default NULL omits these labels, even when the session option quantreg.tau is set. The plotted quantiles and CRPS inset are unchanged. Supply the full argument name.

crps.null

If TRUE, include the null reference in the CRPS inset as a dashed black curve, with a legend identifying Forest and Null. Set to FALSE for the forest curve alone. Ignored when crps = FALSE. Supply the full argument name.

Author

Hemant Ishwaran and Udaya B. Kogalur

Details

The plot compares observed responses with the predicted response distributions. The main panel shows selected quantiles for individual observations; the CRPS inset summarizes distributional prediction error across observations. Both displays use the response selected by m.target and the observations selected by subset.

Quantile panel

Each observation is placed at its observed response on the horizontal axis. A point marks its predicted middle quantile, and a vertical segment with endpoint marks spans its lower and upper quantiles. The dashed diagonal marks equality between observed and predicted values. The default levels request the median and an interval from the 25th to the 75th percentile.

Horizontal jitter separates overlapping observations. All scores use the original response values, not these display positions. Observations with an unavailable response or requested quantile are omitted from the main panel with a warning.

Pinball-loss labels

Supply quantreg.tau = c(.1, .5, .9) to display mean pinball losses for the 10th, 50th, and 90th percentile predictions as text in the lower-right corner of the main panel. Smaller losses indicate better quantile predictions. These levels can differ from the quantiles drawn in the panel.

The values are calculated by get.pinball.error(x, tau = quantreg.tau, subset = subset, m.target = m.target) for the selected response. Each loss averages over the selected observations with finite responses and quantile predictions at that level. Plotting omits these labels unless levels are supplied in the call; the session reporting option alone does not add them.

CRPS inset

The inset evaluates the predicted CDF across response thresholds. At each threshold, it averages the squared difference between the predicted CDF and the indicator that the observed response is at or below that threshold. It integrates these errors by the trapezoidal rule from the first reporting-grid value to each successive value, then divides by the integration width.

The horizontal axis is the response threshold; the right-hand vertical axis is standardized CRPS. Lower values indicate less error over the corresponding integration interval. This is the finite-grid curve returned by get.quantile.crps(), so the grid's range and resolution affect the scores. The first value is unavailable because its integration width is zero. An entirely unavailable curve is omitted with a warning.

Null reference

The null curve provides a comparison with predictions based on the training-response distribution alone. It uses the same empirical CDF for every evaluated observation: $$F_0(t)=\frac{1}{n_0}\sum_{j=1}^{n_0} I(Y_j^{\mathrm{train}}\leq t),$$ where \(n_0\) is the number of finite training responses for the selected outcome. Every training observation contributes, so repeated response values contribute according to their frequencies. Test responses are used only to evaluate the reference, not to construct it.

Forest and null curves use the same response grid, subset, integration rule, and standardization. At each threshold, both exclude observations with an unavailable response or forest CDF prediction. The null distribution itself always uses all finite training responses, regardless of subset. For training plots, it includes the evaluated responses and is an in-sample benchmark rather than an OOB or leave-one-out estimate.

Training responses come from x$forest$yvar, or x$yvar for a training object without responses saved in its forest. If they are unavailable, the null curve is omitted with a warning.

Customizing the display

Use ... for the main panel and inset.args for the inset. For example, inset.args = list(ylim = c(0, 0.3), lwd = 1.5) changes the inset's vertical limits and forest-curve line width. Default inset limits cover both curves.

Axis limits change only the displayed region; they do not change the observations scored or the CRPS integration limits. After the inset is drawn, graphics settings return to the main panel so that further drawing applies there. Successive calls can be used in a multi-panel layout.

See Also

quantreg, get.quantile, get.quantile.crps, get.pinball.error, plot.default

Examples

Run this code
# \donttest{
## Univariate quantiles, with forest and null CRPS curves.
library(randomForestSRC)
set.seed(19)
dta <- na.omit(airquality)
prob <- c(.25, .50, .75)
q <- quantreg(Temp ~ ., data = dta, prob = prob, ntree = 100)
plot.quantreg(q)

## Add pinball losses for this plot only; the interval and inset are unchanged.
plot.quantreg(q, quantreg.tau = c(.2, .5, .8))
print(get.pinball.error(q, tau = c(.2, .5, .8)))

## Customize the main panel directly, and the inset separately.
plot.quantreg(q, main = "Temperature",
              xlim = c(50, 100), ylim = c(45, 110), pch = 19,
              inset.args = list(xlim = c(60, 95), ylim = c(0, .35),
                                lwd = 1.5))

## Keep the inset, but suppress its null reference.
plot.quantreg(q, crps.null = FALSE)

## Multivariate forest: select each response for plotting only.
mv <- quantreg(cbind(Ozone, Temp) ~ ., data = dta,
               splitrule = "mahalanobis", prob = prob, ntree = 100)
print(names(get.quantile(mv, pretty = FALSE)))
op <- par(mfrow = c(1, 2))
plot.quantreg(mv, m.target = "Ozone")
plot.quantreg(mv, m.target = "Temp", main = "Temperature",
              xlim = c(50, 100), ylim = c(45, 110),
              inset.args = list(ylim = c(0, .35)))
par(op)
# }

Run the code above in your browser using DataLab