# NAG CL Interfaceg08rbc (rank_​regsn_​censored)

## 1Purpose

g08rbc 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 when some of the observations may be right-censored.

## 2Specification

 #include
 void g08rbc (Nag_OrderType order, Integer ns, const Integer nv[], const double y[], Integer p, const double x[], Integer pdx, const Integer icen[], double gamma, Integer nmax, double tol, double prvr[], Integer pdprvr, Integer irank[], double zin[], double eta[], double vapvec[], double parest[], NagError *fail)
The function may be called by the names: g08rbc, nag_nonpar_rank_regsn_censored or nag_rank_regsn_censored.

## 3Description

Analysis of data can be made by replacing observations by their ranks. The analysis produces inference for the regression model where the location parameters of the observations, ${\theta }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$, are related by $\theta =X\beta$. Here $X$ is an $n$ by $p$ matrix of explanatory variables and $\beta$ is a vector of $p$ unknown regression parameters. The observations are replaced by their ranks and an approximation, based on Taylor's series expansion, made to the rank marginal likelihood. For details of the approximation see Pettitt (1982).
An observation is said to be right-censored if we can only observe ${Y}_{j}^{*}$ with ${Y}_{j}^{*}\le {Y}_{j}$. We rank censored and uncensored observations as follows. Suppose we can observe ${Y}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,n$, directly but ${Y}_{j}^{*}$, for $\mathit{j}=n+1,\dots ,q$ and $n\le q$, are censored on the right. We define the rank ${r}_{j}$ of ${Y}_{j}$, for $j=1,2,\dots ,n$, in the usual way; ${r}_{j}$ equals $i$ if and only if ${Y}_{j}$ is the $i$th smallest amongst the ${Y}_{1},{Y}_{2},\dots ,{Y}_{n}$. The right-censored ${Y}_{j}^{*}$, for $j=n+1,n+2,\dots ,q$, has rank ${r}_{j}$ if and only if ${Y}_{j}^{*}$ lies in the interval $\left[{Y}_{\left({r}_{j}\right)},{Y}_{\left({r}_{j}+1\right)}\right]$, with ${Y}_{0}=-\infty$, ${Y}_{\left(n+1\right)}=+\infty$ and ${Y}_{\left(1\right)}<\cdots <{Y}_{\left(n\right)}$ the ordered ${Y}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,n$.
The distribution of the $Y$ is assumed to be of the following form. Let ${F}_{L}\left(y\right)={e}^{y}/\left(1+{e}^{y}\right)$, the logistic distribution function, and consider the distribution function ${F}_{\gamma }\left(y\right)$ defined by $1-{F}_{\gamma }={\left[1-{F}_{L}\left(y\right)\right]}^{1/\gamma }$. This distribution function can be thought of as either the distribution function of the minimum, ${X}_{1,\gamma }$, of a random sample of size ${\gamma }^{-1}$ from the logistic distribution, or as the ${F}_{\gamma }\left(y-\mathrm{log}\gamma \right)$ being the distribution function of a random variable having the $F$-distribution with $2$ and $2{\gamma }^{-1}$ degrees of freedom. This family of generalized logistic distribution functions $\left[{F}_{\gamma }\left(.\right)\text{;}0\le \gamma <\infty \right]$ naturally links the symmetric logistic distribution $\left(\gamma =1\right)$ with the skew extreme value distribution ($\mathrm{lim}\gamma \to 0$) and with the limiting negative exponential distribution ($\mathrm{lim}\gamma \to \infty$). For this family explicit results are available for right-censored data. See Pettitt (1983) for details.
Let ${l}_{R}$ denote the logarithm of the rank marginal likelihood of the observations and define the $q×1$ vector $a$ by $a={l}_{R}^{\prime }\left(\theta =0\right)$, and let the $q$ by $q$ diagonal matrix $B$ and $q$ by $q$ symmetric matrix $A$ be given by $B-A=-{l}_{R}^{\prime \prime }\left(\theta =0\right)$. Then various statistics can be found from the analysis.
1. (a)The score statistic ${X}^{\mathrm{T}}a$. This statistic is used to test the hypothesis ${H}_{0}:\beta =0$ (see (e)).
2. (b)The estimated variance-covariance matrix of the score statistic in (a).
3. (c)The estimate ${\stackrel{^}{\beta }}_{R}=M{X}^{\mathrm{T}}a$.
4. (d)The estimated variance-covariance matrix $M={\left({X}^{\mathrm{T}}\left(B-A\right)X\right)}^{-1}$ of the estimate ${\stackrel{^}{\beta }}_{R}$.
5. (e)The ${\chi }^{2}$ statistic $Q={\stackrel{^}{\beta }}_{R}{M}^{-1}\text{​ ​}{\stackrel{^}{\beta }}_{r}={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.
6. (f)The standard errors ${M}_{ii}^{1/2}$ of the estimates given in (c).
7. (g)Approximate $z$-statistics, i.e., ${Z}_{i}={\stackrel{^}{\beta }}_{{R}_{i}}/se\left({\stackrel{^}{\beta }}_{{R}_{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,
 $hk Yk = 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=1nsXTBk-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

Kalbfleisch J D and Prentice R L (1980) The Statistical Analysis of Failure Time Data Wiley
Pettitt A N (1982) Inference for the linear model using a likelihood based on ranks J. Roy. Statist. Soc. Ser. B 44 234–243
Pettitt A N (1983) Approximate methods using ranks for regression with censored data Biometrika 70 121–132

## 5Arguments

1: $\mathbf{order}$Nag_OrderType Input
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.1.3 in the Introduction to the NAG Library CL Interface for a more detailed explanation of the use of this argument.
Constraint: ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ or $\mathrm{Nag_ColMajor}$.
2: $\mathbf{ns}$Integer Input
On entry: the number of samples.
Constraint: ${\mathbf{ns}}\ge 1$.
3: $\mathbf{nv}\left[{\mathbf{ns}}\right]$const Integer Input
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}-1\right]\ge 1$, for $\mathit{i}=1,2,\dots ,{\mathbf{ns}}$.
4: $\mathbf{y}\left[\mathit{dim}\right]$const double Input
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}$Integer Input
On entry: the number of parameters to be fitted.
Constraint: ${\mathbf{p}}\ge 1$.
6: $\mathbf{x}\left[\mathit{dim}\right]$const double Input
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 observations in the $i$th sample.
Constraint: ${\mathbf{x}}$ must not contain a column with all elements equal.
7: $\mathbf{pdx}$Integer Input
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{icen}\left[\mathit{dim}\right]$const Integer Input
Note: the dimension, dim, of the array icen must be at least $\left(\sum _{\mathit{i}=1}^{{\mathbf{ns}}}{\mathbf{nv}}\left[\mathit{i}-1\right]\right)$.
On entry: defines the censoring variable for the observations in y.
${\mathbf{icen}}\left[i-1\right]=0$
If ${\mathbf{y}}\left[i-1\right]$ is uncensored.
${\mathbf{icen}}\left[i-1\right]=1$
If ${\mathbf{y}}\left[i-1\right]$ is censored.
Constraint: ${\mathbf{icen}}\left[\mathit{i}-1\right]=0$ or $1$, for $\mathit{i}=1,2,\dots ,\left(\sum _{\mathit{i}=1}^{{\mathbf{ns}}}{\mathbf{nv}}\left[\mathit{i}-1\right]\right)$.
9: $\mathbf{gamma}$double Input
On entry: the value of the parameter defining the generalized logistic distribution. For ${\mathbf{gamma}}\le 0.0001$, the limiting extreme value distribution is assumed.
Constraint: ${\mathbf{gamma}}\ge 0.0$.
10: $\mathbf{nmax}$Integer Input
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}}$.
11: $\mathbf{tol}$double 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$.
12: $\mathbf{prvr}\left[\mathit{dim}\right]$double Output
Note: the dimension, dim, of the array prvr must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdprvr}}×{\mathbf{p}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{p}}+1×{\mathbf{pdprvr}}\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{pdprvr}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{prvr}}\left[\left(i-1\right)×{\mathbf{pdprvr}}+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.
13: $\mathbf{pdprvr}$Integer Input
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{pdprvr}}\ge {\mathbf{p}}+1$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pdprvr}}\ge {\mathbf{p}}$.
14: $\mathbf{irank}\left[{\mathbf{nmax}}\right]$Integer Output
On exit: for the one sample case, irank contains the ranks of the observations.
15: $\mathbf{zin}\left[{\mathbf{nmax}}\right]$double Output
On exit: for the one sample case, zin contains the expected values of the function $g\left(.\right)$ of the order statistics.
16: $\mathbf{eta}\left[{\mathbf{nmax}}\right]$double Output
On exit: for the one sample case, eta contains the expected values of the function $g\prime \left(.\right)$ of the order statistics.
17: $\mathbf{vapvec}\left[{\mathbf{nmax}}×\left({\mathbf{nmax}}+1\right)/2\right]$double Output
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.
18: $\mathbf{parest}\left[4×{\mathbf{p}}+1\right]$double Output
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.
19: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{ns}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ns}}\ge 1$.
On entry, ${\mathbf{p}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{p}}\ge 1$.
NE_INT_2
On entry, ${\mathbf{nmax}}=〈\mathit{\text{value}}〉$ and ${\mathbf{p}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nmax}}>{\mathbf{p}}$.
On entry, ${\mathbf{pdprvr}}=〈\mathit{\text{value}}〉$ and ${\mathbf{p}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdprvr}}\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_ELEM_CONS
On entry, $〈\mathit{\text{value}}〉$ elements of icen are out of range.
Constraint: ${\mathbf{icen}}\left[i\right]=0$ or $1$, for all $i$.
On entry, $〈\mathit{\text{value}}〉$ elements of ${\mathbf{nv}}\text{​ are ​}<1$.
Constraint: ${\mathbf{nv}}\left[i\right]\ge 1$.
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 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_MAT_ILL_DEFINED
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.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_OBSERVATIONS
On entry, all the observations were adjudged to be tied. You are advised to check the value supplied for tol.
NE_REAL
On entry, ${\mathbf{gamma}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{gamma}}\ge 0.0$.
On entry, ${\mathbf{tol}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{tol}}>0.0$.
NE_REAL_ARRAY_ELEM_CONS
On entry, for $j=〈\mathit{\text{value}}〉$, ${\mathbf{X}}\left(i,j\right)=〈\mathit{\text{value}}〉$ for all $i$.
Constraint: ${\mathbf{X}}\left(i,j\right)\ne {\mathbf{X}}\left(i+1,j\right)$ for at least one $i$.
NE_SAMPLE
On entry, ${\mathrm{max}}_{i}{\mathbf{nv}}\left[i\right]=〈\mathit{\text{value}}〉$ and ${\mathbf{nmax}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathrm{max}}_{i}{\mathbf{nv}}\left[i\right]={\mathbf{nmax}}$.

## 7Accuracy

The computations are believed to be stable.

## 8Parallelism and Performance

g08rbc is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g08rbc 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 g08rbc 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.

## 10Example

This example fits a regression model to a single sample of $40$ observations using just one explanatory variable.

### 10.1Program Text

Program Text (g08rbce.c)

### 10.2Program Data

Program Data (g08rbce.d)

### 10.3Program Results

Program Results (g08rbce.r)