nag_regsn_quant_linear_iid (g02qfc) (PDF version)
g02 Chapter Contents
g02 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_regsn_quant_linear_iid (g02qfc)

## 1  Purpose

nag_regsn_quant_linear_iid (g02qfc) performs a multiple linear quantile regression, returning the parameter estimates and associated confidence limits based on an assumption of Normal, independent, identically distributed errors. nag_regsn_quant_linear_iid (g02qfc) is a simplified version of nag_regsn_quant_linear (g02qgc).

## 2  Specification

 #include #include
 void nag_regsn_quant_linear_iid (Integer n, Integer m, const double x[], const double y[], Integer ntau, const double tau[], double *df, double b[], double bl[], double bu[], Integer info[], NagError *fail)

## 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)$, nag_regsn_quant_linear_iid (g02qfc) 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.
nag_regsn_quant_linear_iid (g02qfc) 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 nag_regsn_quant_linear_iid (g02qfc) can be found in the documentation for nag_regsn_quant_linear (g02qgc).

## 4  References

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

## 5  Arguments

1:     nIntegerInput
On entry: $n$, the number of observations in the dataset.
Constraint: ${\mathbf{n}}\ge 2$.
2:     mIntegerInput
On entry: $p$, the number of variates in the model.
Constraint: $1\le {\mathbf{m}}<{\mathbf{n}}$.
3:     x[${\mathbf{n}}×{\mathbf{m}}$]const doubleInput
Note: where ${\mathbf{X}}\left(i,j\right)$ appears in this document, it refers to the array element ${\mathbf{x}}\left[\left(i-1\right)×{\mathbf{m}}+j-1\right]$.
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]const doubleInput
On entry: $y$, observations on the dependent variable.
5:     ntauIntegerInput
On entry: the number of quantiles of interest.
Constraint: ${\mathbf{ntau}}\ge 1$.
6:     tau[ntau]const doubleInput
On entry: the vector of quantiles of interest. A separate model is fitted to each quantile.
Constraint: $\sqrt{\epsilon }<{\mathbf{tau}}\left[\mathit{l}-1\right]<1-\sqrt{\epsilon }$ where $\epsilon$ is the machine precision returned by nag_machine_precision (X02AJC), for $\mathit{l}=1,2,\dots ,{\mathbf{ntau}}$.
7:     dfdouble *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[${\mathbf{m}}×{\mathbf{ntau}}$]doubleOutput
Note: where ${\mathbf{B}}\left(j,l\right)$ appears in this document, it refers to the array element ${\mathbf{b}}\left[\left(l-1\right)×{\mathbf{m}}+j-1\right]$.
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-1\right]$.
9:     bl[${\mathbf{m}}×{\mathbf{ntau}}$]doubleOutput
Note: where ${\mathbf{BL}}\left(j,l\right)$ appears in this document, it refers to the array element ${\mathbf{bl}}\left[\left(l-1\right)×{\mathbf{m}}+j-1\right]$.
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[${\mathbf{m}}×{\mathbf{ntau}}$]doubleOutput
Note: where ${\mathbf{BU}}\left(j,l\right)$ appears in this document, it refers to the array element ${\mathbf{bu}}\left[\left(l-1\right)×{\mathbf{m}}+j-1\right]$.
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}}$]IntegerOutput
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 function 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 function 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:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_BAD_PARAM
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 2$.
On entry, ${\mathbf{ntau}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ntau}}\ge 1$.
NE_INT_2
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: $1\le {\mathbf{m}}<{\mathbf{n}}$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_REAL_ARRAY
On entry, ${\mathbf{tau}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$ is invalid.
NW_POTENTIAL_PROBLEM
A potential problem occurred whilst fitting the model(s).
Additional information has been returned in info.

Not applicable.

## 8  Further Comments

Calling nag_regsn_quant_linear_iid (g02qfc) is equivalent to calling nag_regsn_quant_linear (g02qgc) with
• ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{intcpt}}=\mathrm{Nag_NoIntercept}$,
• no weights supplied, i.e., wt set to NULL,
• ${\mathbf{pddat}}={\mathbf{m}}$,
• 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 (g02qfce.c)

### 9.2  Program Data

Program Data (g02qfce.d)

### 9.3  Program Results

Program Results (g02qfce.r)

nag_regsn_quant_linear_iid (g02qfc) (PDF version)
g02 Chapter Contents
g02 Chapter Introduction
NAG C Library Manual