bayesQR {bayesQR} | R Documentation |
Bayesian quantile regression
Description
bayesQR
implements a Bayesian method for estimating quantile regression models (see references).
To improve the speed of the routine, the Markov Chain Monte Carlo (MCMC) part of the algorithm is programmed in Fortran and is called from within the R function bayesQR
.
Usage
bayesQR(formula, data, quantile, alasso, normal.approx, ndraw, keep, prior)
Arguments
formula |
a symbolic description of the model to be fit. |
data |
an optional data frame containing the variables in the model. |
quantile |
numerical scalar or vector containing quantile(s) of interest (default=0.5). |
alasso |
logical flag for adaptive lasso variable selection (default=FALSE). |
normal.approx |
logical flag for normal approximation of posterior distribution (default=TRUE). |
ndraw |
number of MCMC draws. |
keep |
thinning parameter, i.e. keep every keepth draw (default=1). |
prior |
an S3 object of class |
Details
The function bayesQR
can estimate four types of models, depending on whether the dependent variable is continuous or binary and whether adaptive lasso variable selection is used.
Continuous dependent variable without adaptive lasso variable selection:
Model: y = Xbeta + e e ~ ALD(location=0, scale=sigma, quantile=p) Priors: beta ~ N(beta0, V0) sigma ~ invGamma(shape0,scale0) Continuous dependent variable with adaptive lasso variable selection:
Model: y = Xbeta + e e ~ ALD(location=0, scale=sigma, quantile=p) Priors: beta ~ ALD(location=0, scale=sigma/lambda, p=0.5) sigma ~ InvGamma(shape=sigma_shape, scale=sigma_scale) (lambda/sigma)^2 ~ Gamma(shape=etasq_shape, scale=etasq_scale) Binary dependent variable without adaptive lasso variable selection:
Model: y* = Xbeta + e e ~ ALD(location=0, scale=1, quantile=p) y = 1, if (y* > 0); y = 0, otherwise Priors: beta ~ N(beta0, V0) Binary dependent variable with adaptive lasso variable selection:
Model: y* = Xbeta + e e ~ ALD(location=0, scale=1, quantile=p) y = 1, if (y* > 0); y = 0, otherwise Priors: beta ~ ALD(location=0, scale=1/lambda, p=0.5) lambda^2 ~ Gamma(shape=lambdasq_shape, scale=lambdasq_scale)
Value
An object of class bayesQR
, basically a list of lists.
For every estimated quantile a list is created containing the following elements:
method |
a string containing the method that was used, i.e. indicating whether the dependent variable was continuous or binary and whether adaptive lasso variable selection was used. |
normal.approx |
logical flag for normal approximation of posterior distribution. |
quantile |
the quantile that was estimated. |
names |
character vector containing the names of the independent variables in the model. |
betadraw |
ndraw/keep x nvar(X) matrix of beta draws. |
sigmadraw |
ndraw/keep vector of sigma draws (only in case of continuous dependent variable). |
Author(s)
Dries F. Benoit, Rahim Al-Hamzawi, Keming Yu and Dirk Van den Poel
References
Paper about the bayesQR package:
Benoit, D.F and Van den Poel, D. (2017). bayesQR: A Bayesian Approach to Quantile Regression, Journal of Statistical Software, 76(7), 1-32. <doi:10.18637/jss.v076.i07>
Continuous dependent variable without adaptive lasso variable selection:
Yu, K. and Moyeed, R. (2001). Bayesian quantile regression, Statistics and Probability Letters, 54, 437-447. <doi:10.1016/S0167-7152(01)00124-9>
Also see:
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>
Continuous dependent variable with adaptive lasso variable selection:
Alhamzawi, R., Yu, K. and Benoit, D.F. (2012). Bayesian adaptive LASSO quantile regression, Statistical Modelling, 12(3), 279-297. <doi:10.1177/1471082X1101200304>
Also see:
Li, Q., Xi, R. and Lin, N. (2010). Bayesian Regularized Quantile Regression. Bayesian Analysis, 5, 1-24. <doi:10.1214/10-BA521>
Binary dependent variable without adaptive lasso variable selection:
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>
Binary dependent variable with adaptive lasso variable selection:
Al-Hamzawi, R., Benoit, D.F. and Yu, K. (2012). Bayesian lasso binary quantile regression. Computational Statistics, 28(6), 2861-2873. <doi:10.1007/s00180-013-0439-0>
Examples
# Simulate data from heteroskedastic regression
set.seed(66)
n <- 200
X <- runif(n=n,min=0,max=10)
X <- X
y <- 1 + 2*X + rnorm(n=n, mean=0, sd=.6*X)
# Estimate series of quantile regressions with adaptive lasso
# NOTE: to limit execution time of the example, ndraw is set
# to a very low value. Set value to 5000 for a better
# approximation of the posterior distirubtion.
out <- bayesQR(y~X, quantile=c(.05,.25,.5,.75,.95), alasso=TRUE, ndraw=500)
# Initiate plot
## Plot datapoints
plot(X, y, main="", cex=.6, xlab="X")
## Add quantile regression lines to the plot (exclude first 500 burn-in draws)
sum <- summary(out, burnin=50)
for (i in 1:length(sum)){
abline(a=sum[[i]]$betadraw[1,1],b=sum[[i]]$betadraw[2,1],lty=i,col=i)
}
# Estimate and plot OLS model
outOLS = lm(y~X)
abline(outOLS,lty=1,lwd=2,col=6)
# Add legend to plot
legend(x=0,y=max(y),legend=c(.05,.25,.50,.75,.95,"OLS"),lty=c(1,2,3,4,5,1),
lwd=c(1,1,1,1,1,2),col=c(1:6),title="Quantile")