G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG02QFF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G02QFF performs a multiple linear quantile regression, returning the parameter estimates and associated confidence limits based on an assumption of Normal, independent, identically distributed errors. G02QFF is a simplified version of G02QGF.

## 2  Specification

 SUBROUTINE G02QFF ( N, M, X, Y, NTAU, TAU, DF, B, BL, BU, INFO, IFAIL)
 INTEGER N, M, NTAU, INFO(NTAU), IFAIL REAL (KIND=nag_wp) X(N,M), Y(N), TAU(NTAU), DF, B(M,NTAU), BL(M,NTAU), BU(M,NTAU)

## 3  Description

Given a vector of $n$ observed values, $y=\left\{{y}_{i}:i=1,2,\dots ,n\right\}$, an $n×p$ design matrix $X$, a column vector, $x$, of length $p$ holding the $i$th row of $X$ and a quantile $\tau \in \left(0,1\right)$, G02QFF estimates the $p$-element vector $\beta$ as the solution to
 $minimize β ∈ ℝ p ∑ i=1 n ρ τ y i - xiT β$ (1)
where ${\rho }_{\tau }$ is the piecewise linear loss function ${\rho }_{\tau }\left(z\right)=z\left(\tau -I\left(z<0\right)\right)$, and $I\left(z<0\right)$ is an indicator function taking the value $1$ if $z<0$ and $0$ otherwise.
G02QFF assumes Normal, independent, identically distributed (IID) errors and calculates the asymptotic covariance matrix from
 $Σ = τ 1 - τ n s τ 2 XT X -1$
where $s$ is the sparsity function, which is estimated from the residuals, ${r}_{i}={y}_{i}-{x}_{i}^{\mathrm{T}}\stackrel{^}{\beta }$ (see Koenker (2005)).
Given an estimate of the covariance matrix, $\stackrel{^}{\Sigma }$, lower, ${\stackrel{^}{\beta }}_{L}$, and upper, ${\stackrel{^}{\beta }}_{U}$, limits for a $95%$ confidence interval are calculated for each of the $p$ parameters, via
 $β^ Li = β^ i - t n-p , 0.975 Σ^ ii , β^ Ui = β^ i + t n-p , 0.975 Σ^ ii$
where ${t}_{n-p,0.975}$ is the $97.5$ percentile of the Student's $t$ distribution with $n-k$ degrees of freedom, where $k$ is the rank of the cross-product matrix ${X}^{\mathrm{T}}X$.
Further details of the algorithms used by G02QFF can be found in the documentation for G02QGF.

## 4  References

Koenker R (2005) Quantile Regression Econometric Society Monographs, Cambridge University Press, New York

## 5  Parameters

1:     N – INTEGERInput
On entry: $n$, the number of observations in the dataset.
Constraint: ${\mathbf{N}}\ge 2$.
2:     M – INTEGERInput
On entry: $p$, the number of variates in the model.
Constraint: $1\le {\mathbf{M}}<{\mathbf{N}}$.
3:     X(N,M) – REAL (KIND=nag_wp) arrayInput
On entry: $X$, the design matrix, with the $\mathit{i}$th value for the $\mathit{j}$th variate supplied in ${\mathbf{X}}\left(\mathit{i},\mathit{j}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{N}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{M}}$.
4:     Y(N) – REAL (KIND=nag_wp) arrayInput
On entry: $y$, observations on the dependent variable.
5:     NTAU – INTEGERInput
On entry: the number of quantiles of interest.
Constraint: ${\mathbf{NTAU}}\ge 1$.
6:     TAU(NTAU) – REAL (KIND=nag_wp) arrayInput
On entry: the vector of quantiles of interest. A separate model is fitted to each quantile.
Constraint: $\sqrt{\epsilon }<{\mathbf{TAU}}\left(\mathit{l}\right)<1-\sqrt{\epsilon }$ where $\epsilon$ is the machine precision returned by X02AJF, for $\mathit{l}=1,2,\dots ,{\mathbf{NTAU}}$.
7:     DF – REAL (KIND=nag_wp)Output
On exit: the degrees of freedom given by $n-k$, where $n$ is the number of observations and $k$ is the rank of the cross-product matrix ${X}^{\mathrm{T}}X$.
8:     B(M,NTAU) – REAL (KIND=nag_wp) arrayOutput
On exit: $\stackrel{^}{\beta }$, the estimates of the parameters of the regression model, with ${\mathbf{B}}\left(j,l\right)$ containing the coefficient for the variable in column $j$ of X, estimated for $\tau ={\mathbf{TAU}}\left(l\right)$.
9:     BL(M,NTAU) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\stackrel{^}{\beta }}_{L}$, the lower limit of a $95%$ confidence interval for $\stackrel{^}{\beta }$, with ${\mathbf{BL}}\left(j,l\right)$ holding the lower limit associated with ${\mathbf{B}}\left(j,l\right)$.
10:   BU(M,NTAU) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\stackrel{^}{\beta }}_{U}$, the upper limit of a $95%$ confidence interval for $\stackrel{^}{\beta }$, with ${\mathbf{BU}}\left(j,l\right)$ holding the upper limit associated with ${\mathbf{B}}\left(j,l\right)$.
11:   INFO(${\mathbf{NTAU}}$) – INTEGER arrayOutput
On exit: ${\mathbf{INFO}}\left(l\right)$ holds additional information concerning the model fitting and confidence limit calculations when $\tau ={\mathbf{TAU}}\left(l\right)$.
 Code Warning $0$ Model fitted and confidence limits calculated successfully. $1$ The routine did not converge whilst calculating the parameter estimates. The returned values are based on the estimate at the last iteration. $2$ A singular matrix was encountered during the optimization. The model was not fitted for this value of $\tau$. $8$ The routine did not converge whilst calculating the confidence limits. The returned limits are based on the estimate at the last iteration. $16$ Confidence limits for this value of $\tau$ could not be calculated. The returned upper and lower limits are set to a large positive and large negative value respectively.
It is possible for multiple warnings to be applicable to a single model. In these cases the value returned in INFO is the sum of the corresponding individual nonzero warning codes.
12:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=11$
On entry, ${\mathbf{N}}<2$.
${\mathbf{IFAIL}}=21$
 On entry, ${\mathbf{M}}<1$, or ${\mathbf{M}}\ge {\mathbf{N}}$.
${\mathbf{IFAIL}}=51$
On entry, ${\mathbf{NTAU}}<1$.
${\mathbf{IFAIL}}=61$
On entry, TAU is invalid.
${\mathbf{IFAIL}}=111$
On exit, problems were encountered whilst fitting at least one model. Additional information has been returned in INFO.

## 7  Accuracy

Not applicable.

Calling G02QFF is equivalent to calling G02QGF with
• ${\mathbf{RCORD}}=2$,
• ${\mathbf{INTCPT}}=\text{'N'}$,
• ${\mathbf{WEIGHT}}=\text{'U'}$,
• ${\mathbf{LDDAT}}={\mathbf{N}}$,
• setting each element of ISX to $1$,
• ${\mathbf{IP}}={\mathbf{M}}$,
• ${\mathbf{Interval Method}}=\mathrm{IID}$, and
• ${\mathbf{Significance Level}}=0.95$.

## 9  Example

A quantile regression model is fitted to Engels 1857 study of household expenditure on food. The model regresses the dependent variable, household food expenditure, against household income. An intercept is included in the model by augmenting the dataset with a column of ones.

### 9.1  Program Text

Program Text (g02qffe.f90)

### 9.2  Program Data

Program Data (g02qffe.d)

### 9.3  Program Results

Program Results (g02qffe.r)