Plot Categorical Regression Spline Fits
plot.crs.RdPlot fitted conditional mean, conditional quantile, gradient, and
bivariate surface displays for crs objects using the
modern np-style plot interface. This page is the canonical
reference for CRS plot options and plot control helper objects.
Arguments
- x
an object of class
"crs"returned bycrs. Mean-regression objects plot fitted conditional means by default. Objects fit withtauplot fitted conditional quantiles.
Control Helper Constructors
These arguments configure optional S3 control objects consumed by CRS plot
methods. The crs_*_control() helpers use the same argument conventions
as the corresponding modern np plot controls where the CRS plot route
supports the same feature.
- wild
wild-bootstrap multiplier family.
- blocklen
optional positive block length for
bootstrap="fixed"andbootstrap="geom". If omitted for meancrsplots, CRS uses the same automatic block-length selector as np.- xtrim
optional scalar trimming/expansion control stored on a grid control object. This uses the same scalar CRS contract as the top-level
xtrimargument documented below.- xq
optional conditioning quantile or vector of conditioning quantiles.
- slices
reserved for future explicit slice selection.
Data and evaluation controls
grid_controloptional detailed grid controls created by
crs_grid_control.nevalthe number of evaluation points used for each plotted continuous margin. For bivariate surfaces, the plotted grid has
neval * nevalevaluation points.xqthe conditioning quantile used to hold non-plotted continuous variables fixed when drawing one-dimensional slices.
xtrimscalar trimming/expansion control for the evaluation support. Values in
[0,0.5)trim both tails by the requested quantile amount; negative values expand the support. The default evaluates over the observed support of the plotted continuous variable.
Plot content controls
common_scalelogical; whether multiple one-dimensional panels should share a common vertical scale when feasible.
gradient_order,gradientsderivative plotting controls.
gradients=TRUErequests gradients/effects rather than the fitted function, andgradient_orderselects the derivative order. Current CRS gradient plotting requires a scalargradient_order.layout"auto"orTRUErequests automaticpar(mfrow=...)management for multi-panel plots."current"orFALSEpreserves the user's current graphics layout.outputone of
"plot","data", or"both"."both"is the public spelling for the historical"plot-data"behavior."data"returns the plotting payload without drawing.
Interval and bootstrap controls
alphathe nominal significance level used for interval/band construction.
Bthe bootstrap replication count. The default is
1999.bandone of
"pmzsd","pointwise","bonferroni","simultaneous", or"all".band="all"draws pointwise, simultaneous, and Bonferroni bands with a package-drawn legend unless suppressed.boot_controloptional detailed bootstrap controls created by
crs_boot_control. This controls wild-bootstrap multipliers and dependent-bootstrap block length. CRS plot refit bootstraps currently keep fitted tuning parameters fixed.bootstrapthe bootstrap resampling scheme. Mean CRS plots support
"wild","inid","fixed", and"geom". Quantile CRS plots default to"inid"and support"inid","fixed", and"geom";"wild"is mean-only. Mean CRS gradient/effect plots also support"wild","inid","fixed", and"geom"; quantile CRS gradient plots support the refit schemes only.centerinterval centering control. CRS currently supports
center="estimate"only and fails fast for unsupported centering requests.errorsone of
"none","bootstrap", or"asymptotic".
Rendering and view controls
data_overlaylogical; when
TRUE, overlay observed response data on fitted mean/quantile displays where meaningful and expand plot limits to include the data. Overlay points default to small, transparent markers and can be customized with ordinarypoints()graphical arguments passed through....data_ruglogical; when
TRUE, draw rug-style support cues for the plotted coordinates. For ordinary one-dimensional base plots this behaves like a standard rug. For eligible bivariate surface plots, the base renderer draws floor-rug ticks andrenderer="rgl"draws analogous 3D floor-rug ticks.legendlegend control for legends drawn by the package, including
band="all"uncertainty legends.TRUEdraws the default legend,FALSE,NULL, orNAsuppresses it, a single character string supplies the legend position, and a list is merged into the defaultlegendcall for base plots or the defaultrgl::legend3d()call forrenderer="rgl". For routes with more than one package-drawn legend, named sublists such aslegend=list(bands=FALSE)may be used when a route distinguishes those legend roles.perspectivelogical; whether two-continuous-predictor CRS fits should be displayed as bivariate fitted-function surfaces.
phi,theta,viewview controls for bivariate continuous surface plots. As in np, the
rglbackend remaps the inherited base defaultstheta=0,phi=20to a more informative oblique view.rendererthe surface-rendering backend for eligible bivariate continuous plots.
"base"usespersp-style graphics."rgl"uses the suggested rgl package and displays through the active rgl backend. On supported surface routes,data_overlay=TRUEadds observed data as an interactive point cloud,data_rug=TRUEadds 3D floor-rug ticks, anderrors!="none"adds interval surfaces. Withband="all", CRS draws a matching interactive legend usingrgl::legend3d().
Graphical parameters
border,cex,cex.axis,cex.lab,cex.main,cex.sub,col,lty,lwd,main,pch,sub,type,xlab,xlim,ylab,ylim,zlab,zlimstandard graphical controls forwarded to the underlying plotting primitives when relevant.
rgl.persp3d.<arg>,rgl.view3d.<arg>,rgl.par3d.<arg>,rgl.grid3d.<arg>,rgl.widget.<arg>,rgl.surface3d.<arg>,rgl.legend3d.<arg>backend-specific rgl controls. For example,
rgl.legend3d.bty="o"restores a box around theband="all"rgl legend, andrgl.surface3d.alphacustomizes interval-surface transparency.
- ...
for
plot.crs, additional arguments supplied to control plotting behavior or passed through to underlying plotting helpers where supported. Supported named plotting controls are summarized above; standard graphical parameters are forwarded where relevant. Forcrs_boot_control(), unsupported helper options fail fast rather than being silently ignored.
Details
The default display is the fitted function, matching the modern
np regression plot convention. One-dimensional fits are shown as
partial fitted curves. For two continuous predictors,
perspective=TRUE requests a fitted surface.
Plot interval/error types are:
"pmzsd" : point estimate +/- z_(1-alpha/2) * standard error
"pointwise" : per-point two-sided interval
"bonferroni" : pointwise interval with alpha adjusted for m grid points
"simultaneous" : joint-band interval from the bootstrap route
where \(m\) is the number of evaluation points used in the plotted
curve or surface. band="all" overlays pointwise, simultaneous,
and Bonferroni bands.
For mean-regression plots, errors="bootstrap" defaults to the
fast fixed-design wild bootstrap used by np, with
bootstrap="wild" and B=1999. The refit bootstrap remains
available with bootstrap="inid". Mean plots also support the
np-style block refit bootstraps bootstrap="fixed" and
bootstrap="geom"; use crs_boot_control(blocklen=...) to
set the block length explicitly, otherwise the np automatic
block-length selector is used.
Quantile CRS plots, i.e. objects fit with tau, follow the
npqreg convention and default to the refit
bootstrap="inid" selector. bootstrap="fixed" and
bootstrap="geom" are also available for quantile fitted-curve
plots, while bootstrap="wild" remains mean-only.
For mean CRS gradient/effect plots requested with
gradients=TRUE, errors="bootstrap" also defaults to the
fixed-design wild bootstrap. Numeric continuous panels report derivative
intervals computed with the corresponding crshat() derivative
operator. Categorical panels report focal-minus-baseline effect intervals.
Refit gradient/effect bootstrap intervals remain available with
bootstrap="inid", bootstrap="fixed", and
bootstrap="geom". For quantile CRS gradient plots,
bootstrap="wild" is not available because quantile estimation is not
linear in the response.
Unsupported legacy CRS plot arguments such as ci,
deriv, and mean now fail fast. New public plot controls
use the np-style names documented here.
Value
Invisibly returns the plotted object for ordinary plotting calls.
When output="data" or output="both" is requested, returns
the plotting payload. The control helper constructors return small S3
lists consumed by plot.crs() and related CRS plot methods.
Author
Jeffrey S. Racine racinej@mcmaster.ca
See also
crs, crsiv, crsivderiv,
clsd
Examples
set.seed(42)
n <- 100
x <- runif(n)
y <- sin(2*pi*x) + rnorm(n, sd = 0.25)
model <- crs(y ~ x, cv = "none", degree = 3, segments = 1)
plot(model)
plot(model, data_rug = TRUE)
if (FALSE) { # \dontrun{
plot(model, errors = "bootstrap", band = "all")
plot(model, errors = "bootstrap", bootstrap = "inid", B = 99)
plot(model, errors = "bootstrap", bootstrap = "fixed", B = 99,
boot_control = crs_boot_control(blocklen = 5))
z <- runif(n)
y2 <- sin(2*pi*x) + z + rnorm(n, sd = 0.25)
smodel <- crs(y2 ~ x + z, cv = "none", degree = c(3, 1),
segments = c(1, 1))
plot(smodel, perspective = TRUE, data_rug = TRUE)
plot(smodel, perspective = TRUE, renderer = "rgl",
errors = "bootstrap", band = "all", B = 99)
qmodel <- crs(y ~ x, cv = "none", degree = 3, segments = 1, tau = 0.5)
plot(qmodel, errors = "bootstrap", B = 99)
} # }