| Title: | Bayesian Quantile Regression with Lasso and Adaptive Lasso |
|---|---|
| Description: | Markov chain Monte Carlo samplers for Bayesian quantile regression, based on the asymmetric Laplace distribution and the location-scale mixture representation of Kozumi and Kobayashi (2011) <doi:10.1080/00949655.2010.496117>. A binary response and an observed continuous response are both supported, each with three penalty layers behind one interface: no penalty, following Benoit and Van den Poel (2012) <doi:10.1002/jae.1216>; the Bayesian lasso, following Benoit, Al-Hamzawi and Yu (2013) <doi:10.1007/s00180-013-0439-0>; and the Bayesian adaptive lasso of Rubio Garcia (2023) <https://soar.wichita.edu/entities/publication/a2f86232-4704-4ec2-b685-751e7b04ec42>. In the binary family each is available as published and in a corrected form, the default, in which every improper prior component is replaced by a proper one so that the posterior exists unconditionally; the continuous family ships the corrected form only. The continuous adaptive-lasso layer at its default reproduces the penalty of Alhamzawi, Yu and Benoit (2012) <doi:10.1177/1471082X1101200304>. A binary threshold model identifies the coefficient vector only up to a positive scale, so the binary samplers expose the identification anchor as an explicit argument, allowing fixing the scale of the error distribution, fixing a single coefficient, and constraining the norm of the coefficient vector to be compared directly; an observed response identifies the scale, so the continuous samplers have no anchor and draw it every sweep. The MCMC cores are written in Fortran and called from R. |
| Authors: | Fernando Rubio Garcia [aut, cre] (Wichita State University), Dries F. Benoit [ctb, cph] (Author of 'bayesQR', from which the Fortran RNG wrapper and package layout are derived), Rahim Al-Hamzawi [ctb], Keming Yu [ctb], Dirk Van den Poel [ctb] |
| Maintainer: | Fernando Rubio Garcia <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.1.0.9000 |
| Built: | 2026-10-15 11:18:50 UTC |
| Source: | https://github.com/fernandorubiogarcia/bbqr |
Fits a quantile regression model to a binary response by Markov chain Monte
Carlo, using the asymmetric Laplace distribution (ALD) and the location-scale
mixture representation of Kozumi and Kobayashi (2011). Three penalty layers
are available through the penalty argument, the identification anchor is
exposed through anchor, and the prior hierarchy is chosen by model on
the prior() object. The defaults – model = "v5" at anchor = "sigma1"
– sample a posterior that is proper unconditionally and identified by
construction.
bbqr( formula, data = NULL, quantile = 0.5, penalty = c("alasso", "lasso", "none"), ndraw = 10000, burn = NULL, keep = 1, prior = NULL, anchor = NULL, sigma_fixed = 1, standardize = FALSE, use_boundaries = FALSE, clip = NULL, sampler = NULL, beta_init = NULL, beta0_init = 0 )bbqr( formula, data = NULL, quantile = 0.5, penalty = c("alasso", "lasso", "none"), ndraw = 10000, burn = NULL, keep = 1, prior = NULL, anchor = NULL, sigma_fixed = 1, standardize = FALSE, use_boundaries = FALSE, clip = NULL, sampler = NULL, beta_init = NULL, beta0_init = 0 )
formula |
A model formula. The response must be binary: 0/1, logical, or a two-level factor (the second level is treated as the success). |
data |
A data frame in which to interpret |
quantile |
The quantile level(s) to fit, each strictly between 0 and 1.
If more than one is given, the samplers are run once per level and an
object of class |
penalty |
The shrinkage layer: |
ndraw |
Total number of MCMC iterations. |
burn |
Number of initial iterations to discard. Also the window over
which the Metropolis proposal for the penalty hyperparameter adapts.
Defaults to |
keep |
Thinning interval; every |
prior |
A prior specification from |
anchor |
The identification anchor; see the Identification section
of |
sigma_fixed |
The value the ALD inverse-scale is held at when
|
standardize |
If |
use_boundaries |
If |
clip |
Which numerical clamps to apply, available for
|
sampler |
Which routine draws the latents |
beta_init, beta0_init
|
Starting values for the slopes and the
intercept. |
For a single quantile, an object of class "bbqr": a list with
components
betaMatrix of retained slope draws, one column per covariate.
beta0Vector of retained intercept draws.
sigmaVector of retained ALD inverse-scale draws. Constant at
sigma_fixed under anchor = "sigma1"; under the norm anchors it
varies, because the rescaling step absorbs the scale into it.
acceptFinal Metropolis acceptance rate for the penalty
hyperparameter, or NA when the sampler has no Metropolis step.
penalty, anchor, quantile
The settings used.
priorThe prior actually applied.
modelWhich hierarchy was sampled: "v3", "v4" or "v5".
derivedTRUE when the chain targets a posterior one of the
derivations writes down; FALSE when a projection anchor was combined
with "v4" or "v5".
b0_priorThe intercept prior actually used, as mean, var and
prec. Recorded because the "v5" reference depends on quantile,
so it cannot be reconstructed from the prior object alone.
Penalty-specific draws are also returned: lambdasq, omega and delta
for the adaptive lasso; lambdasq, tauhyper and delta for the lasso.
For several quantiles, an object of class "bbqr.list" holding one such
object per level.
Each penalty has a published specification and a corrected one, selected by
prior(penalty, model = ). "v3" is the published hierarchy: for the
adaptive lasso and the lasso its joint posterior does not exist, because the
log-uniform hyperprior on the global shrinkage scale ( or
) is not integrable along the ray where the scale, the
and the latent vanish together while the
likelihood stays bounded below. "v5", the default, replaces every improper
component with a proper one – on the global
scale, and a -calibrated normal prior on the intercept – so that
the posterior is proper with no condition on the design, on the number of
covariates, or on the anchor. "v4" is the intermediate step for the
adaptive lasso. The fitted object records which hierarchy was sampled in
model, and whether the chain targets a derived posterior in derived.
Under "v4" and "v5" the numerical clamps, argument floors and the
historical sampler routine are refused, because the derivations say none of
them is part of the target; "v3" keeps them reachable so that earlier
results can be reproduced. See prior() for the hierarchies in full.
The three penalties share the same latent-variable augmentation and differ only in what sits on top of the slopes:
"none"A vague prior on each slope and
no shrinkage, following Benoit and Van den Poel (2012).
"lasso"One shrinkage parameter shared by all slopes, following Benoit, Al-Hamzawi and Yu (2013).
"alasso"A separate shrinkage parameter per slope, so that coefficients are penalised individually rather than uniformly, following Rubio Garcia (2023).
A binary threshold model identifies the coefficient vector only up to a
positive scale: is unchanged if
and the error scale are multiplied by the same positive constant.
Some anchor must therefore be imposed, and the choice is not innocuous. The
available anchors are:
"sigma1"Fix the ALD inverse-scale at sigma_fixed (default 1)
and never sample it. The default for every penalty. It closes the scale
ray outright, so the posterior summaries of are on a stated
scale, and it is the convention under which the -calibrated
intercept prior of model = "v5" is exact. In the simulation study
behind this package its point estimates matched "free" while its
credible intervals were markedly narrower, because a sampled
lets the unidentified scale inflate them.
"free"Impose nothing beyond the prior: sample from
its full conditional and let the prior alone settle the scale. This is
the sampled- convention of the adaptive-lasso and lasso
derivations, and it is a derived posterior under every model; it is
simply not identified by the likelihood, so ||beta|| is a prior
artefact. Not available for penalty = "none": with neither a penalty
nor an anchor the likelihood is flat along the scale ray, so nothing
identifies the model and only the vague prior stops the chain
drifting.
"beta1"Hold the first slope at 1 and never sample it. The first column of the design matrix must be a covariate with a genuinely non-zero coefficient for this to be sensible.
"norm1"Rescale so that after every
sweep.
"normslopes"Rescale so that over the slopes
alone, the convention used in the maximum-score literature.
The two norm anchors share one projection step and differ only in how the
scaling constant is chosen. In both cases and the ALD
inverse-scale are rescaled alongside the slopes. At the
observed-data level the model is invariant under
.
These projections are identification experiments and are not steps in any
of the derivations.
Note, however, that this invariance does not extend to the penalised
posterior: the shrinkage layer is stated on a fixed scale, so repeatedly
renormalising the coefficients moves them relative to the penalty. Anchors
that constrain the norm of the coefficient vector should therefore be
expected to behave differently from "sigma1", which leaves the
coefficients where the sampler put them. Under model = "v4" or "v5"
the three projection anchors ("beta1", "norm1", "normslopes") warn
and set derived = FALSE on the fit: the projection is an exact
reparameterisation of the likelihood but not of the prior, so the chain
targets no written-down posterior. They remain available because the
comparison is the point of exposing the anchor at all.
The prior variances and the penalty are stated on the scale of the design
matrix as supplied. If one covariate is measured in units a hundred times
larger than another, a shared penalty shrinks them by very different
relative amounts, and the recovered direction can be badly wrong. Setting
standardize = TRUE centres and scales the covariates before sampling and
maps the draws back afterwards; the back-transform preserves the linear
predictor exactly, but the posterior itself differs because the penalty now
acts on comparable coefficients. Unless the covariates are already on a
common scale, prefer standardize = TRUE.
Benoit, D. F. and Van den Poel, D. (2012). Binary quantile regression: a Bayesian approach based on the asymmetric Laplace distribution. Journal of Applied Econometrics, 27(7), 1174–1188. doi:10.1002/jae.1216
Benoit, D. F., Al-Hamzawi, R. and Yu, K. (2013). Bayesian lasso binary quantile regression. Computational Statistics, 28(6), 2861–2873. doi:10.1007/s00180-013-0439-0
Kozumi, H. and Kobayashi, G. (2011). Gibbs sampling methods for Bayesian quantile regression. Journal of Statistical Computation and Simulation, 81(11), 1565–1578. doi:10.1080/00949655.2010.496117
Rubio Garcia, F. (2023). Bayesian adaptive lasso binary quantile regression with hybrid resampling for classification of imbalanced data. M.S. thesis, Wichita State University, Dept. of Mathematics, Statistics, and Physics. https://soar.wichita.edu/entities/publication/a2f86232-4704-4ec2-b685-751e7b04ec42
prior() for hyperparameters, summary.bbqr() for posterior
summaries, plot.bbqr() for trace and density plots, and
predict.bbqr() for fitted probabilities. cbqr() fits the same three
penalties when the response is observed rather than thresholded.
set.seed(42) n <- 200 X <- matrix(rnorm(n * 4), n, 4, dimnames = list(NULL, paste0("x", 1:4))) y <- as.numeric(X %*% c(1.5, -1, 0, 0) + rnorm(n) > 0) dat <- data.frame(y = y, X) fit <- bbqr(y ~ x1 + x2 + x3 + x4, data = dat, quantile = 0.5, ndraw = 1000, burn = 200) fit summary(fit) # Compare the three penalties at the same quantile fits <- lapply(c("none", "lasso", "alasso"), function(p) bbqr(y ~ x1 + x2 + x3 + x4, data = dat, penalty = p, ndraw = 1000, burn = 200)) sapply(fits, coef) # The published adaptive-lasso hierarchy, whose posterior does not exist, # is still available for reproducing earlier results old <- bbqr(y ~ x1 + x2 + x3 + x4, data = dat, ndraw = 1000, burn = 200, prior = prior("alasso", model = "v3")) c(fit$model, old$model)set.seed(42) n <- 200 X <- matrix(rnorm(n * 4), n, 4, dimnames = list(NULL, paste0("x", 1:4))) y <- as.numeric(X %*% c(1.5, -1, 0, 0) + rnorm(n) > 0) dat <- data.frame(y = y, X) fit <- bbqr(y ~ x1 + x2 + x3 + x4, data = dat, quantile = 0.5, ndraw = 1000, burn = 200) fit summary(fit) # Compare the three penalties at the same quantile fits <- lapply(c("none", "lasso", "alasso"), function(p) bbqr(y ~ x1 + x2 + x3 + x4, data = dat, penalty = p, ndraw = 1000, burn = 200)) sapply(fits, coef) # The published adaptive-lasso hierarchy, whose posterior does not exist, # is still available for reproducing earlier results old <- bbqr(y ~ x1 + x2 + x3 + x4, data = dat, ndraw = 1000, burn = 200, prior = prior("alasso", model = "v3")) c(fit$model, old$model)
Low-level sampler for binary quantile regression with an adaptive-lasso
penalty, in which each slope receives its own shrinkage parameter. Most
users should call bbqr() with penalty = "alasso" instead; this function
is exported for direct access to the sampler.
With the defaults – model = "v5" on the prior, anchor = "sigma1", no
clamps – every transition implements the corresponding full conditional
in the V5 appendix: the ALD inverse-scale is held at sigma_fixed, the
omega draw is Gamma(alpha_omega + k delta, beta_omega + sum(1 / lambdasq)), the intercept carries its -calibrated normal prior,
and delta is updated by a random-walk Metropolis step on the log scale
under a proper Gamma(alpha_delta, beta_delta) prior. That last prior is
required rather than optional: see prior(). anchor = "free" samples
the inverse-scale from its full conditional instead, which the appendix
also covers.
bbqr_alasso( formula, data = NULL, quantile = 0.5, ndraw = 10000, burn = NULL, keep = 1, prior = NULL, anchor = c("sigma1", "free", "beta1", "norm1", "normslopes"), sigma_fixed = 1, standardize = FALSE, use_boundaries = FALSE, clip = NULL, sampler = c("gig_half", "v4_invgaus"), kappa_lam = 0, beta_init = NULL, beta0_init = 0 )bbqr_alasso( formula, data = NULL, quantile = 0.5, ndraw = 10000, burn = NULL, keep = 1, prior = NULL, anchor = c("sigma1", "free", "beta1", "norm1", "normslopes"), sigma_fixed = 1, standardize = FALSE, use_boundaries = FALSE, clip = NULL, sampler = c("gig_half", "v4_invgaus"), kappa_lam = 0, beta_init = NULL, beta0_init = 0 )
formula |
A model formula. The response must be binary: 0/1, logical, or a two-level factor (the second level is treated as the success). |
data |
A data frame in which to interpret |
quantile |
The quantile level(s) to fit, each strictly between 0 and 1.
If more than one is given, the samplers are run once per level and an
object of class |
ndraw |
Total number of MCMC iterations. |
burn |
Number of initial iterations to discard. Also the window over
which the Metropolis proposal for the penalty hyperparameter adapts.
Defaults to |
keep |
Thinning interval; every |
prior |
A prior specification from |
anchor |
The identification anchor; see the Identification section
of |
sigma_fixed |
The value the ALD inverse-scale is held at when
|
standardize |
If |
use_boundaries |
If |
clip |
Which numerical clamps to apply, for isolating which individual
clamp a result depends on. There are eighteen sites: the eight the single
Accepts three forms. A named logical vector overrides individual sites
on top of
|
sampler |
Which routine draws the latents
The switch exists so that the v4-to-v6 difference can be attributed. |
kappa_lam |
Coefficient of an |
beta_init, beta0_init
|
Starting values for the slopes and the
intercept. |
An object of class "bbqr", as documented in bbqr(), with two
extra components: clip, the resolved logical(18) of switches, and
clip_hits, the number of times each site's clamp actually bound.
clip_hits is counted whether or not the switch was on, so a fit with
every clamp off still reports how often each clamp would have fired.
Denominators differ by site. ystar, z, v4_zarg and v4_zbound are
out of ndraw * n; s, lambdasq, v4_sarg and v4_sbound out of
ndraw * p; mh_sd out of burn; delta out of the accepted Metropolis
proposals; omega and v4_rate_om out of ndraw. Multiply by the number
of guards in a group where it holds more than one: v4_zarg has two,
v4_sarg three, each rate group two. v4_sd is out of n alone, since
v4 floored that standard deviation in the initialisation sweep only and
left the main-loop assignment bare. sigma and v4_rate_sig stay at zero
under anchor = "sigma1", where nothing ever reaches them.
Which of the three adaptive-lasso hierarchies is sampled is set by
model on the prior() object, not by an argument here. "v4" and "v5"
are derivation-faithful: their appendices state that no clamp, no
sampler-argument floor, and no exp(-kappa_lam / lambda_j^2) tilt is part
of the target, so a fit that names them while enabling one of those devices
is refused rather than recorded. Concretely, under model = "v4" or
"v5" this function requires clip = "none" (the default), kappa_lam = 0
and sampler = "gig_half". model = "v3" leaves all three switches
reachable, because reproducing what the earlier builds actually ran needs
them.
One further check is a warning rather than an error. Under model = "v4"
with a free sigma, a flat intercept is admissible only if a > 1, and the
historical default a = 1 sits exactly on the divergent boundary. That
configuration is what Experiments v4 and v6 ran, so it stays available and
warns instead of failing.
Rubio Garcia, F. (2023). Bayesian adaptive lasso binary quantile regression with hybrid resampling for classification of imbalanced data. M.S. thesis, Wichita State University, Dept. of Mathematics, Statistics, and Physics. https://soar.wichita.edu/entities/publication/a2f86232-4704-4ec2-b685-751e7b04ec42
bbqr(), and cbqr_alasso() for the same penalty layer
fitted to an observed continuous response
set.seed(1) n <- 150 X <- matrix(rnorm(n * 3), n, 3, dimnames = list(NULL, c("x1", "x2", "x3"))) y <- as.numeric(X %*% c(1, -1, 0) + rnorm(n) > 0) d <- data.frame(y = y, X) fit <- bbqr_alasso(y ~ x1 + x2 + x3, data = d, ndraw = 400, burn = 100) coef(fit)set.seed(1) n <- 150 X <- matrix(rnorm(n * 3), n, 3, dimnames = list(NULL, c("x1", "x2", "x3"))) y <- as.numeric(X %*% c(1, -1, 0) + rnorm(n) > 0) d <- data.frame(y = y, X) fit <- bbqr_alasso(y ~ x1 + x2 + x3, data = d, ndraw = 400, burn = 100) coef(fit)
Low-level sampler for binary quantile regression with a standard lasso
penalty: one shrinkage parameter shared by all slopes. This implements the
hierarchical sampler of Benoit, Al-Hamzawi and Yu (2013). Most users should
call bbqr() with penalty = "lasso" instead; this function is exported
for direct access to the sampler.
bbqr_lasso( formula, data = NULL, quantile = 0.5, ndraw = 10000, burn = NULL, keep = 1, prior = NULL, anchor = c("sigma1", "free", "beta1", "norm1", "normslopes"), sigma_fixed = 1, standardize = FALSE, use_boundaries = FALSE, beta_init = NULL, beta0_init = 0 )bbqr_lasso( formula, data = NULL, quantile = 0.5, ndraw = 10000, burn = NULL, keep = 1, prior = NULL, anchor = c("sigma1", "free", "beta1", "norm1", "normslopes"), sigma_fixed = 1, standardize = FALSE, use_boundaries = FALSE, beta_init = NULL, beta0_init = 0 )
formula |
A model formula. The response must be binary: 0/1, logical, or a two-level factor (the second level is treated as the success). |
data |
A data frame in which to interpret |
quantile |
The quantile level(s) to fit, each strictly between 0 and 1.
If more than one is given, the samplers are run once per level and an
object of class |
ndraw |
Total number of MCMC iterations. |
burn |
Number of initial iterations to discard. Also the window over
which the Metropolis proposal for the penalty hyperparameter adapts.
Defaults to |
keep |
Thinning interval; every |
prior |
A prior specification from |
anchor |
The identification anchor; see the Identification section
of |
sigma_fixed |
The value the ALD inverse-scale is held at when
|
standardize |
If |
use_boundaries |
If |
beta_init, beta0_init
|
Starting values for the slopes and the
intercept. |
The default anchor = "sigma1" holds the ALD inverse-scale at
sigma_fixed; anchor = "free" samples it from its full conditional,
which is what the published algorithm does. Which hierarchy is sampled –
the published one, whose posterior does not exist, or the corrected
"v5" default – is set by model on the prior() object.
An object of class "bbqr", as documented in bbqr().
Benoit, D. F., Al-Hamzawi, R. and Yu, K. (2013). Bayesian lasso binary quantile regression. Computational Statistics, 28(6), 2861–2873. doi:10.1007/s00180-013-0439-0
bbqr(), and cbqr_lasso() for the same penalty layer
fitted to an observed continuous response
set.seed(1) n <- 150 X <- matrix(rnorm(n * 3), n, 3, dimnames = list(NULL, c("x1", "x2", "x3"))) y <- as.numeric(X %*% c(1, -1, 0) + rnorm(n) > 0) d <- data.frame(y = y, X) fit <- bbqr_lasso(y ~ x1 + x2 + x3, data = d, ndraw = 400, burn = 100) coef(fit)set.seed(1) n <- 150 X <- matrix(rnorm(n * 3), n, 3, dimnames = list(NULL, c("x1", "x2", "x3"))) y <- as.numeric(X %*% c(1, -1, 0) + rnorm(n) > 0) d <- data.frame(y = y, X) fit <- bbqr_lasso(y ~ x1 + x2 + x3, data = d, ndraw = 400, burn = 100) coef(fit)
Low-level sampler for binary quantile regression with a vague normal prior
on the slopes and no shrinkage layer, implementing Benoit and Van den Poel
(2012). Most users should call bbqr() with penalty = "none" instead.
bbqr_none( formula, data = NULL, quantile = 0.5, ndraw = 10000, burn = NULL, keep = 1, prior = NULL, anchor = c("sigma1", "beta1", "norm1", "normslopes"), standardize = FALSE, use_boundaries = FALSE, beta_init = NULL, beta0_init = 0 )bbqr_none( formula, data = NULL, quantile = 0.5, ndraw = 10000, burn = NULL, keep = 1, prior = NULL, anchor = c("sigma1", "beta1", "norm1", "normslopes"), standardize = FALSE, use_boundaries = FALSE, beta_init = NULL, beta0_init = 0 )
formula |
A model formula. The response must be binary: 0/1, logical, or a two-level factor (the second level is treated as the success). |
data |
A data frame in which to interpret |
quantile |
The quantile level(s) to fit, each strictly between 0 and 1.
If more than one is given, the samplers are run once per level and an
object of class |
ndraw |
Total number of MCMC iterations. |
burn |
Number of initial iterations to discard. Defaults to
|
keep |
Thinning interval; every |
prior |
A prior specification from |
anchor |
The identification anchor; see the Identification section
of |
standardize |
If |
use_boundaries |
If |
beta_init, beta0_init
|
Starting values for the slopes and the
intercept. |
The default anchor = "sigma1" reproduces the published algorithm, which
holds the ALD scale at 1. "free" is deliberately absent from the choices
here, unlike the penalised fitters: with neither a penalty nor an anchor the
likelihood is flat along the scale ray, so the model is not identified and
only the vague prior stops the chain drifting.
An object of class "bbqr", as documented in bbqr().
Benoit, D. F. and Van den Poel, D. (2012). Binary quantile regression: a Bayesian approach based on the asymmetric Laplace distribution. Journal of Applied Econometrics, 27(7), 1174–1188. doi:10.1002/jae.1216
bbqr(), and cbqr_none() for the same penalty layer
fitted to an observed continuous response
set.seed(1) n <- 150 X <- matrix(rnorm(n * 3), n, 3, dimnames = list(NULL, c("x1", "x2", "x3"))) y <- as.numeric(X %*% c(1, -1, 0) + rnorm(n) > 0) d <- data.frame(y = y, X) fit <- bbqr_none(y ~ x1 + x2 + x3, data = d, ndraw = 400, burn = 100) coef(fit)set.seed(1) n <- 150 X <- matrix(rnorm(n * 3), n, 3, dimnames = list(NULL, c("x1", "x2", "x3"))) y <- as.numeric(X %*% c(1, -1, 0) + rnorm(n) > 0) d <- data.frame(y = y, X) fit <- bbqr_none(y ~ x1 + x2 + x3, data = d, ndraw = 400, burn = 100) coef(fit)
User-facing entry point for the three continuous penalty layers. The binary
threshold model is fitted by bbqr() instead; the two share no arguments
that refer to identification, because a continuous response identifies the
scale and a binary one does not.
cbqr( formula, data = NULL, quantile = 0.5, penalty = c("alasso", "lasso", "none"), ndraw = 10000, burn = NULL, keep = 1, prior = NULL, q = NULL, standardize = TRUE, use_boundaries = FALSE, clip = NULL, sampler = NULL, beta_init = NULL, beta0_init = 0 )cbqr( formula, data = NULL, quantile = 0.5, penalty = c("alasso", "lasso", "none"), ndraw = 10000, burn = NULL, keep = 1, prior = NULL, q = NULL, standardize = TRUE, use_boundaries = FALSE, clip = NULL, sampler = NULL, beta_init = NULL, beta0_init = 0 )
formula |
A two-sided formula. The intercept is split off and never penalised, so it must not appear among the penalised columns. |
data |
Optional data frame. |
quantile |
Quantile level(s) in (0, 1). |
penalty |
One of |
ndraw, burn, keep
|
MCMC controls. |
prior |
Optional named list overriding the continuous prior
defaults. Accepted names are |
q |
Exponent on sigma in the local-scale prior. Layer-specific default:
1 for |
standardize |
Centre and scale both |
use_boundaries |
Apply the kernel's numerical clamps. |
clip |
Per-site clamp configuration; |
sampler |
Latent-draw routine; |
beta_init, beta0_init
|
Starting values. |
A cbqr object, or a cbqr.list when quantile has length > 1.
The components are:
family, penalty, q, quantile
what was fitted.
beta, beta0, sigma
the kept draws: a matrix of slopes, and
vectors for the intercept and the ALD inverse-scale. Unlike a binary
fit, sigma is always a live parameter here.
lambdasq, omega, delta
the shrinkage layer, "alasso"
only: the per-coefficient scales, the global scale, and its shape.
lambdasq, tau_hyper, delta
the shrinkage layer, "lasso"
only: one global scale, its hyperparameter, and the shape. Absent for
"none", which has no shrinkage layer.
accept, acc
Metropolis acceptance rate for delta, and its
running trace. NA when there is no Metropolis step.
ndraw, burn, keep, ndraw_kept
the MCMC controls as used.
n, nvar, names, terms, call
the data and the model frame the fit came from.
priorthe resolved prior list, including any defaults filled in.
standardizedthe centring and scaling applied to X and y,
or NULL. Draws are already mapped back, so this is a record rather
than something to undo.
b0_priorthe intercept prior actually used.
clip, clip_hits, sampler
the clamp configuration, how often
each site fired, and the latent-draw routine. "alasso" only.
Alhamzawi, R., Yu, K. and Benoit, D. F. (2012). Bayesian adaptive lasso quantile regression. Statistical Modelling, 12(3), 279–297. doi:10.1177/1471082X1101200304
Benoit, D. F., Al-Hamzawi, R. and Yu, K. (2013). Bayesian lasso binary quantile regression. Computational Statistics, 28(6), 2861–2873. doi:10.1007/s00180-013-0439-0
Kozumi, H. and Kobayashi, G. (2011). Gibbs sampling methods for Bayesian quantile regression. Journal of Statistical Computation and Simulation, 81(11), 1565–1578. doi:10.1080/00949655.2010.496117
bbqr() for the binary threshold model; cbqr_alasso(),
cbqr_lasso() and cbqr_none() for the direct forms; predict.cbqr(),
summary.cbqr() and plot.cbqr() for the fitted object. prior() does
not configure these fitters.
set.seed(1) d <- data.frame(x1 = rnorm(120), x2 = rnorm(120)) d$y <- 1 + 2 * d$x1 - d$x2 + rnorm(120) fit <- cbqr(y ~ x1 + x2, d, ndraw = 400, burn = 100) round(coef(fit), 2)set.seed(1) d <- data.frame(x1 = rnorm(120), x2 = rnorm(120)) d$y <- 1 + 2 * d$x1 - d$x2 + rnorm(120) fit <- cbqr(y ~ x1 + x2, d, ndraw = 400, burn = 100) round(coef(fit), 2)
Fits the continuous-response adaptive-lasso hierarchy for an observed response. The response is observed, so there is no latent response draw and no identification anchor: sigma is identified by the data and is sampled every sweep.
cbqr_alasso( formula, data = NULL, quantile = 0.5, ndraw = 10000, burn = NULL, keep = 1, prior = NULL, q = NULL, standardize = TRUE, clip = NULL, sampler = NULL, beta_init = NULL, beta0_init = 0 )cbqr_alasso( formula, data = NULL, quantile = 0.5, ndraw = 10000, burn = NULL, keep = 1, prior = NULL, q = NULL, standardize = TRUE, clip = NULL, sampler = NULL, beta_init = NULL, beta0_init = 0 )
formula |
A two-sided formula. The intercept is split off and never penalised, so it must not appear among the penalised columns. |
data |
Optional data frame. |
quantile |
Quantile level(s) in (0, 1). |
ndraw, burn, keep
|
MCMC controls. |
prior |
Optional named list overriding the continuous prior
defaults. Accepted names are |
q |
Exponent on sigma in the local-scale prior rate
|
standardize |
Centre and scale both |
clip |
Optional clamp configuration: a single logical, a named logical vector over the sixteen continuous clamp sites, or a character vector of site names. Not the binary eighteen-site contract. |
sampler |
|
beta_init, beta0_init
|
Starting values. |
An object of class cbqr.
Alhamzawi, R., Yu, K. and Benoit, D. F. (2012). Bayesian adaptive lasso quantile regression. Statistical Modelling, 12(3), 279–297. doi:10.1177/1471082X1101200304
Benoit, D. F., Al-Hamzawi, R. and Yu, K. (2013). Bayesian lasso binary quantile regression. Computational Statistics, 28(6), 2861–2873. doi:10.1007/s00180-013-0439-0
Kozumi, H. and Kobayashi, G. (2011). Gibbs sampling methods for Bayesian quantile regression. Journal of Statistical Computation and Simulation, 81(11), 1565–1578. doi:10.1080/00949655.2010.496117
cbqr() for the common interface, bbqr_alasso() for the
binary counterpart. prior() configures that one, not this one.
set.seed(1) d <- data.frame(x1 = rnorm(120), x2 = rnorm(120)) d$y <- 1 + 2 * d$x1 - d$x2 + rnorm(120) fit <- cbqr_alasso(y ~ x1 + x2, d, ndraw = 400, burn = 100) round(coef(fit), 2)set.seed(1) d <- data.frame(x1 = rnorm(120), x2 = rnorm(120)) d$y <- 1 + 2 * d$x1 - d$x2 + rnorm(120) fit <- cbqr_alasso(y ~ x1 + x2, d, ndraw = 400, burn = 100) round(coef(fit), 2)
Fits the continuous-response lasso hierarchy for an observed response: a single shared
lambda^2 carried as a rate with a Gamma prior and a tau_h hyperlayer.
The prior rate here is sigma^q * lambda^2 / 2, with lambda^2 a single
global scale multiplying; the adaptive-lasso rate is
sigma^q / (2 * lambda_j^2), one scale per coefficient and dividing. The
two forms are different by construction, not a typo.
cbqr_lasso( formula, data = NULL, quantile = 0.5, ndraw = 10000, burn = NULL, keep = 1, prior = NULL, q = NULL, standardize = TRUE, use_boundaries = FALSE, beta_init = NULL, beta0_init = 0 )cbqr_lasso( formula, data = NULL, quantile = 0.5, ndraw = 10000, burn = NULL, keep = 1, prior = NULL, q = NULL, standardize = TRUE, use_boundaries = FALSE, beta_init = NULL, beta0_init = 0 )
formula |
A two-sided formula. The intercept is split off and never penalised, so it must not appear among the penalised columns. |
data |
Optional data frame. |
quantile |
Quantile level(s) in (0, 1). |
ndraw, burn, keep
|
MCMC controls. |
prior |
Optional named list overriding the continuous prior
defaults. Accepted names are |
q |
Exponent on sigma in the local-scale prior rate
|
standardize |
Centre and scale both |
use_boundaries |
Apply the kernel's numerical clamps. |
beta_init, beta0_init
|
Starting values. |
This is Benoit, Al-Hamzawi & Yu (2013)'s hierarchy, not the adaptive one
with k = 1, and the two are not reachable from one another.
An object of class cbqr.
Alhamzawi, R., Yu, K. and Benoit, D. F. (2012). Bayesian adaptive lasso quantile regression. Statistical Modelling, 12(3), 279–297. doi:10.1177/1471082X1101200304
Benoit, D. F., Al-Hamzawi, R. and Yu, K. (2013). Bayesian lasso binary quantile regression. Computational Statistics, 28(6), 2861–2873. doi:10.1007/s00180-013-0439-0
Kozumi, H. and Kobayashi, G. (2011). Gibbs sampling methods for Bayesian quantile regression. Journal of Statistical Computation and Simulation, 81(11), 1565–1578. doi:10.1080/00949655.2010.496117
cbqr() for the common interface, bbqr_lasso() for the
binary counterpart.
set.seed(1) d <- data.frame(x1 = rnorm(120), x2 = rnorm(120)) d$y <- 1 + 2 * d$x1 - d$x2 + rnorm(120) fit <- cbqr_lasso(y ~ x1 + x2, d, ndraw = 400, burn = 100) round(coef(fit), 2)set.seed(1) d <- data.frame(x1 = rnorm(120), x2 = rnorm(120)) d$y <- 1 + 2 * d$x1 - d$x2 + rnorm(120) fit <- cbqr_lasso(y ~ x1 + x2, d, ndraw = 400, burn = 100) round(coef(fit), 2)
Fits the unpenalised hierarchy for an observed response. Unlike its binary
counterpart, which holds sigma at the identification anchor and never samples
it, this kernel draws sigma every sweep from
its Gamma full conditional given the latents, with shape a + 3n/2.
cbqr_none( formula, data = NULL, quantile = 0.5, ndraw = 10000, burn = NULL, keep = 1, prior = NULL, standardize = TRUE, use_boundaries = FALSE, beta_init = NULL, beta0_init = 0 )cbqr_none( formula, data = NULL, quantile = 0.5, ndraw = 10000, burn = NULL, keep = 1, prior = NULL, standardize = TRUE, use_boundaries = FALSE, beta_init = NULL, beta0_init = 0 )
formula |
A two-sided formula. The intercept is split off and never penalised, so it must not appear among the penalised columns. |
data |
Optional data frame. |
quantile |
Quantile level(s) in (0, 1). |
ndraw, burn, keep
|
MCMC controls. |
prior |
Optional named list overriding the continuous prior
defaults. Accepted names are |
standardize |
Centre and scale both |
use_boundaries |
Apply the kernel's numerical clamps. |
beta_init, beta0_init
|
Starting values. |
An object of class cbqr.
Alhamzawi, R., Yu, K. and Benoit, D. F. (2012). Bayesian adaptive lasso quantile regression. Statistical Modelling, 12(3), 279–297. doi:10.1177/1471082X1101200304
Benoit, D. F., Al-Hamzawi, R. and Yu, K. (2013). Bayesian lasso binary quantile regression. Computational Statistics, 28(6), 2861–2873. doi:10.1007/s00180-013-0439-0
Kozumi, H. and Kobayashi, G. (2011). Gibbs sampling methods for Bayesian quantile regression. Journal of Statistical Computation and Simulation, 81(11), 1565–1578. doi:10.1080/00949655.2010.496117
cbqr() for the common interface, bbqr_none() for the
binary counterpart.
set.seed(1) d <- data.frame(x1 = rnorm(120), x2 = rnorm(120)) d$y <- 1 + 2 * d$x1 - d$x2 + rnorm(120) fit <- cbqr_none(y ~ x1 + x2, d, ndraw = 400, burn = 100) round(coef(fit), 2)set.seed(1) d <- data.frame(x1 = rnorm(120), x2 = rnorm(120)) d$y <- 1 + 2 * d$x1 - d$x2 + rnorm(120) fit <- cbqr_none(y ~ x1 + x2, d, ndraw = 400, burn = 100) round(coef(fit), 2)
Extract posterior mean coefficients
## S3 method for class 'bbqr' coef(object, ...) ## S3 method for class 'bbqr.list' coef(object, ...)## S3 method for class 'bbqr' coef(object, ...) ## S3 method for class 'bbqr.list' coef(object, ...)
object |
An object of class |
... |
Ignored. |
A named numeric vector of posterior means, intercept first. For a
"bbqr.list", a matrix with one column per quantile.
Trace and density plots for a fitted binary quantile regression
## S3 method for class 'bbqr' plot(x, which = NULL, type = c("both", "trace", "density"), ...)## S3 method for class 'bbqr' plot(x, which = NULL, type = c("both", "trace", "density"), ...)
x |
An object of class |
which |
Which coefficients to plot, by name or index. Index 1 is the intercept. Defaults to all. |
type |
|
... |
Passed to the underlying plotting calls. |
x, invisibly. Called for its side effect.
set.seed(1) n <- 150 X <- matrix(rnorm(n * 3), n, 3, dimnames = list(NULL, c("x1", "x2", "x3"))) y <- as.numeric(X %*% c(1, -1, 0) + rnorm(n) > 0) fit <- bbqr(y ~ x1 + x2 + x3, data = data.frame(y = y, X), ndraw = 500, burn = 100) op <- graphics::par(no.readonly = TRUE) plot(fit, which = "x1") graphics::par(op)set.seed(1) n <- 150 X <- matrix(rnorm(n * 3), n, 3, dimnames = list(NULL, c("x1", "x2", "x3"))) y <- as.numeric(X %*% c(1, -1, 0) + rnorm(n) > 0) fit <- bbqr(y ~ x1 + x2 + x3, data = data.frame(y = y, X), ndraw = 500, burn = 100) op <- graphics::par(no.readonly = TRUE) plot(fit, which = "x1") graphics::par(op)
Same interface as plot.bbqr(), with one addition: sigma is a plottable
parameter here. In the binary model it is constant under the default
anchor = "sigma1", so there is usually nothing to look at; here it is
always a live parameter.
## S3 method for class 'cbqr' plot(x, which = NULL, type = c("both", "trace", "density"), ...)## S3 method for class 'cbqr' plot(x, which = NULL, type = c("both", "trace", "density"), ...)
x |
An object of class |
which |
Coefficient names or indices; defaults to all, plus |
type |
|
... |
Passed to the underlying plot calls. |
x, invisibly. Called for the side effect of drawing.
plot.bbqr() for the binary counterpart.
Predicted probabilities and indices from a binary quantile regression
## S3 method for class 'bbqr' predict(object, newdata = NULL, type = c("response", "link", "class"), ...)## S3 method for class 'bbqr' predict(object, newdata = NULL, type = c("response", "link", "class"), ...)
object |
An object of class |
newdata |
A data frame of covariates. Required: fitted objects do not retain the design matrix, so that they stay small enough to hold thousands of fits in memory during a simulation study. |
type |
|
... |
Ignored. |
Predictions use the posterior mean coefficients. Because the coefficient
vector is identified only up to a positive scale, type = "response"
depends on the identification anchor, whereas type = "class" does not.
A numeric vector, one entry per row of newdata.
set.seed(1) n <- 150 X <- matrix(rnorm(n * 3), n, 3, dimnames = list(NULL, c("x1", "x2", "x3"))) y <- as.numeric(X %*% c(1, -1, 0) + rnorm(n) > 0) d <- data.frame(y = y, X) fit <- bbqr(y ~ x1 + x2 + x3, data = d, ndraw = 500, burn = 100) head(predict(fit, newdata = d, type = "response")) mean(predict(fit, newdata = d, type = "class") == y)set.seed(1) n <- 150 X <- matrix(rnorm(n * 3), n, 3, dimnames = list(NULL, c("x1", "x2", "x3"))) y <- as.numeric(X %*% c(1, -1, 0) + rnorm(n) > 0) d <- data.frame(y = y, X) fit <- bbqr(y ~ x1 + x2 + x3, data = d, ndraw = 500, burn = 100) head(predict(fit, newdata = d, type = "response")) mean(predict(fit, newdata = d, type = "class") == y)
Returns the fitted conditional quantile of the response, which is the
linear predictor. That is a different quantity from what predict.bbqr()
returns – P(y = 1 | x) from the ALD distribution function – which on a
continuous fit saturates at 1 and is silently meaningless.
## S3 method for class 'cbqr' predict(object, newdata = NULL, interval = FALSE, level = 0.95, ...)## S3 method for class 'cbqr' predict(object, newdata = NULL, interval = FALSE, level = 0.95, ...)
object |
An object of class |
newdata |
A data frame of predictors. Required: the fitted object does not store the design matrix. |
interval |
Return posterior credible intervals for the fitted quantile
as well as the point estimate. Uses the full retained draws, so the cost is
|
level |
Credible level when |
... |
Ignored. |
A numeric vector, or a matrix with columns fit, lower, upper
when interval = TRUE.
Builds the list of prior hyperparameters and Metropolis tuning constants for one of the three penalty layers.
prior( penalty = c("alasso", "lasso", "none"), model = c("v5", "v4", "v3"), a = NULL, b = NULL, alpha_delta = NULL, beta_delta = NULL, alpha_omega = NULL, beta_omega = NULL, alpha_tau = NULL, beta_tau = NULL, b0_mean = NULL, b0_var = NULL, delta_init = 1, omega_init = 1, tau_init = 1, mh_sd0 = 0.05, target_acc = 0.3, beta_var = 100 )prior( penalty = c("alasso", "lasso", "none"), model = c("v5", "v4", "v3"), a = NULL, b = NULL, alpha_delta = NULL, beta_delta = NULL, alpha_omega = NULL, beta_omega = NULL, alpha_tau = NULL, beta_tau = NULL, b0_mean = NULL, b0_var = NULL, delta_init = 1, omega_init = 1, tau_init = 1, mh_sd0 = 0.05, target_acc = 0.3, beta_var = 100 )
penalty |
Which sampler the prior is for: |
model |
Which prior hierarchy to sample. The three are nested
corrections, each removing one failure of propriety. For the adaptive
lasso they differ only in the prior on
|
a, b
|
Shape and rate of the |
alpha_delta, beta_delta
|
Shape and rate of the
For For |
alpha_omega, beta_omega
|
Shape and rate of the |
alpha_tau, beta_tau
|
Shape and rate of the |
b0_mean, b0_var
|
Mean and variance of the That reference is the moment match to the exactly calibrated prior. At the
Note that |
delta_init, omega_init, tau_init
|
Starting values for the penalty
hyperparameters. |
mh_sd0 |
Initial standard deviation of the random-walk Metropolis
proposal for |
target_acc |
Target acceptance rate for that Metropolis step. The proposal standard deviation is adapted towards this value during burn-in and then held fixed. |
beta_var |
Prior variance of each slope under |
This object is accepted by bbqr() and the three direct
binary fitters, and by those only. The continuous fitters
(cbqr() and friends) take a plain named list,
not a bbqr.prior: their hierarchy has no anchor, a live
, and the q exponent, and its reference defaults differ.
Passing the result of this function to cbqr() fails with
“Unknown prior component(s)”; cbqr() documents
the components they do accept. The defaults are the "v5"
hierarchy, in which every prior component is a probability distribution and
the posterior is proper unconditionally; model = "v3" reproduces the
specification of the source paper for each penalty instead. In most cases
this function only needs to be called to change one or two values.
A list of class "bbqr.prior".
Benoit, D. F. and Van den Poel, D. (2012). Binary quantile regression: a Bayesian approach based on the asymmetric Laplace distribution. Journal of Applied Econometrics, 27(7), 1174–1188. doi:10.1002/jae.1216
Benoit, D. F., Al-Hamzawi, R. and Yu, K. (2013). Bayesian lasso binary quantile regression. Computational Statistics, 28(6), 2861–2873. doi:10.1007/s00180-013-0439-0
bbqr() and the direct binary fitters, which
accept this object; cbqr(), which does not.
# Default adaptive-lasso prior: the fully proper "v5" hierarchy prior("alasso") # The published specification, for reproducing earlier results. Its # posterior does not exist, and the print method says so. prior("alasso", model = "v3") # A vaguer prior on the slopes for the unpenalised sampler prior("none", beta_var = 1000)# Default adaptive-lasso prior: the fully proper "v5" hierarchy prior("alasso") # The published specification, for reproducing earlier results. Its # posterior does not exist, and the print method says so. prior("alasso", model = "v3") # A vaguer prior on the slopes for the unpenalised sampler prior("none", beta_var = 1000)
Posterior means, standard deviations and equal-tailed credible intervals for every coefficient. A coefficient whose interval excludes zero is flagged as selected, which is the variable-selection rule used with these samplers.
## S3 method for class 'bbqr' summary(object, level = 0.95, ...)## S3 method for class 'bbqr' summary(object, level = 0.95, ...)
object |
An object of class |
level |
Credible level for the intervals. |
... |
Ignored. |
An object of class "bbqr.summary".
set.seed(1) n <- 150 X <- matrix(rnorm(n * 3), n, 3, dimnames = list(NULL, c("x1", "x2", "x3"))) y <- as.numeric(X %*% c(1, -1, 0) + rnorm(n) > 0) fit <- bbqr(y ~ x1 + x2 + x3, data = data.frame(y = y, X), ndraw = 500, burn = 100) summary(fit)set.seed(1) n <- 150 X <- matrix(rnorm(n * 3), n, 3, dimnames = list(NULL, c("x1", "x2", "x3"))) y <- as.numeric(X %*% c(1, -1, 0) + rnorm(n) > 0) fit <- bbqr(y ~ x1 + x2 + x3, data = data.frame(y = y, X), ndraw = 500, burn = 100) summary(fit)
Posterior means, standard deviations and equal-tailed credible intervals for every coefficient, plus the ALD inverse-scale. A coefficient whose interval excludes zero is flagged.
## S3 method for class 'cbqr' summary(object, level = 0.95, ...)## S3 method for class 'cbqr' summary(object, level = 0.95, ...)
object |
An object of class |
level |
Credible level for the intervals. |
... |
Ignored. |
Unlike the binary summary, there is no identification caveat: a continuous
response identifies the scale, so the coefficients are on the scale of y
and are directly interpretable.
An object of class "cbqr.summary".