# NAG Library Function Document

## 1Purpose

nag_rank_regsn (g08rac) calculates the parameter estimates, score statistics and their variance-covariance matrices for the linear model using a likelihood based on the ranks of the observations.

## 2Specification

 #include #include
 void nag_rank_regsn (Nag_OrderType order, Integer ns, const Integer nv[], const double y[], Integer p, const double x[], Integer pdx, Integer idist, Integer nmax, double tol, double prvr[], Integer pdparvar, Integer irank[], double zin[], double eta[], double vapvec[], double parest[], NagError *fail)

## 3Description

Analysis of data can be made by replacing observations by their ranks. The analysis produces inference for regression arguments arising from the following model.
For random variables ${Y}_{1},{Y}_{2},\dots ,{Y}_{n}$ we assume that, after an arbitrary monotone increasing differentiable transformation, $h\left(.\right)$, the model
 $hYi= xiT β+εi$ (1)
holds, where ${x}_{i}$ is a known vector of explanatory variables and $\beta$ is a vector of $p$ unknown regression coefficients. The ${\epsilon }_{i}$ are random variables assumed to be independent and identically distributed with a completely known distribution which can be one of the following: Normal, logistic, extreme value or double-exponential. In Pettitt (1982) an estimate for $\beta$ is proposed as $\stackrel{^}{\beta }=M{X}^{\mathrm{T}}a$ with estimated variance-covariance matrix $M$. The statistics $a$ and $M$ depend on the ranks ${r}_{i}$ of the observations ${Y}_{i}$ and the density chosen for ${\epsilon }_{i}$.
The matrix $X$ is the $n$ by $p$ matrix of explanatory variables. It is assumed that $X$ is of rank $p$ and that a column or a linear combination of columns of $X$ is not equal to the column vector of $1$ or a multiple of it. This means that a constant term cannot be included in the model (1). The statistics $a$ and $M$ are found as follows. Let ${\epsilon }_{i}$ have pdf $f\left(\epsilon \right)$ and let $g=-{f}^{\prime }/f$. Let ${W}_{1},{W}_{2},\dots ,{W}_{n}$ be order statistics for a random sample of size $n$ with the density $f\left(.\right)$. Define ${Z}_{i}=g\left({W}_{i}\right)$, then ${a}_{i}=E\left({Z}_{{r}_{i}}\right)$. To define $M$ we need ${M}^{-1}={X}^{\mathrm{T}}\left(B-A\right)X$, where $B$ is an $n$ by $n$ diagonal matrix with ${B}_{ii}=E\left({g}^{\prime }\left({W}_{{r}_{i}}\right)\right)$ and $A$ is a symmetric matrix with ${A}_{ij}=\mathrm{cov}\left({Z}_{{r}_{i}},{Z}_{{r}_{j}}\right)$. In the case of the Normal distribution, the ${Z}_{1}<\cdots <{Z}_{n}$ are standard Normal order statistics and $E\left({g}^{\prime }\left({W}_{i}\right)\right)=1$, for $i=1,2,\dots ,n$.
The analysis can also deal with ties in the data. Two observations are adjudged to be tied if $\left|{Y}_{i}-{Y}_{j}\right|<{\mathbf{tol}}$, where tol is a user-supplied tolerance level.
Various statistics can be found from the analysis:
 (a) The score statistic ${X}^{\mathrm{T}}a$. This statistic is used to test the hypothesis ${H}_{0}:\beta =0$, see (e). (b) The estimated variance-covariance matrix ${X}^{\mathrm{T}}\left(B-A\right)X$ of the score statistic in (a). (c) The estimate $\stackrel{^}{\beta }=M{X}^{\mathrm{T}}a$. (d) The estimated variance-covariance matrix $M={\left({X}^{\mathrm{T}}\left(B-A\right)X\right)}^{-1}$ of the estimate $\stackrel{^}{\beta }$. (e) The ${\chi }^{2}$ statistic $Q={\stackrel{^}{\beta }}^{\mathrm{T}}{M}^{-1}\stackrel{^}{\beta }={a}^{\mathrm{T}}X{\left({X}^{\mathrm{T}}\left(B-A\right)X\right)}^{-1}{X}^{\mathrm{T}}a$ used to test ${H}_{0}:\beta =0$. Under ${H}_{0}$, $Q$ has an approximate ${\chi }^{2}$-distribution with $p$ degrees of freedom. (f) The standard errors ${M}_{ii}^{1/2}$ of the estimates given in (c). (g) Approximate $z$-statistics, i.e., ${Z}_{i}={\stackrel{^}{\beta }}_{i}/se\left({\stackrel{^}{\beta }}_{i}\right)$ for testing ${H}_{0}:{\beta }_{i}=0$. For $i=1,2,\dots ,n$, ${Z}_{i}$ has an approximate $N\left(0,1\right)$ distribution.
