G08 Chapter Contents
G08 Chapter Introduction
NAG Library Manual

NAG Library Routine DocumentG08RAF

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

G08RAF 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.

2  Specification

 SUBROUTINE G08RAF ( NS, NV, NSUM, Y, IP, X, LDX, IDIST, NMAX, TOL, PRVR, LDPRVR, IRANK, ZIN, ETA, VAPVEC, PAREST, WORK, LWORK, IWA, IFAIL)
 INTEGER NS, NV(NS), NSUM, IP, LDX, IDIST, NMAX, LDPRVR, IRANK(NMAX), LWORK, IWA(NMAX), IFAIL REAL (KIND=nag_wp) Y(NSUM), X(LDX,IP), TOL, PRVR(LDPRVR,IP), ZIN(NMAX), ETA(NMAX), VAPVEC(NMAX*(NMAX+1)/2), PAREST(4*IP+1), WORK(LWORK)

3  Description

Analysis of data can be made by replacing observations by their ranks. The analysis produces inference for regression parameters 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.

4  References

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

5  Parameters

1:     NS – INTEGERInput
On entry: the number of samples.
Constraint: ${\mathbf{NS}}\ge 1$.
2:     NV(NS) – INTEGER arrayInput
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}=1,2,\dots ,{\mathbf{NS}}$.
3:     NSUM – INTEGERInput
On entry: the total number of observations.
Constraint: ${\mathbf{NSUM}}=\sum _{\mathit{i}=1}^{{\mathbf{NS}}}{\mathbf{NV}}\left(\mathit{i}\right)$.
4:     Y(NSUM) – REAL (KIND=nag_wp) arrayInput
On entry: the observations in each sample. Specifically, ${\mathbf{Y}}\left(\sum _{k=1}^{i-1}{\mathbf{NV}}\left(k\right)+j\right)$ must contain the $j$th observation in the $i$th sample.
5:     IP – INTEGERInput
On entry: the number of parameters to be fitted.
Constraint: ${\mathbf{IP}}\ge 1$.
6:     X(LDX,IP) – REAL (KIND=nag_wp) arrayInput
On entry: the design matrices for each sample. Specifically, ${\mathbf{X}}\left(\sum _{k=1}^{i-1}{\mathbf{NV}}\left(k\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:     LDX – INTEGERInput
On entry: the first dimension of the array X as declared in the (sub)program from which G08RAF is called.
Constraint: ${\mathbf{LDX}}\ge {\mathbf{NSUM}}$.
8:     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:     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\right)\right)$ and ${\mathbf{NMAX}}>{\mathbf{IP}}$.
10:   TOL – REAL (KIND=nag_wp)Input
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:   PRVR(LDPRVR,IP) – REAL (KIND=nag_wp) arrayOutput
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{IP}}$, ${\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{IP}}-1$, ${\mathbf{PRVR}}\left(i+1,j\right)$ contains an estimate of the covariance between the $i$th and $j$th parameter estimates.
12:   LDPRVR – INTEGERInput
On entry: the first dimension of the array PRVR as declared in the (sub)program from which G08RAF is called.
Constraint: ${\mathbf{LDPRVR}}\ge {\mathbf{IP}}+1$.
13:   IRANK(NMAX) – INTEGER arrayOutput
On exit: for the one sample case, IRANK contains the ranks of the observations.
14:   ZIN(NMAX) – REAL (KIND=nag_wp) arrayOutput
On exit: for the one sample case, ZIN contains the expected values of the function $g\left(.\right)$ of the order statistics.
15:   ETA(NMAX) – REAL (KIND=nag_wp) arrayOutput
On exit: for the one sample case, ETA contains the expected values of the function $g\prime \left(.\right)$ of the order statistics.
16:   VAPVEC(${\mathbf{NMAX}}×\left({\mathbf{NMAX}}+1\right)/2$) – REAL (KIND=nag_wp) arrayOutput
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:   PAREST($4×{\mathbf{IP}}+1$) – REAL (KIND=nag_wp) arrayOutput
On exit: the statistics calculated by the routine.
The first IP components of PAREST contain the score statistics.
The next IP elements contain the parameter estimates.
${\mathbf{PAREST}}\left(2×{\mathbf{IP}}+1\right)$ contains the value of the ${\chi }^{2}$ statistic.
The next IP elements of PAREST contain the standard errors of the parameter estimates.
Finally, the remaining IP elements of PAREST contain the $z$-statistics.
18:   WORK(LWORK) – REAL (KIND=nag_wp) arrayWorkspace
19:   LWORK – INTEGERInput
On entry: the dimension of the array WORK as declared in the (sub)program from which G08RAF is called.
Constraint: ${\mathbf{LWORK}}\ge {\mathbf{NMAX}}×\left({\mathbf{IP}}+1\right)$.
20:   IWA(NMAX) – INTEGER arrayWorkspace
21:   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}}=1$
 On entry, ${\mathbf{NS}}<1$, or ${\mathbf{TOL}}\le 0.0$, or ${\mathbf{NMAX}}\le {\mathbf{IP}}$, or ${\mathbf{LDPRVR}}<{\mathbf{IP}}+1$, or ${\mathbf{LDX}}<{\mathbf{NSUM}}$, or ${\mathbf{NMAX}}\ne {\mathrm{max}}_{1\le i\le {\mathbf{NS}}}\left({\mathbf{NV}}\left(i\right)\right)$, or ${\mathbf{NV}}\left(i\right)\le 0$, for some $i$, ${\mathbf{NV}}\left(i\right)$, or ${\mathbf{NSUM}}\ne \sum _{i=1}^{{\mathbf{NS}}}{\mathbf{NV}}\left(i\right)$, or ${\mathbf{IP}}<1$, or ${\mathbf{LWORK}}<{\mathbf{NMAX}}×\left({\mathbf{IP}}+1\right)$.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{IDIST}}<1$, or ${\mathbf{IDIST}}>4$.
${\mathbf{IFAIL}}=3$
On entry, all the observations are adjudged to be tied. You are advised to check the value supplied for TOL.
${\mathbf{IFAIL}}=4$
The matrix ${X}^{\mathrm{T}}\left(B-A\right)X$ is either ill-conditioned or not positive definite. This error should only occur with extreme rankings of the data.
${\mathbf{IFAIL}}=5$
The matrix $X$ has at least one of its columns with all elements equal.

7  Accuracy

The computations are believed to be stable.

The time taken by G08RAF depends on the number of samples, the total number of observations and the number of parameters 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.

9  Example

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.

9.1  Program Text

Program Text (g08rafe.f90)

9.2  Program Data

Program Data (g08rafe.d)

9.3  Program Results

Program Results (g08rafe.r)