Plot method for objects of class bqr.svy produced by bqr.svy().
It can display fitted quantile curves, coefficient–quantile profiles,
MCMC trace plots, and posterior densities.
# S3 method for bqr.svy
plot(
x,
y = NULL,
type = c("fit", "quantile", "trace", "density"),
predictor = NULL,
tau = NULL,
which = NULL,
add_points = TRUE,
combine = TRUE,
show_ci = FALSE,
ci_probs = c(0.1, 0.9),
at = NULL,
grid_length = 200,
points_alpha = 0.4,
point_size = 1.5,
line_size = 1.2,
main = NULL,
use_ggplot = TRUE,
theme_style = c("minimal", "classic", "bw", "light"),
color_palette = c("viridis", "plasma", "set2", "dark2"),
add_h0 = FALSE,
add_ols = FALSE,
ols_fit = NULL,
ols_weights = NULL,
...
)# S3 method for bwqr_fit
plot(x, ...)
# S3 method for bwqr_fit_multi
plot(x, ...)
invisible(NULL) for base R graphics, or a ggplot object if
use_ggplot = TRUE.
Object of class bqr.svy.
Ignored (S3 signature).
One of "fit", "quantile", "trace",
"density".
(fit) Name of a numeric predictor; if NULL, the first
numeric predictor (excluding the response) is used.
Quantile(s) to plot; must appear in x$quantile. If
NULL, all available are used.
(quantile/trace/density) Coefficient name or index to display. The default is the first coefficient associated with the first variable in the model.
(fit) Logical; overlay observed data points.
(fit) Logical; if multiple tau: TRUE overlays
curves in one panel; FALSE uses one panel per quantile.
(fit) Logical; draw credible bands.
(fit) Length-2 numeric vector with lower/upper probabilities for credible bands.
(fit) Named list of fixed values for non-predictor
covariates (see Details).
(fit) Integer; number of points in the predictor grid.
(fit) Point transparency in [0,1].
(fit) Point size.
(fit/quantile) Line width for fitted/summary lines.
Optional main title.
Logical; if TRUE, return a ggplot object.
(ggplot) One of "minimal", "classic",
"bw", "light".
(ggplot) One of "viridis", "plasma",
"set2", "dark2".
(quantile) Logical; add a horizontal reference at \(y = 0\).
(quantile) Logical; add the OLS estimate (dotted line) for the selected coefficient.
(quantile) Optional precomputed lm object; if
NULL, an lm() is fitted internally using x$model and
x$terms.
(quantile) Optional numeric vector of weights when fitting
OLS internally (length must match nrow(x$model)).
Accepted for compatibility; ignored by internal plotting code.
Supported plot types:
type = "fit": Fitted quantile curves versus a single
numeric predictor. Optionally overlay observed points and credible
bands. Other covariates can be held fixed via at.
type = "quantile": A single coefficient as a function
of the quantile \(\tau\). Optionally add a reference line at 0 and
the corresponding OLS estimate.
type = "trace": MCMC trace for one selected
coefficient at a chosen \(\tau\).
type = "density": Posterior density for one selected
coefficient at a chosen \(\tau\).
Notes:
tau must be included in x$quantile. If NULL, all
available quantiles in the object are used.
For type = "fit", predictor must be a numeric column in
the original model. If NULL, the first numeric predictor
(different from the response) is chosen automatically.
For type = "fit", at is a named list
(list(var = value, ...)) used to fix other covariates while
plotting versus predictor. Provide valid levels for factors.
When use_ggplot = TRUE, a ggplot object is returned and the
appearance is controlled by theme_style and
color_palette. Otherwise, base graphics are used and the
function returns invisible(NULL).
# \donttest{
data(mtcars)
fit <- bqr.svy(mpg ~ wt + hp + cyl, data = mtcars,
quantile = c(0.5, 0.75), method = "ald",
niter = 20000, burnin = 10000, thin = 5)
plot(fit, type = "fit", predictor = "wt", show_ci = TRUE)
plot(fit, type = "quantile", which = "wt", add_h0 = TRUE, add_ols = TRUE)
plot(fit, type = "trace", which = "wt", tau = 0.5)
plot(fit, type = "density", which = "wt", tau = 0.5)
# }
Run the code above in your browser using DataLab