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 "prior". If omitted, a diffuse prior will be assumed (see prior).

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.

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

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

[Package bayesQR version 2.4 Index]