Learn R Programming

lqr (version 4.1)

lqr: Robust Linear Quantile Regression

Description

It fits a robust linear quantile regression model using a new family of zero-quantile distributions for the error term. This family of distribution includes skewed versions of the Normal, Student's t, Laplace, Slash and Contaminated Normal distribution. It provides estimates and full inference. It also provides envelopes plots for assessing the fit and confidences bands when several quantiles are provided simultaneously.

Usage

lqr(y,x,p=0.5,dist="normal",nu="",gama="",precision=10^-6,envelope=FALSE,CI=0.95)

#lqr(y, x, p = 0.5, dist = "normal") #lqr(y, x, p = 0.5, dist = "t") #lqr(y, x, p = 0.5, dist = "laplace") #lqr(y, x, p = 0.5, dist = "slash") #lqr(y, x, p = 0.5, dist = "cont")

#lqr(y, x, p = c(0.25,0.50,0.75), dist = "normal")

Arguments

y

the response vector of dimension \(n\) where \(n\) is the total of observations.

x

design matrix for the fixed effects of dimension \(N x d\) where \(d\) represents the number of fixed effects including the intercept, if considered.

p

An unique quantile or a set of quantiles related to the quantile regression.

dist

represents the distribution to be used for the error term. The values are normal for Normal distribution, t for Student's t distribution, laplace for Laplace distribution, slash for Slash distribution and cont for the Contaminated normal distribution.

nu

It represents the degrees of freedom when dist = t. For the Slash distribution (dist = slash) it is a shape parameter \(\nu>0\). For the Contaminated Normal distribution, \(\nu\) is the parameter that represents the percentage of outliers. When is not provided, we use the MLE.

gama

It represents a scale factor for the contaminated normal distribution. When is not provided, we use the MLE.

precision

The convergence maximum error permitted. By default is 10^-6.

envelope

if TRUE, it will show a confidence envelope for a curve based on bootstrap replicates. By default it is TRUE when just one quantile is provided. If a grid of quantiles is provided it will be FALSE by default.

CI

Confidence to be used for the Confidence Interval when a grid of quantiles is provided. Default = 0.95.

Value

iter

number of iterations.

criteria

attained criteria value.

beta

fixed effects estimates.

sigma

scale parameter estimate for the error term.

nu

Estimate of nu parameter detailed above.

gamma

Estimate of gamma parameter detailed above.

SE

Standard Error estimates.

table

Table containing the inference for the fixed effects parameters.

loglik

Log-likelihood value.

AIC

Akaike information criterion.

BIC

Bayesian information criterion.

HQ

Hannan-Quinn information criterion.

fitted.values

vector containing the fitted values.

residuals

vector containing the residuals.

Details

When a grid of quantiles is provided, a graphical summary with point estimates and Confidence Intervals for model parameters is shown.

References

Galarza, C., Lachos, V. H., Cabral, C. R. B., & Castro, C. L. (2017). Robust quantile regression using a generalized class of skewed distributions. Stat, 6(1), 113-130.

Wichitaksorn, N., Choy, S. T., & Gerlach, R. (2014). A generalized class of skew distributions and associated robust quantile regression models. Canadian Journal of Statistics, 42(4), 579-596.

See Also

cens.lqr,best.lqr,Log.lqr, Log.best.lqr,dSKD,QRLMM, QRNLMM

Examples

Run this code
# NOT RUN {
#Example 1
##Load the data
data(ais)
attach(ais)

##Setting
y<-BMI
x<-cbind(1,LBM,Sex)

## Fitting a median regression with Normal errors (by default)

modelF = lqr(y[Sex==1], x[Sex==1,1:2])
modelM = lqr(y[Sex==0], x[Sex==0,1:2])
plot(LBM,BMI,col=Sex+1,xlab="Lean Body Mass",ylab="Body4 Mass Index",main="Quantile Regression")
abline(a = modelF$beta[1],b = modelF$beta[2],lwd=2,col=2)
abline(a = modelM$beta[1],b = modelM$beta[2],lwd=2,col=4)

