Package 'Brq'

Title: Bayesian Analysis of Quantile Regression Models
Description: Bayesian estimation and variable selection for quantile regression models.
Authors: Rahim Alhamzawi
Maintainer: Rahim Alhamzawi (University of Al-Qadisiyah) <[email protected]>
License: GPL (>= 3)
Version: 3.0
Built: 2025-02-12 04:10:00 UTC
Source: https://github.com/cran/Brq

Help Index


Bayesian adaptive Lasso quantile regression

Description

This function implements the idea of Bayesian adaptive Lasso quantile regression employing a likelihood function that is based on the asymmetric Laplace distribution. The asymmetric Laplace error distribution is written as a scale mixture of normals as in Reed and Yu (2009). The proposed method (BALqr) extends the Bayesian Lasso quantile regression by allowing different penalization parameters for different regression coeffficients (Alhamzawi et al., 2012).

Usage

BALqr(x,y, tau = 0.5, runs = 11000, burn = 1000, thin=1)

Arguments

x

Matrix of predictors.

y

Vector of dependent variable.

tau

The quantile of interest. Must be between 0 and 1.

runs

Length of desired Gibbs sampler output.

burn

Number of Gibbs sampler iterations before output is saved.

thin

thinning parameter of MCMC draws.

Author(s)

Rahim Alhamzawi

References

[1] Alhamzawi, Rahim, Keming Yu, and Dries F. Benoit. (2012). Bayesian adaptive Lasso quantile regression. Statistical Modelling 12.3: 279-297.

[2] Reed, C. and Yu, K. (2009). A partially collapsed Gibbs sampler for Bayesian quantile regression. Technical Report. Department of Mathematical Sciences, Brunel University. URL: http://bura.brunel.ac.uk/bitstream/2438/3593/1/fulltext.pdf.

Examples

# Example 
n <- 150
p=8
Beta=c(5, 0, 0, 0, 0, 0, 0, 0)
x <- matrix(rnorm(n=p*n),n)
x=scale(x)
y <-x%*%Beta+rnorm(n)
y=y-mean(y)
fit = Brq(y~0+x,tau=0.5, method="BALqr",runs=5000, burn=1000)
summary(fit)

Bayesian adaptive Lasso tobit quantile regression

Description

This function implements the idea of Bayesian adaptive Lasso tobit quantile regression employing a likelihood function that is based on the asymmetric Laplace distribution. The asymmetric Laplace error distribution is written as a scale mixture of normal distributions as in Reed and Yu (2009). The proposed method (BALtqr) extends the Bayesian Lasso tobit quantile regression by allowing different penalization parameters for different regression coeffficients (Alhamzawi et al., 2013).

Usage

BALtqr(x,y, tau = 0.5, left = 0,  runs = 11000, burn = 1000, thin=1)

Arguments

x

Matrix of predictors.

y

Vector of dependent variable.

tau

The quantile of interest. Must be between 0 and 1.

left

Left censored point.

runs

Length of desired Gibbs sampler output.

burn

Number of Gibbs sampler iterations before output is saved.

thin

thinning parameter of MCMC draws.

Author(s)

Rahim Alhamzawi

References

[1] Alhamzawi, Rahim. (2013). Tobit Quantile Regression with the adaptive Lasso penalty. The Fourth International Arab Conference of Statistics, 450 ISSN (1681 6870).

[2] Reed, C. and Yu, K. (2009). A partially collapsed Gibbs sampler for Bayesian quantile regression. Technical Report. Department of Mathematical Sciences, Brunel University. URL: http://bura.brunel.ac.uk/bitstream/2438/3593/1/fulltext.pdf.

Examples

# Example 
n <- 150
p=8
Beta=c(5, 0, 0, 0, 0, 0, 0, 0)
x <- matrix(rnorm(n=p*n),n)
x=scale(x)
y <-x%*%Beta+rnorm(n)
y=y-mean(y)
y=pmax(0, y)

fit = Brq(y~0+x,tau=0.5, method="BALtqr",runs=5000, burn=1000)
summary(fit)
model(fit)

