View source: R/plot_quantile.R
| plot.bqr.svy | R Documentation |
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 class 'bqr.svy'
plot(
x,
y = NULL,
type = c("fit", "quantile", "trace", "density"),
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 = 2.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 class 'bwqr_fit'
plot(x, ...)
## S3 method for class 'bwqr_fit_multi'
plot(x, ...)
x |
Object of class |
y |
Ignored (S3 signature). |
type |
One of |
tau |
Quantile(s) to plot; must appear in |
which |
Variable name(s) or coefficient index(es) to display.
For |
add_points |
(fit) Logical; overlay observed data points. |
combine |
(fit) Logical; if multiple |
show_ci |
(fit) Logical; draw credible bands. |
ci_probs |
(fit) Length-2 numeric vector with lower/upper probabilities for credible bands. |
at |
(fit) Named list of fixed values for non-plotted covariates (see Details). |
grid_length |
(fit) Integer; number of points in the predictor grid. |
points_alpha |
(fit) Point transparency in |
point_size |
(fit) Point size. |
line_size |
(fit/quantile) Line width for fitted/summary lines. |
main |
Optional main title. |
use_ggplot |
Logical; if |
theme_style |
(ggplot) One of |
color_palette |
(ggplot) One of |
add_h0 |
(quantile) Logical; add a horizontal reference at |
add_ols |
(quantile) Logical; add the OLS estimate (dotted line) for the selected coefficient. |
ols_fit |
(quantile) Optional precomputed |
ols_weights |
(quantile) Optional numeric vector of weights when fitting
OLS internally (length must match |
... |
Accepted for compatibility; ignored by internal plotting code. |
Supported plot types:
type = "fit": Fitted quantile curves versus a single
numeric predictor (selected via which). 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", which must name 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 the selected 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).
invisible(NULL) for base R graphics, or a ggplot object if
use_ggplot = TRUE.
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", which = "wt", show_ci = TRUE)
plot(fit, type = "quantile", which = "wt", add_h0 = TRUE, add_ols = TRUE)
plot(fit, type = "quantile", which = c("(Intercept)", "wt", "hp", "cyl"),
add_h0 = TRUE, add_ols = TRUE)
plot(fit, type = "trace", which = "wt", tau = 0.5)
plot(fit, type = "density", which = "wt", tau = 0.5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.