View source: R/plot_quantile_region.R
| plotQuantileRegion | R Documentation |
Draws bivariate quantile regions from a fitted mo.bqr.svy object.
The function projects data onto a grid, determines which points lie inside
each quantile region, and visualises the result using ggplot2.
plotQuantileRegion(
model,
response,
datafile,
ngridpoints = 200,
xValue = 1,
paintedArea = TRUE,
range_y = NULL,
main = NULL,
point_alpha = 0.3,
point_size = 1.2,
line_size = 0.8,
verbose = FALSE
)
model |
An object of class |
response |
Character vector of length 2 giving the names of the
response columns in |
datafile |
A data frame containing at least the two columns named
in |
ngridpoints |
Integer; number of grid points per axis (default = 200). |
xValue |
Numeric vector of covariate values at which to evaluate
the regression. For an intercept-only model use |
paintedArea |
Logical; if |
range_y |
An optional |
main |
Optional character string for the plot title. |
point_alpha |
Numeric in |
point_size |
Numeric; size of the data points (default = 1.2). |
line_size |
Numeric; line width for contour outlines (default = 0.8). |
verbose |
Logical; if |
Two display modes are available:
paintedArea = TRUE (default): Filled ribbons with contour
outlines, using a sequential "Blues" palette. An in-plot
text legend shows the quantile level and approximate coverage.
paintedArea = FALSE: Contour-only lines coloured by
quantile, with a standard ggplot2 legend at the bottom.
The quantile regions are built from the directional approach described in
Nascimento & Gonçalves (2025). For each quantile
\tau, the function evaluates every grid point against the
half-space constraints defined by the fitted directions and orthogonal
bases.
Invisibly, a list with components:
plot |
A |
data |
A data frame with columns |
mo.bqr.svy, prior
# Load the Anthro dataset (children anthropometric data, already cleaned)
data(Anthro, package = "bayesQRsurvey")
# --- Directions ---
n_dir <- 12
angles <- (0:(n_dir - 1)) * 2 * pi / n_dir
U_mat <- rbind(cos(angles), sin(angles))
gamma_list <- lapply(seq_len(n_dir), function(k)
matrix(c(-sin(angles[k]), cos(angles[k])), ncol = 1))
# --- Fit ---
fit <- mo.bqr.svy(
cbind(wgt, hgt) ~ 1,
data = Anthro,
quantile = c(0.05, 0.10, 0.25),
U = U_mat,
gamma_U = gamma_list,
max_iter = 2000,
verbose = FALSE
)
# --- Plot quantile regions (filled ribbons) ---
plotQuantileRegion(fit, response = c("wgt", "hgt"), datafile = Anthro)
# Contour-only style
plotQuantileRegion(fit, response = c("wgt", "hgt"), datafile = Anthro,
paintedArea = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.