Bayesian Binary Quantile Regression

Description

This function implements the idea of Bayesian Binary quantile regression employing a likelihood function that is based on the asymmetric Laplace distribution.

Usage

BBqr(x,y, tau =0.5, runs =11000, burn =1000, thin=1)

Arguments

x

Matrix of predictors.

y

Vector of dependent variable.

tau

The quantile of interest. Must be between 0 and 1.

runs

Length of desired Gibbs sampler output.

burn

Number of Gibbs sampler iterations before output is saved.

thin

thinning parameter of MCMC draws.

Author(s)

Rahim Alhamzawi


Bayesian Lasso Binary quantile regression

Description

This function implements the idea of Bayesian Lasso Binary quantile regression using a likelihood function that is based on the asymmetric Laplace distribution (Rahim, 2016). The asymmetric Laplace error distribution is written as a scale mixture of normal distributions.

Usage

BLBqr(x,y, tau = 0.5, runs = 11000, burn = 1000, thin=1)

Arguments

x

Matrix of predictors.

y

Vector of dependent variable.

tau

The quantile of interest. Must be between 0 and 1.

runs

Length of desired Gibbs sampler output.

burn

Number of Gibbs sampler iterations before output is saved.

thin

thinning parameter of MCMC draws.

Author(s)

Rahim Alhamzawi


Bayesian Lasso quantile regression

Description

This function implements the idea of Bayesian Lasso quantile regression using a likelihood function that is based on the asymmetric Laplace distribution (Rahim, 2016). The asymmetric Laplace error distribution is written as a scale mixture of normal distributions as in Reed and Yu (2009). This function implements the Bayesian lasso for linear quantile regression models by assigning scale mixture of normal (SMN) priors on the parameters and independent exponential priors on their variances. We propose an alternative Bayesian analysis of the Bayesian lasso problem reported in Li, et al. (2010). A Gibbs sampling algorithm for the Bayesian Lasso quantile regression is constructed by sampling the parameters from their full conditional distributions.

Usage

BLqr(x,y, tau = 0.5, runs = 11000, burn = 1000, thin=1)

Arguments

x

Matrix of predictors.

y

Vector of dependent variable.

tau

The quantile of interest. Must be between 0 and 1.

runs

Length of desired Gibbs sampler output.

burn

Number of Gibbs sampler iterations before output is saved.

thin

thinning parameter of MCMC draws.

Author(s)

Rahim Alhamzawi

References

[1] Alhamzawi, R. (2016). Bayesian variable selection in quantile regression using asymmetric Laplace distribution. Working paper.

[2] Reed, C. and Yu, K. (2009). A partially collapsed Gibbs sampler for Bayesian quantile regression. Technical Report. Department of Mathematical Sciences, Brunel University. URL: http://bura.brunel.ac.uk/bitstream/2438/3593/1/fulltext.pdf.

[3] Li, Q., Xi, R. and Lin, N. (2010). Bayesian regularized quantile regression. Bayesian Analysis, 5(3): 533-56.

Examples

# Example 
n <- 150
p=8
Beta=c(5, 0, 0, 0, 0, 0, 0, 0)
x <- matrix(rnorm(n=p*n),n)
x=scale(x)
y <-x%*%Beta+rnorm(n)
y=y-mean(y)

fit = Brq(y~0+x,tau=0.5, method="BLqr",runs=5000, burn=1000)
summary(fit)
model(fit)

Bayesian tobit quantile regression

Description

This function implements the idea of Bayesian Lasso tobit quantile regression using a likelihood function that is based on the asymmetric Laplace distribution (Rahim, 2016). The asymmetric Laplace error distribution is written as a scale mixture of normal distributions as in Reed and Yu (2009). This function implements the Bayesian lasso for linear tobit quantile regression models by assigning scale mixture of normal (SMN) priors on the parameters and independent exponential priors on their variances. A Gibbs sampling algorithm for the Bayesian Lasso tobit quantile regression is constructed by sampling the parameters from their full conditional distributions.

Usage