#COMPARING SOME MODELS for median regression
x<-cbind(1,LBM)

modelN  = lqr(y,x,dist = "normal")
modelT  = lqr(y,x,dist = "t")
modelL  = lqr(y,x,dist = "laplace")

#Comparing AIC criterias
modelN$AIC;modelT$AIC;modelL$AIC

#This could be automatically done using best.lqr()
best.model = best.lqr(y, x, p = 0.75, criterion = "AIC")

#Let's use a grid of quantiles
modelfull = lqr(y,x,p = seq(from = 0.10,to = 0.90,by = 0.05),dist = "normal")

#Plotting quantiles 0.10,0.25,0.50,0.75 and 0.90

plot(LBM,BMI,xlab = "Lean Body Mass"
     ,ylab = "Body Mass Index", main = "Quantile Regression",pch=16)
abline(a = modelfull[[1]]$beta[1],b = modelfull[[1]]$beta[2],lwd=2,lty=1,col=2)
abline(a = modelfull[[17]]$beta[1],b = modelfull[[17]]$beta[2],lwd=2,lty=1,col=2)
abline(a = modelfull[[4]]$beta[1],b = modelfull[[4]]$beta[2],lwd=2,lty=1,col=3)
abline(a = modelfull[[14]]$beta[1],b = modelfull[[14]]$beta[2],lwd=2,lty=1,col=3)
abline(a = modelfull[[9]]$beta[1],b = modelfull[[9]]$beta[2],lwd=2,lty=1,col=4)


#Example 2
##Load the data

data(crabs,package = "MASS")

crabs$sex <- as.character(crabs$sex)
crabs$sex[crabs$sex=="M"]=0
crabs$sex[crabs$sex=="F"]=1
crabs$sex = as.numeric(crabs$sex)

attach(crabs)
head(crabs)

##Setting
y  <- BD
x  <- cbind(1,FL,sex)
plot(crabs)

## Fitting a median regression with Normal errors (by default)
modelF = lqr(y[sex==1], x[sex==1,1:2])
modelM = lqr(y[sex==0], x[sex==0,1:2])
plot(FL,BD,col=sex+1,xlab="Frontal lobe size",ylab="Body depth",main="Quantile Regression")
abline(a = modelF$beta[1],b = modelF$beta[2],lwd=2,col=2)
abline(a = modelM$beta[1],b = modelM$beta[2],lwd=2,col=4)

#COMPARING SOME MODELS for median regression
x<-cbind(1,FL)

modelN  = lqr(y,x,dist = "normal")
modelT  = lqr(y,x,dist = "t")
modelL  = lqr(y,x,dist = "laplace")
modelS  = lqr(y,x,dist = "slash")
modelC  = lqr(y,x,dist = "cont" )

#Comparing AIC criterias
modelN$AIC;modelT$AIC;modelL$AIC;modelS$AIC;modelC$AIC

#Let's use a grid of quantiles
modelfull = lqr(y,x,p = seq(from = 0.10,to = 0.90,by = 0.05),dist = "t")

#Plotting quantiles 0.10,0.25,0.50,0.75 and 0.90

plot(FL,BD,xlab = "Frontal lobe size"
     ,ylab = "Body depth", main = "Quantile Regression",pch=16)
abline(a = modelfull[[1]]$beta[1],b = modelfull[[1]]$beta[2],lwd=2,lty=1,col=2)
abline(a = modelfull[[17]]$beta[1],b = modelfull[[17]]$beta[2],lwd=2,lty=1,col=2)
abline(a = modelfull[[4]]$beta[1],b = modelfull[[4]]$beta[2],lwd=2,lty=1,col=3)
abline(a = modelfull[[14]]$beta[1],b = modelfull[[14]]$beta[2],lwd=2,lty=1,col=3)
abline(a = modelfull[[9]]$beta[1],b = modelfull[[9]]$beta[2],lwd=2,lty=1,col=4)
# }

Run the code above in your browser using DataLab