plotQuantileRegion: Plot Bivariate Quantile Regions for Multiple-Output Models

View source: R/plot_quantile_region.R

plotQuantileRegionR Documentation

Plot Bivariate Quantile Regions for Multiple-Output Models

Description

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.

Usage

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
)

Arguments

model

An object of class "mo.bqr.svy" produced by mo.bqr.svy.

response

Character vector of length 2 giving the names of the response columns in datafile.

datafile

A data frame containing at least the two columns named in response.

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 xValue = 1.

paintedArea

Logical; if TRUE (default) the regions are drawn as filled ribbons (see Details).

range_y

An optional 2 \times 2 matrix whose rows give the [min, max] range for the first and second response, respectively. If NULL, the ranges are computed from the data with a 15 percent margin.

main

Optional character string for the plot title.

point_alpha

Numeric in [0, 1]; transparency for the observed-data point cloud (default = 0.3).

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 TRUE, print per-quantile progress messages (default = FALSE).

Details

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.

Value

Invisibly, a list with components:

plot

A ggplot object.

data

A data frame with columns y1, min, max and tau, one block per quantile level.

See Also

mo.bqr.svy, prior

Examples


# 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)



bayesQRsurvey documentation built on April 7, 2026, 1:06 a.m.