| Type: | Package |
| Title: | Bayesian Quantile Regression with Lasso and Adaptive Lasso |
| Version: | 0.1.0 |
| 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. |
| License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
| Copyright: | See inst/COPYRIGHTS for the attribution of third-party components inherited from the 'bayesQR' package. |
| Encoding: | UTF-8 |
| Depends: | R (≥ 4.2) |
| Imports: | graphics, stats, utils |
| Suggests: | testthat (≥ 3.0.0), coda, knitr, rmarkdown, quantreg |
| Config/testthat/edition: | 3 |
| VignetteBuilder: | knitr |
| NeedsCompilation: | yes |
| RoxygenNote: | 7.3.3 |
| URL: | https://github.com/fernandorubiogarcia/bbqr |
| BugReports: | https://github.com/fernandorubiogarcia/bbqr/issues |
| Packaged: | 2026-08-25 20:39:30 UTC; ferna |
| Author: | 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 <j332v755@wichita.edu> |
| Repository: | CRAN |
| Date/Publication: | 2026-09-08 13:00:13 UTC |
bbqr: 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.
Two response families
The package fits the same three penalty layers to two kinds of response, through two parallel entry points.
bbqr()A binary response, observed only as 0/1 through a threshold. The latent response is drawn each sweep. Because the threshold identifies the coefficient vector only up to a positive scale, these fits take an
anchorthat says how the scale is fixed.bbqr_alasso(),bbqr_lasso()andbbqr_none()are the direct forms.cbqr()An observed continuous response. There is no latent response draw and no
anchor: the data identify the scale, sosigmais sampled every sweep. The location-scale latentszandsare still drawn. These fits instead takeq, the exponent onsigmain the local-scale prior rate, which the binary model cannot see because itssigmais held fixed.cbqr_alasso(),cbqr_lasso()andcbqr_none()are the direct forms.
The two families do not share a prior constructor. prior() builds a
bbqr.prior object for the binary fitters; the continuous fitters take a
plain named list, because their hierarchy has different components (no
anchor, a live sigma, and the q exponent) and different reference
defaults. Passing a prior() object to cbqr() is an error, and says so.
Method sources
The binary samplers implement Rubio Garcia (2023) for the adaptive lasso,
and Benoit, Al-Hamzawi and Yu (2013) and Benoit and Van den Poel (2012) for
the lasso and unpenalised layers. On the continuous side the published
specification each layer reproduces is a different one: at its default
q = 1 the adaptive lasso is the penalty of Alhamzawi, Yu and Benoit
(2012), the lasso at q = 0 is Benoit, Al-Hamzawi and Yu (2013) carried
over to an observed response, and the unpenalised layer is the sampler of
Kozumi and Kobayashi (2011). See citation("bbqr").
In the binary family, each of the three penalties is shipped in two
forms, selected by prior(penalty, model = ): "v3", the hierarchy as
published, and "v5", the default, in which every improper prior component
has been replaced by a proper one so that the posterior exists
unconditionally. The published adaptive-lasso and lasso hierarchies have no
posterior, for the reason given in prior(); they are kept so that earlier
results can be reproduced, and the print method labels them. The continuous
family ships one hierarchy, the proper one: there is no model argument and
no published continuous specification being reproduced alongside it.
Getting started
bbqr() is the entry point for a 0/1 response; see its help page for the
three penalties, the identification anchors and the derivation versions.
cbqr() is the entry point for a continuous one. prior() sets
hyperparameters and selects the hierarchy for the binary fitters only; the
continuous fitters take a plain named list, documented at cbqr().
Relationship to bayesQR
The Fortran RNG wrapper (src/wrapper.c) and the general layout of the
package follow Benoit's bayesQR, which is GPL (>= 2) licensed and is
acknowledged in the Authors@R field of DESCRIPTION. The six MCMC
kernels shipped here – three binary, three continuous – were written for
this package.
Author(s)
Maintainer: Fernando Rubio Garcia j332v755@wichita.edu (Wichita State University)
Other contributors:
Dries F. Benoit (Author of 'bayesQR', from which the Fortran RNG wrapper and package layout are derived) [contributor, copyright holder]
Rahim Al-Hamzawi [contributor]
Keming Yu [contributor]
Dirk Van den Poel [contributor]
See Also
Useful links:
Report bugs at https://github.com/fernandorubiogarcia/bbqr/issues
The tau-calibrated reference intercept prior
Description
At the sigma = 1 anchor and with x'beta = 0, the model reduces to
Pr(y = 1) = G_tau(beta0) with G_tau the distribution function of -E
for E ~ ALD(0, 1, tau). By the probability integral transform,
G_tau(beta0) is exactly Uniform(0, 1) when beta0 ~ ALD(0, 1, 1 - tau),
so the reference normal prior is that law's moment match:
Usage
.bbqr_b0_reference(quantile)
Arguments
quantile |
The quantile level |
Details
mean = -theta = -(1 - 2 tau) / (tau (1 - tau))
var = (1 - 2 tau + 2 tau^2) / (tau^2 (1 - tau)^2)
The mean is not zero away from the median. Centring the intercept prior at
the origin puts the prior-predictive mean of Pr(y = 1) at 0.73 rather than
0.5 at tau = 0.1, so it is a specification error rather than a neutral
default. The variance is within 5% of the value that minimises the
Kolmogorov-Smirnov distance to Uniform(0, 1) over scalings of itself, so
no optimisation is performed: the closed form is used as it stands.
Value
A list with elements mean and var.
Bayesian binary quantile regression
Description
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.
Usage
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
)
Arguments
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. |
Value
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_fixedunderanchor = "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
NAwhen the sampler has no Metropolis step.penalty,anchor,quantileThe settings used.
priorThe prior actually applied.
modelWhich hierarchy was sampled:
"v3","v4"or"v5".derivedTRUEwhen the chain targets a posterior one of the derivations writes down;FALSEwhen a projection anchor was combined with"v4"or"v5".b0_priorThe intercept prior actually used, as
mean,varandprec. Recorded because the"v5"reference depends onquantile, 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.
Derivation version
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 (\omega or
\tau_h) is not integrable along the ray where the scale, the
\lambda_j^2 and the latent s_j vanish together while the
likelihood stays bounded below. "v5", the default, replaces every improper
component with a proper one – \mathrm{Gamma}(2, 2) on the global
scale, and a \tau-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.
Choosing a penalty
The three penalties share the same latent-variable augmentation and differ only in what sits on top of the slopes:
"none"A vague
N(0, \sigma^2_\beta)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).
Identification
A binary threshold model identifies the coefficient vector only up to a
positive scale: \mathrm{sign}(x'\beta + \varepsilon) is unchanged if
\beta 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\betaare on a stated scale, and it is the convention under which the\tau-calibrated intercept prior ofmodel = "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\sigmalets the unidentified scale inflate them."free"Impose nothing beyond the prior: sample
\sigmafrom its full conditional and let the prior alone settle the scale. This is the sampled-\sigmaconvention of the adaptive-lasso and lasso derivations, and it is a derived posterior under everymodel; it is simply not identified by the likelihood, so||beta||is a prior artefact. Not available forpenalty = "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
\|(\beta_0, \beta)\| = 1after every sweep."normslopes"Rescale so that
\|\beta\| = 1over 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 \beta_0 and the ALD
inverse-scale \sigma are rescaled alongside the slopes. At the
observed-data level the model is invariant under
(\beta_0, \beta, \sigma) \mapsto (c\beta_0, c\beta, \sigma/c).
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.
Scaling
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.
References
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
See Also
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.
Examples
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)
Adaptive-lasso binary quantile regression
Description
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 \tau-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.
Usage
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
)
Arguments
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. |
Value
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.
Derivation version
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.
References
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
See Also
bbqr(), and cbqr_alasso() for the same penalty layer
fitted to an observed continuous response
Examples
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)
Lasso binary quantile regression
Description
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.
Usage
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
)
Arguments
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. |
Details
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.
Value
An object of class "bbqr", as documented in bbqr().
References
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
See Also
bbqr(), and cbqr_lasso() for the same penalty layer
fitted to an observed continuous response
Examples
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)
Unpenalised binary quantile regression
Description
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.
Usage
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
)
Arguments
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. |
Details
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.
Value
An object of class "bbqr", as documented in bbqr().
References
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
See Also
bbqr(), and cbqr_none() for the same penalty layer
fitted to an observed continuous response
Examples
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)
Bayesian quantile regression for a continuous response
Description
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.
Usage
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
)
Arguments
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. |
Value
A cbqr object, or a cbqr.list when quantile has length > 1.
The components are:
family,penalty,q,quantilewhat was fitted.
beta,beta0,sigmathe kept draws: a matrix of slopes, and vectors for the intercept and the ALD inverse-scale. Unlike a binary fit,
sigmais always a live parameter here.lambdasq,omega,deltathe shrinkage layer,
"alasso"only: the per-coefficient scales, the global scale, and its shape.lambdasq,tau_hyper,deltathe shrinkage layer,
"lasso"only: one global scale, its hyperparameter, and the shape. Absent for"none", which has no shrinkage layer.accept,accMetropolis acceptance rate for
delta, and its running trace.NAwhen there is no Metropolis step.ndraw,burn,keep,ndraw_keptthe MCMC controls as used.
n,nvar,names,terms,callthe data and the model frame the fit came from.
priorthe resolved prior list, including any defaults filled in.
standardizedthe centring and scaling applied to
Xandy, orNULL. Draws are already mapped back, so this is a record rather than something to undo.b0_priorthe intercept prior actually used.
clip,clip_hits,samplerthe clamp configuration, how often each site fired, and the latent-draw routine.
"alasso"only.
References
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
See Also
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.
Examples
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)
Continuous quantile regression with the adaptive lasso
Description
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.
Usage
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
)
Arguments
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. |
Value
An object of class cbqr.
References
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
See Also
cbqr() for the common interface, bbqr_alasso() for the
binary counterpart. prior() configures that one, not this one.
Examples
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)
Continuous quantile regression with the lasso
Description
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.
Usage
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
)
Arguments
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. |
Details
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.
Value
An object of class cbqr.
References
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
See Also
cbqr() for the common interface, bbqr_lasso() for the
binary counterpart.
Examples
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)
Continuous quantile regression, unpenalised
Description
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.
Usage
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
)
Arguments
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. |
Value
An object of class cbqr.
References
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
See Also
cbqr() for the common interface, bbqr_none() for the
binary counterpart.
Examples
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
Description
Extract posterior mean coefficients
Usage
## S3 method for class 'bbqr'
coef(object, ...)
## S3 method for class 'bbqr.list'
coef(object, ...)
Arguments
object |
An object of class |
... |
Ignored. |
Value
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
Description
Trace and density plots for a fitted binary quantile regression
Usage
## S3 method for class 'bbqr'
plot(x, which = NULL, type = c("both", "trace", "density"), ...)
Arguments
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. |
Value
x, invisibly. Called for its side effect.
Examples
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)
Trace and density plots for a continuous quantile regression
Description
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.
Usage
## S3 method for class 'cbqr'
plot(x, which = NULL, type = c("both", "trace", "density"), ...)
Arguments
x |
An object of class |
which |
Coefficient names or indices; defaults to all, plus |
type |
|
... |
Passed to the underlying plot calls. |
Value
x, invisibly. Called for the side effect of drawing.
See Also
plot.bbqr() for the binary counterpart.
Predicted probabilities and indices from a binary quantile regression
Description
Predicted probabilities and indices from a binary quantile regression
Usage
## S3 method for class 'bbqr'
predict(object, newdata = NULL, type = c("response", "link", "class"), ...)
Arguments
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. |
Details
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.
Value
A numeric vector, one entry per row of newdata.
Examples
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)
Predictions from a continuous quantile regression
Description
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.
Usage
## S3 method for class 'cbqr'
predict(object, newdata = NULL, interval = FALSE, level = 0.95, ...)
Arguments
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. |
Value
A numeric vector, or a matrix with columns fit, lower, upper
when interval = TRUE.
Prior and hyperparameter settings for the binary fitters
Description
Builds the list of prior hyperparameters and Metropolis tuning constants for one of the three penalty layers.
Usage
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
)
Arguments
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 |
Details
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
\sigma, 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.
Value
A list of class "bbqr.prior".
References
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
See Also
bbqr() and the direct binary fitters, which
accept this object; cbqr(), which does not.
Examples
# 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)
Summarise a fitted binary quantile regression
Description
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.
Usage
## S3 method for class 'bbqr'
summary(object, level = 0.95, ...)
Arguments
object |
An object of class |
level |
Credible level for the intervals. |
... |
Ignored. |
Value
An object of class "bbqr.summary".
Examples
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)
Summarise a fitted continuous quantile regression
Description
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.
Usage
## S3 method for class 'cbqr'
summary(object, level = 0.95, ...)
Arguments
object |
An object of class |
level |
Credible level for the intervals. |
... |
Ignored. |
Details
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.
Value
An object of class "cbqr.summary".