BLtqr(x,y, tau = 0.5, left = 0,  runs = 11000, burn = 1000, thin=1)

Arguments

x

Matrix of predictors.

y

Vector of dependent variable.

tau

The quantile of interest. Must be between 0 and 1.

left

Left censored point.

runs

Length of desired Gibbs sampler output.

burn

Number of Gibbs sampler iterations before output is saved.

thin

thinning parameter of MCMC draws.

Author(s)

Rahim Alhamzawi

Examples

# Example 
n <- 150
p=8
Beta=c(5, 0, 0, 0, 0, 0, 0, 0)
x <- matrix(rnorm(n=p*n),n)
x=scale(x)
y <-x%*%Beta+rnorm(n)
y=y-mean(y)
y=pmax(0, y)

fit = Brq(y~0+x,tau=0.5, method="BLtqr",runs=5000, burn=1000)
summary(fit)
model(fit)

Exploring Relationships in Body Dimensions

Description

This dataset contains 21 body dimension measurements as well as age, weight, height, and gender on 507 individuals. The 247 men and 260 women were primarily individuals in their twenties and thirties, with a scattering of older men and women, all exercising several hours a week.

Source:

Measurements were initially taken by Grete Heinz and Louis J. Peterson - at San Jose State University and at the U.S. Naval Postgraduate School in Monterey, California. Later, measurements were taken at dozens of California health and fitness clubs by technicians under the supervision of one of these authors.

Usage

data(Body)

Format

The data frame has the following components:

  • BiacSk: Biacromial diameter (cm)

  • BiilSk: Biiliac diameter, or "pelvic breadth" (cm)

  • BitrSk: Bitrochanteric diameter (cm)

  • CheDeSk: Chest depth between spine and sternum at nipple level, mid-expiration (cm)

  • CheDiSk: Chest diameter at nipple level, mid-expiration (cm)

  • ElbowSk: Elbow diameter, sum of two elbows (cm)

  • WristSk: Wrist diameter, sum of two wrists (cm)

  • KneeSk: Knee diameter, sum of two knees (cm)

  • AnkleSk: Ankle diameter, sum of two ankles (cm)

  • ShoulGi: Shoulder girth over deltoid muscles (cm)

  • ChestGi: Chest girth, nipple line in males and just above breast tissue in females, mid-expiration (cm)

  • WaistGi: Waist girth, narrowest part of torso below the rib cage, average of contracted and relaxed position (cm)

  • NavelGi: Navel (or "Abdominal") girth at umbilicus and iliac crest, iliac crest as a landmark (cm)

  • HipGi: Hip girth at level of bitrochanteric diameter (cm)

  • ThighGi: Thigh girth below gluteal fold, average of right and left girths (cm)

  • BicepGi: Bicep girth, flexed, average of right and left girths (cm)

  • ForeaGi: Forearm girth, extended, palm up, average of right and left girths (cm)

  • KneeGi: Knee girth over patella, slightly flexed position, average of right and left girths (cm)

  • CalfGi: Calf maximum girth, average of right and left girths (cm)

  • AnkleGi: Ankle minimum girth, average of right and left girths (cm)

  • WristGi: Wrist minimum girth, average of right and left girths (cm)

  • Age: (years)

  • Weight: (kg)

  • Height: (cm)

  • Gender: (1 - male, 0 - female)

Source

Heinz, G., Peterson, L.J., Johnson, R.W. and Kerk, C.J. (2003), “Exploring Relationships in Body Dimensions”, Journal of Statistics Education , 11.


Bayesian Quantile Regression

Description

This function implements the idea of Bayesian quantile regression employing a likelihood function that is based on the asymmetric Laplace distribution (Yu and Moyeed, 2001). The asymmetric Laplace error distribution is written as scale mixtures of normal distributions as in Reed and Yu (2009).

Usage

Bqr(x,y, tau =0.5, runs =11000, burn =1000, thin=1)

Arguments

x

Matrix of predictors.

y

Vector of dependent variable.

tau

The quantile of interest. Must be between 0 and 1.

