Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_nonpar_rank_regsn_censored (g08rb)

## Purpose

nag_nonpar_rank_regsn_censored (g08rb) 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.

## Syntax

[prvr, irank, zin, eta, vapvec, parest, ifail] = g08rb(nv, y, x, icen, gamma, nmax, tol, 'ns', ns, 'ip', ip)
[prvr, irank, zin, eta, vapvec, parest, ifail] = nag_nonpar_rank_regsn_censored(nv, y, x, icen, gamma, nmax, tol, 'ns', ns, 'ip', ip)

## Description

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.
 (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 of the score statistic in (a). (c) The estimate ${\stackrel{^}{\beta }}_{R}=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 }}_{R}$. (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. (f) The standard errors ${M}_{ii}^{1/2}$ of the estimates given in (c). (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.

## References

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{nv}\left({\mathbf{ns}}\right)$int64int32nag_int array
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}}$.
2:     $\mathrm{y}\left(\mathit{nsum}\right)$ – double array
nsum, the dimension of the array, must satisfy the constraint $\mathit{nsum}=\sum _{\mathit{i}=1}^{{\mathbf{ns}}}{\mathbf{nv}}\left(\mathit{i}\right)$.
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.
3:     $\mathrm{x}\left(\mathit{ldx},{\mathbf{ip}}\right)$ – double array
ldx, the first dimension of the array, must satisfy the constraint $\mathit{ldx}\ge \mathit{nsum}$.
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 observations in the $i$th sample.
Constraint: ${\mathbf{x}}$ must not contain a column with all elements equal.
4:     $\mathrm{icen}\left(\mathit{nsum}\right)$int64int32nag_int array
nsum, the dimension of the array, must satisfy the constraint $\mathit{nsum}=\sum _{\mathit{i}=1}^{{\mathbf{ns}}}{\mathbf{nv}}\left(\mathit{i}\right)$.
Defines the censoring variable for the observations in y.
${\mathbf{icen}}\left(i\right)=0$
If ${\mathbf{y}}\left(i\right)$ is uncensored.
${\mathbf{icen}}\left(i\right)=1$
If ${\mathbf{y}}\left(i\right)$ is censored.
Constraint: ${\mathbf{icen}}\left(\mathit{i}\right)=0$ or $1$, for $\mathit{i}=1,2,\dots ,\mathit{nsum}$.
5:     $\mathrm{gamma}$ – double scalar
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$.
6:     $\mathrm{nmax}$int64int32nag_int scalar
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}}$.
7:     $\mathrm{tol}$ – double scalar
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$.

### Optional Input Parameters

1:     $\mathrm{ns}$int64int32nag_int scalar
Default: the dimension of the array nv.
The number of samples.
Constraint: ${\mathbf{ns}}\ge 1$.
2:     $\mathrm{ip}$int64int32nag_int scalar
Default: the second dimension of the array x.
The number of parameters to be fitted.
Constraint: ${\mathbf{ip}}\ge 1$.

### Output Parameters

1:     $\mathrm{prvr}\left(\mathit{ldprvr},{\mathbf{ip}}\right)$ – double array
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.
2:     $\mathrm{irank}\left({\mathbf{nmax}}\right)$int64int32nag_int array
For the one sample case, irank contains the ranks of the observations.
3:     $\mathrm{zin}\left({\mathbf{nmax}}\right)$ – double array
For the one sample case, zin contains the expected values of the function $g\left(.\right)$ of the order statistics.
4:     $\mathrm{eta}\left({\mathbf{nmax}}\right)$ – double array
For the one sample case, eta contains the expected values of the function $g\prime \left(.\right)$ of the order statistics.
5:     $\mathrm{vapvec}\left({\mathbf{nmax}}×\left({\mathbf{nmax}}+1\right)/2\right)$ – double array
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.
6:     $\mathrm{parest}\left(4×{\mathbf{ip}}+1\right)$ – double array
The statistics calculated by the function.
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.
7:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{ns}}<1$, or ${\mathbf{tol}}\le 0.0$, or ${\mathbf{nmax}}\le {\mathbf{ip}}$, or $\mathit{ldprvr}<{\mathbf{ip}}+1$, or $\mathit{ldx}<\mathit{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$, $i=1,2,\dots ,{\mathbf{ns}}$, or $\mathit{nsum}\ne \sum _{i=1}^{{\mathbf{ns}}}{\mathbf{nv}}\left(i\right)$, or ${\mathbf{ip}}<1$, or ${\mathbf{gamma}}<0.0$, or $\mathit{lwork}<{\mathbf{nmax}}×\left({\mathbf{ip}}+1\right)$.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{icen}}\left(i\right)\ne 0$ or $1$, for some $1\le i\le \mathit{nsum}$.
${\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$
 On entry, at least one column of the matrix $X$ has all its elements equal.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

The computations are believed to be stable.

The time taken by nag_nonpar_rank_regsn_censored (g08rb) 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.

## Example

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

fprintf('g08rb example results\n\n');

y = [143; 164; 188; 188; 190; 192; 206; 209; 213; 216;
220; 227; 230; 234; 246; 265; 304; 216; 244; 142;
156; 163; 198; 205; 232; 232; 233; 233; 233; 233;
239; 240; 261; 280; 280; 296; 296; 323; 204; 344];
nv = [int64(numel(y))];
x  = zeros(nv,1);
x(20:end) = 1;
icen = zeros(nv,1,'int64');
icen(18:19) = 1;
icen(39:40) = 1;

gamma = 1e-05;
nmax  = int64(nv);
tol   = 1e-05;

ns    = size(y,2);
ip    = size(x,2);
fprintf('Number of samples            = %3d\n', ns);
fprintf('Number of parameters fitted  = %3d\n', ip);
fprintf('Distribution power parameter = %8.1e\n', gamma);
fprintf('Tolerance for ties           = %8.1e\n', tol);

[parvar, irank, zin, eta, vapvec, parest, ifail] = ...
g08rb( ...
nv, y, x, icen, gamma, nmax, tol);

% Display results
fprintf('\nScore statistic\n');
fprintf('%9.3f\n', parest(1:ip));
fprintf('\nCovariance matrix of score statistic\n');
for j = 1:ip
fprintf('%9.3f', parvar(1:j,j));
fprintf('\n');
end
fprintf('\nParameter estimates\n');
fprintf('%9.3f', parest(ip+1:ip+ip));
fprintf('\n\nCovariance matrix of parameter estimates\n');
for j = 1:ip
fprintf('%9.3f', parvar(j+1,1:j));
fprintf('\n');
end

chisq = parest(2*ip+1);
fprintf('\nChi-squared statistic = %8.3f with %2d d.f.\n\n', chisq, ip);

sterr = reshape(parest(2*ip+2:end),[ip,2]);
fprintf('Standard errors of estimates and approximate z-statistics\n');
disp(sterr);

```
```g08rb example results

Number of samples            =   1
Number of parameters fitted  =   1
Distribution power parameter =  1.0e-05
Tolerance for ties           =  1.0e-05

Score statistic
4.584

Covariance matrix of score statistic
7.653

Parameter estimates
0.599

Covariance matrix of parameter estimates
0.131

Chi-squared statistic =    2.746 with  1 d.f.

Standard errors of estimates and approximate z-statistics
0.3615    1.6571

```