In many situations, more than one sample of observations will be available. In this case we assume the model
 $hkYk= XkT β+ek, k=1,2,…,ns,$
where ns is the number of samples. In an obvious manner, ${Y}_{k}$ and ${X}_{k}$ are the vector of observations and the design matrix for the $k$th sample respectively. Note that the arbitrary transformation ${h}_{k}$ can be assumed different for each sample since observations are ranked within the sample.
The earlier analysis can be extended to give a combined estimate of $\beta$ as $\stackrel{^}{\beta }=Dd$, where
 $D-1=∑k=1ns XkT Bk-AkXk$
and
 $d=∑k= 1ns XkT ak ,$
with ${a}_{k}$, ${B}_{k}$ and ${A}_{k}$ defined as $a$, $B$ and $A$ above but for the $k$th sample.
The remaining statistics are calculated as for the one sample case.

## 4References

Pettitt A N (1982) Inference for the linear model using a likelihood based on ranks J. Roy. Statist. Soc. Ser. B 44 234–243

## 5Arguments

1:    $\mathbf{order}$Nag_OrderTypeInput
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by ${\mathbf{order}}=\mathrm{Nag_RowMajor}$. See Section 3.3.1.3 in How to Use the NAG Library and its Documentation for a more detailed explanation of the use of this argument.
Constraint: ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ or $\mathrm{Nag_ColMajor}$.
2:    $\mathbf{ns}$IntegerInput
On entry: the number of samples.
Constraint: ${\mathbf{ns}}\ge 1$.
3:    $\mathbf{nv}\left[{\mathbf{ns}}\right]$const IntegerInput
On entry: the number of observations in the $\mathit{i}$th sample, for $\mathit{i}=1,2,\dots ,{\mathbf{ns}}$.
Constraint: ${\mathbf{nv}}\left[\mathit{i}\right]\ge 1$, for $\mathit{i}=0,1,\dots ,{\mathbf{ns}}-1$.
4:    $\mathbf{y}\left[\mathit{dim}\right]$const doubleInput
Note: the dimension, dim, of the array y must be at least $\left(\sum _{\mathit{i}=1}^{{\mathbf{ns}}}{\mathbf{nv}}\left[\mathit{i}-1\right]\right)$.
On entry: the observations in each sample. Specifically, ${\mathbf{y}}\left[\sum _{k=1}^{i-1}{\mathbf{nv}}\left[k-1\right]+j-1\right]$ must contain the $j$th observation in the $i$th sample.
5:    $\mathbf{p}$IntegerInput
On entry: the number of parameters to be fitted.
Constraint: ${\mathbf{p}}\ge 1$.
6:    $\mathbf{x}\left[\mathit{dim}\right]$const doubleInput
Note: the dimension, dim, of the array x must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdx}}×{\mathbf{p}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\left(\sum _{\mathit{i}=1}^{{\mathbf{ns}}}{\mathbf{nv}}\left[\mathit{i}-1\right]\right)×{\mathbf{pdx}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
Where ${\mathbf{X}}\left(i,j\right)$ appears in this document, it refers to the array element
• ${\mathbf{x}}\left[\left(j-1\right)×{\mathbf{pdx}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{x}}\left[\left(i-1\right)×{\mathbf{pdx}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: the design matrices for each sample. Specifically, ${\mathbf{X}}\left(\sum _{k=1}^{i-1}{\mathbf{nv}}\left[k-1\right]+j,l\right)$ must contain the value of the $l$th explanatory variable for the $j$th observation in the $i$th sample.
Constraint: ${\mathbf{x}}$ must not contain a column with all elements equal.
7:    $\mathbf{pdx}$IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array x.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$, ${\mathbf{pdx}}\ge \left(\sum _{\mathit{i}=1}^{{\mathbf{ns}}}{\mathbf{nv}}\left[\mathit{i}-1\right]\right)$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pdx}}\ge {\mathbf{p}}$.
8:    $\mathbf{idist}$IntegerInput
On entry: the error distribution to be used in the analysis.
${\mathbf{idist}}=1$
Normal.
${\mathbf{idist}}=2$
Logistic.
${\mathbf{idist}}=3$
Extreme value.
${\mathbf{idist}}=4$
Double-exponential.
Constraint: $1\le {\mathbf{idist}}\le 4$.
9:    $\mathbf{nmax}$IntegerInput
On entry: the value of the largest sample size.
Constraint: ${\mathbf{nmax}}=\underset{1\le i\le {\mathbf{ns}}}{\mathrm{max}}\phantom{\rule{0.25em}{0ex}}\left({\mathbf{nv}}\left[i-1\right]\right)$ and ${\mathbf{nmax}}>{\mathbf{p}}$.
10:  $\mathbf{tol}$doubleInput
On entry: the tolerance for judging whether two observations are tied. Thus, observations ${Y}_{i}$ and ${Y}_{j}$ are adjudged to be tied if $\left|{Y}_{i}-{Y}_{j}\right|<{\mathbf{tol}}$.
Constraint: ${\mathbf{tol}}>0.0$.
11:  $\mathbf{prvr}\left[\mathit{dim}\right]$doubleOutput
Note: the dimension, dim, of the array prvr must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdparvar}}×{\mathbf{p}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{p}}+1×{\mathbf{pdparvar}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
Where ${\mathbf{PRVR}}\left(i,j\right)$ appears in this document, it refers to the array element
• ${\mathbf{prvr}}\left[\left(j-1\right)×{\mathbf{pdparvar}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{prvr}}\left[\left(i-1\right)×{\mathbf{pdparvar}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On exit: the variance-covariance matrices of the score statistics and the parameter estimates, the former being stored in the upper triangle and the latter in the lower triangle. Thus for $1\le i\le j\le {\mathbf{p}}$, ${\mathbf{PRVR}}\left(i,j\right)$ contains an estimate of the covariance between the $i$th and $j$th score statistics. For $1\le j\le i\le {\mathbf{p}}-1$, ${\mathbf{PRVR}}\left(i+1,j\right)$ contains an estimate of the covariance between the $i$th and $j$th parameter estimates.
12:  $\mathbf{pdparvar}$IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array prvr.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$, ${\mathbf{pdparvar}}\ge {\mathbf{p}}+1$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pdparvar}}\ge {\mathbf{p}}$.
13:  $\mathbf{irank}\left[{\mathbf{nmax}}\right]$IntegerOutput
On exit: for the one sample case, irank contains the ranks of the observations.
14:  $\mathbf{zin}\left[{\mathbf{nmax}}\right]$doubleOutput
On exit: for the one sample case, zin contains the expected values of the function $g\left(.\right)$ of the order statistics.
15:  $\mathbf{eta}\left[{\mathbf{nmax}}\right]$doubleOutput
On exit: for the one sample case, eta contains the expected values of the function $g\prime \left(.\right)$ of the order statistics.
16:  $\mathbf{vapvec}\left[{\mathbf{nmax}}×\left({\mathbf{nmax}}+1\right)/2\right]$doubleOutput
On exit: for the one sample case, vapvec contains the upper triangle of the variance-covariance matrix of the function $g\left(.\right)$ of the order statistics stored column-wise.
17:  $\mathbf{parest}\left[4×{\mathbf{p}}+1\right]$doubleOutput
On exit: the statistics calculated by the function.
The first p components of parest contain the score statistics.
The next p elements contain the parameter estimates.
${\mathbf{parest}}\left[2×{\mathbf{p}}\right]$ contains the value of the ${\chi }^{2}$ statistic.
The next p elements of parest contain the standard errors of the parameter estimates.
Finally, the remaining p elements of parest contain the $z$-statistics.
18:  $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, idist is outside the range $1$ to $4$: ${\mathbf{idist}}=〈\mathit{\text{value}}〉$.
On entry, ${\mathbf{ns}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ns}}\ge 1$.
On entry, ${\mathbf{p}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{p}}\ge 1$.
On entry, ${\mathbf{pdparvar}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdparvar}}>0$.
On entry, ${\mathbf{pdx}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdx}}>0$.
NE_INT_2
On entry, ${\mathbf{nmax}}=〈\mathit{\text{value}}〉$ and ${\mathbf{p}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nmax}}>{\mathbf{p}}$.
On entry, ${\mathbf{pdparvar}}=〈\mathit{\text{value}}〉$ and ${\mathbf{p}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdparvar}}\ge {\mathbf{p}}$.
On entry, ${\mathbf{pdparvar}}=〈\mathit{\text{value}}〉$ and ${\mathbf{p}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdparvar}}\ge {\mathbf{p}}+1$.
On entry, ${\mathbf{pdx}}=〈\mathit{\text{value}}〉$ and ${\mathbf{p}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdx}}\ge {\mathbf{p}}$.
On entry, ${\mathbf{pdx}}=〈\mathit{\text{value}}〉$ and sum ${\mathbf{nv}}\left[i-1\right]=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdx}}\ge \text{}$ the sum of ${\mathbf{nv}}\left[i-1\right]$.
NE_INT_ARRAY
On entry, ${\mathbf{nv}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nv}}\left[\mathit{i}\right]\ge 1$, for $\mathit{i}=0,1,\dots ,{\mathbf{ns}}-1$.
NE_INT_ARRAY_ELEM_CONS
On entry $M=〈\mathit{\text{value}}〉$.
Constraint: $M$ elements of array ${\mathbf{nv}}>0$.
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.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_MAT_ILL_DEFINED
The matrix ${X}^{\mathrm{T}}\left(B-A\right)X$ is either singular or non-positive definite.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_OBSERVATIONS
All the observations were adjudged to be tied.
NE_REAL
On entry, ${\mathbf{tol}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{tol}}>0.0$.
NE_REAL_ARRAY_ELEM_CONS
On entry, all elements in column $〈\mathit{\text{value}}〉$ of ${\mathbf{x}}$ are equal to $〈\mathit{\text{value}}〉$.
NE_SAMPLE
The largest sample size is $〈\mathit{\text{value}}〉$ which is not equal to nmax, ${\mathbf{nmax}}=〈\mathit{\text{value}}〉$.

## 7Accuracy

The computations are believed to be stable.

## 8Parallelism and Performance

nag_rank_regsn (g08rac) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_rank_regsn (g08rac) makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the x06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

The time taken by nag_rank_regsn (g08rac) depends on the number of samples, the total number of observations and the number of arguments fitted.
In extreme cases the parameter estimates for certain models can be infinite, although this is unlikely to occur in practice. See Pettitt (1982) for further details.

## 10Example

A program to fit a regression model to a single sample of $20$ observations using two explanatory variables. The error distribution will be taken to be logistic.

### 10.1Program Text

Program Text (g08race.c)

### 10.2Program Data

Program Data (g08race.d)

### 10.3Program Results

Program Results (g08race.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017