runs

Length of desired Gibbs sampler output.

burn

Number of Gibbs sampler iterations before output is saved.

thin

thinning parameter of MCMC draws.

Author(s)

Rahim Alhamzawi

Examples

# Example 1
n <- 100
x <- runif(n=n,min=0,max=5)
y <- 1 + 1.5*x + .5*x*rnorm(n)
Brq(y~x,tau=0.5,runs=2000, burn=500)
fit=Brq(y~x,tau=0.5,runs=2000, burn=500)
DIC(fit)

# Example 2
n <- 100
x <- runif(n=n,min=0,max=5)
y <- 1 + 1.5*x+ .5*x*rnorm(n)
plot(x,y, main="Scatterplot and Quantile Regression Fit", xlab="x", cex=.5, col="gray")
for (i in 1:5) {
if (i==1) p = .05
if (i==2) p = .25
if (i==3) p = .50
if (i==4) p = .75
if (i==5) p = .95
fit = Brq(y~x,tau=p,runs=1500, burn=500)
# Note: runs =11000 and burn =1000
abline(a=mean(fit$coef[1]),b=mean(fit$coef[2]),lty=i,col=i)
}
abline( lm(y~x),lty=1,lwd=2,col=6)
legend(x=-0.30,y=max(y)+0.5,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")

Bayesian tobit quantile regression

Description

This function implements the idea of Bayesian tobit quantile regression employing a likelihood function that is based on the asymmetric Laplace distribution (Yu and Stander, 2007). The asymmetric Laplace error distribution is written as scale mixtures of normal distributions as in Reed and Yu (2009).

Usage

Btqr(x,y, tau = 0.5, left = 0,  runs = 11000, burn = 1000, thin=1)

Arguments

x

Matrix of predictors.

y

Vector of dependent variable.

tau

The quantile of interest. Must be between 0 and 1.

left

Left censored point.

runs

Length of desired Gibbs sampler output.

burn

Number of Gibbs sampler iterations before output is saved.

thin

thinning parameter of MCMC draws.

Author(s)

Rahim Alhamzawi

Examples

# Example 
set.seed(12345)
x <- abs(rnorm(100))
y <- -0.5 + x +(.25 + .25*x)*rnorm(100)
plot(x,y, type="n")
h <-(y > 0)
points(x[h],y[h],cex=.9,pch=16)
points(x[!h],y[!h],cex=.9,pch=1)
y <- pmax(0,y)
for(tau in (2:8)/9){
fit=Brq(y~x,tau=tau, method="Btqr", left=0, runs=1000, burn=500)$coef
# Note: runs =11000 and burn =1000
Xs=sort(x)
Xc=cbind(1,sort(x))
Xcf=Xc%*%c(fit)
Xcfp=pmax(0,Xcf)
lines(Xs,Xcfp,col="red")}

Estimate Deviance Information Criterion (DIC)

Description

This function computes the Deviance Information Criterion (DIC) for Brq, which is a hierarchical modeling generalization of the Akaike Information Criterion. It is useful for Bayesian model selection.

Usage

DIC(object)

Arguments

object

an output object of the Brq function.

References

Spiegelhalter, D.J.. Best, N.G., Carlin, B.P., van der Linde, A. (2002). Bayesian measures of model complexity and fit. Journal of the Royal Statistical Society, Series B, 64 (4): 583-639.


Immunoglobulin G Data

Description

This data set comprises the serum concentration (grams per litre) of immunoglobulin G in 298 children aged from 6 months to 6 years and is discussed in detail by Isaacs et al. (1983) and used in Keming et al. (2003).

Usage

data("ImmunogG")

Format

A data frame with 298 observations on the following 2 variables.

IgG

The serum concentration (grams per litre) of immunoglobulin G

Age

Age of children in years.

Source

[1] Isaacs, D., Altman, D. G., Tidmarsh, C. E., Valman, H. B. and Webster, A. D. B. (1983) Serum Immunoglobin concentrations in preschool children measured by laser nephelometry: reference ranges for IgG, IgA and IgM. J. Clin. Path., 36, 1193-1196.

References

[1] Yu, K., Lu, Z., & Stander, J. (2003). Quantile regression: applications and current research areas. Journal of the Royal Statistical Society:Series D (The Statistician), 52(3), 331-350.

Examples

data(ImmunogG)
attach(ImmunogG)
y=IgG
x=Age
X=cbind(x, x^2)
plot(Age,IgG)
plot(Age,IgG, main="Quantile Regression Fit", cex=.5, col="gray")
for (i in 1:5) {
if (i==1) p = .05
if (i==2) p = .25
if (i==3) p = .50
if (i==4) p = .75
if (i==5) p = .95
fit = Brq(y~X,tau=p,runs=400, burn=100)
# Note: runs =11000 and burn =1000
curve(fit$coef[1]+fit$coef[2]*x+fit$coef[3]*x^2,col=i,add=TRUE)
}

Model selection based on credible intervals

Description

Model selection based on credible intervals

Usage

model(object)

Arguments

object

an output object of the Brq function.


Produce the histogram, autocorrelation and trace plots for the objects of Brq function

Description

plot.Brq is an S3 method that produces histogram, autocorrelation and trace plots for the objects of Brq function

Usage

## S3 method for class 'Brq'
plot(x, plottype=c("hist", "trace", "ACF", "traceACF", "histACF","tracehist",
 "traceACFhist"),Coefficients=1,breaks=30,lwd=1,col1=0,col2=1,col3=1,col4=1, ...)

Arguments

x

an output object of the Brq function, i.e. an S3 object of class Brq.

plottype

should be "hist", "trace", "ACF", "traceACF", "histACF", "tracehist" or "traceACFhist".

Coefficients

Regression parameters that should be plotted

breaks

a single number giving the number of cells for the histogram,

lwd

line width relative to the default (default=1). 2 is twice as wide.

col1

color for the histograms

col2

color for the density of the histograms

col3

color for the autocorrelation

col4

color for the trace plots

...

additional arguments that are passed to the generic plot function


Print the Bayesian quantile regression methods

Description

print.Brq is an S3 method that prints the content of an S3 object of class Brq to the console.

Usage

## S3 method for class 'Brq'
print(x,...)

Arguments

x

object of class Brq

...

not used.

Value

Print the Bayesian quantile regression methods


Print the summary of Bayesian quantile regression methods.

Description

print.Brq.summary is an S3 method that prints the content of an S3 object of class Brq.summary to the console.

Usage

## S3 method for class 'summary.Brq'
print(x, ...)

Arguments

x

object of class Brq.

...

not used.

Value

Print the summary of Bayesian quantile regression methods.

Author(s)

Rahim Alhamzawi

Examples

# Simulate data from heteroskedastic regression
set.seed(666)
n <- 100
x <- runif(n=n,min=0,max=10)
y <- 2 + 2*x + 0.6 *x*rnorm(n=n, mean=0, sd=1)

fit <- Brq(y ~ x, tau=0.5, method="Bqr") 

# Return Bayes estimates and credible intervals 
Results<- summary(fit)

# Print the Brq.summary object
Results

Prostate Cancer Data

Description

The data is taken from a prostate cancer study (Stamey et al., 1989). It has 97 rows and 9 columns. The response variable is the logarithm of prostate-specific antigen. The covariates are eight clinical measures: the logarithm of cancer volume (lcavol), the logarithm of prostate weight (lweight), age, the logarithm of the amount of benign prostatic hyperplasia (lbph), seminal vesicle invasion (svi), the logarithm of capsular penetration (lcp), the Gleason score (gleason) and the percentage Gleason score 4 or 5 (pgg45).

Usage

data("Prostate")

Format

The data frame has the following components:

  • lcavol : The logarithm of cancer volume.

  • lweight : The logarithm of prostate weight.

  • age : Age

  • lbph : The logarithm of the amount of benign prostatic hyperplasia.

  • svi : Seminal vesicle invasion.

  • lcp : The logarithm of capsular penetration.

  • gleason : Gleason score.

  • pgg45 : Percentage Gleason scores 4 or 5.

  • lpsa : The logarithm of prostate-specific antigen.

Source

Stamey, T. A., Kabalin, J. N., McNeal, J. E., Johnstone, I. M., Freiha, F., Redwine, E. A., and Yang, N. (1989). Prostate specific antigen in the diagnosis and treatment of adenocarcinoma of the prostate. II. Radical prostatectomy treated patients. The Journal of urology, 141(5), 1076-1083.

References

Stamey, T. A., Kabalin, J. N., McNeal, J. E., Johnstone, I. M., Freiha, F., Redwine, E. A., & Yang, N. (1989). Prostate specific antigen in the diagnosis and treatment of adenocarcinoma of the prostate. II. Radical prostatectomy treated patients. The Journal of urology, 141(5), 1076-1083.

Examples

data(Prostate)
y=Prostate[,9]
x=as.matrix(Prostate[, -9])
y=y-mean(y)
x=scale(x)
fit=Brq(y~0+x, method="BLqr")
plot(fit, plottype="hist",D=1:8)
plot(fit, plottype="hist",D=1:8, col2=4,lwd=2)
plot(fit, plottype="trace",D=1:8, col4=4)

Salaries of 459 US statistics professor data

Description

A university union collected data on the salaries of 459 US statistics professors and the number of years for which they had been professors during the period from 1980 to 1990 (Bailar, 1991).

Usage

data("salary")

Format

A data frame with 459 observations on the following 2 variables.

Salaries

Salaries of 459 US statistics professor (1000s of dollars).

Years

Number of years as professor

Source

[1] Bailar, B. (1991) Salary survey of U.S. colleges and universities offering degrees in statistics. Amstat News, 182, 3-10.

References

[1] Bailar, B. (1991) Salary survey of U.S. colleges and universities offering degrees in statistics. Amstat News, 182, 3-10.


Summarize the output of the Brq function

Description

summary.Brq is an S3 method that summarizes the output of the Brq function in an object of class summary.Brq. This function produces the Bayesian estimates and credible intervals for the regression coefficients.

Usage

## S3 method for class 'Brq'
summary(object, ...)

Arguments

object

an object of class Brq.

...

not used.

Author(s)

Rahim Alhamzawi

References

[1] Alhamzawi, R. (2018). Brq: An R package for Bayesian Quantile Regression. Working paper.

Examples

# Example 

fit = Brq(stack.loss~stack.x,tau=0.5, method= "Bqr", runs=5000, burn=1000)
summary(fit)

Weight and age for a sample of 4011 US girl data

Description

This data set comprises weight and age for a sample of 4011 US girls reported in Cole (1988) and used in Keming et al. (2003).

Usage

data(USgirl)

Format

A data frame with 4011 observations on the following 2 variables.

Age

Age (years)

Weight

Weight (Kg)

References

[1] Cole, T. J. (1988) Fitting smoothed centile curves to reference data (with discussion). J R. Statist. Soc. A, 151, 385-418.

[2] Yu, K., Lu, Z., and Stander, J. (2003). Quantile regression: applications and current research areas. Journal of the Royal Statistical Society: Series D (The Statistician), 52(3), 331-350.


Wheat Data

Description

This is a regression subsample data set consisting of 113 observations on 6 variables is taken from the national program for the development of wheat cultivation in Iraq - Qadisiyah governorate branch (2017). The complete data set was first analyzed by Hilali (2019). The outcome of interest in this dataset is the percentage increase in wheat yield per dunam (2500 square meters).

Usage

data("wheat")

Format

A data frame with 113 observations on the following 6 variables.

y

a numeric vector

U

a numeric vector

Qs

a numeric vector

H

a numeric vector

K

a numeric vector

ME

a numeric vector

References

Abbas, H. K. and Taher, R. J. (2019). Bayesian adaptive lasso tobit regression. Journal of Al-Qadisiyah for Computer Science and Mathematics, 110 (1). <doi:10.29304/jqcm.2019.11.1.471>